Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

eslint-plugin-cascading-imports

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-cascading-imports

Sort import declarations into a pleasing and readable cascade.

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

⛲ eslint-plugin-cascading-imports

License Latest release Coverage status

This plugin allows to automatically enforce a visual "cascading" order for import declarations.

Imports in each block will be sorted according to the length of their bindings, and if equal then according to the length of their specifier. Imports without bindings will be left untouched, as their order may be important.

Before:

import { lorem, ipsum } from 'cicero';
import foo from 'foo';
import { bar as baz } from 'bar';
import { xizzy } from 'magic-words';

import './beforehand.css';
import './after.css';
import { Bandersnatch } from './jabberwocky.js';
import * as nebula from './lib/galaxy.js';

After:

import foo from 'foo';
import { xizzy } from 'magic-words';
import { bar as baz } from 'bar';
import { lorem, ipsum } from 'cicero';

import './beforehand.css';
import './after.css';
import * as nebula from './lib/galaxy.js';
import { Bandersnatch } from './jabberwocky.js';

Note: only ES6 import syntax is supported.

Installation

npm i -D eslint-plugin-cascading-imports

Make sure you've also installed ESLint.

Usage

This plugin exports a single rule, called cascading-imports:

{
  "plugins": [
    "cascading-imports"
  ],
  "rules": {
    "cascading-imports/cascading-imports": "warn"
  }
}

The reported problems can be automatically fixed by running ESLint with the --fix option.

Please note this plugin only works properly if each import is on its own line. You can use the newline-after-import from eslint-plugin-import to enforce this.

Also note that this plugin could conflict with other sorting rules, e.g. eslint-plugin-import/order. To alleviate this, separate your imports in blocks according to their "type" (external, internal, etc).

Changelog

See the full changelog here.

Contributing

Contributions are welcomed! Please open an issue before submitting substantial changes.

  • sort-imports - Core ESLint rule to sort imports and their bindings
  • eslint-plugin-import - Various ESLint rules to validate your imports

License

ISC

Keywords

bindings

FAQs

Package last updated on 20 Jan 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts