npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

eslint-plugin-import-splitnsort

v1.0.2

Published

ESLInt plugin to enforce idiosyncratic TypeScript import style and ordering, deprecating VSCode plugin import-splitnsort

Downloads

26

Readme

eslint-plugin-import-splitnsort

An ESLInt plugin to enforce idiosyncratic TypeScript import style and ordering, deprecating my VSCode extension Split'n'Sort Imports.

import-splitnsort is highly opinionated so, like its predecessor, it will appeal perhaps to only a few users:

  • imports that reference multiple exports can be organized but they can't really be sorted without splitting them up, one per line
  • if you try to import multiple exports from the same module in one statement, sooner or later you violate the max-len rule
  • multi-export imports don't help you eyeball your imports and they disguise their 'weight' in your code

import-splitnsort is best used with autofix. In VSCode, that means these settings:

  "editor.codeActionsOnSave": {
    "source.fixAll.eslint": true
  }

Before import-splitnsort

import num, { a, X, Y as Z } from './my-module';
import * as myModule from './my-module';
import './my-code.js';

After import-splitnsort

import './my-code.js';

import * as myModule from './my-module';

import { X } from './my-module';
import { Y as Z } from './my-module';

import { a } from './my-module';

import num from './my-module';

Background

Back in October 2019, Ricardo Amaral kindly made some excellent suggestions for improving Split'n'Sort Imports. However, I'd retired from building software and I never implemented them. Or so I thought ... now, in the middle of the horrible year of 2020, locked down by the virus, thankful that the only impact to me so far has been cabin fever, I'm trying to stay busy.

Features

Imports are sorted case-sensitive and broken into 5 categories, in this order:

import 'code.js';                           // side-effect imports

import * as vscode from 'vscode';           // namespace imports

import { Observer } from 'rxjs';            // named class-like imports

import { map } from 'rxjs/operators';       // named function-like imports

import $ from 'JQuery';                     // default imports

Of course, it is very rare for a single file to use all these different import types.

Comments before an after the imports are kept, but all comments within them, as well as any line breaks or whitespace, are removed.

Additionally, imports are partitioned into two sections. The first section comprises all the imports from files and modules local to your project, sorted and categorized as described above, the second is the same but for node_modules.

import-splitnsort has a peer dependency on @typescript-eslint/parser, but that parser currently fails to parse these types of imports:

  • import type {APIResponseType} from "./api"
  • import zip = require("./ZipCodeValidator");

I'll add support for these imports when I've figured out how.

Installation

npm i -D eslint-plugin-import-splitnsort

In your .eslintrc configuration:

{
  plugins: ['import-splitnsort', ...],
  extends: ['plugin:import-splitnsort/recommended', ...]
}

You can configure the one and only rule, or reconfigure it if you extended plugin:import-splitnsort/recommended:

{
  rules: {
    'import-splitnsort/split-and-sort': 'off | warn | error'
  }
}

Don't forget to turn off any other import sorting rules or VSCode plugins!

{
  rules: {
    'sort-imports': 'off'
  }
}