⛲ Sort import declarations into a pleasing and readable cascade.

Overview

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.

Related

License

ISC

You might also like...

Sort imports by path - VS Code extension

Import sort by absolute path The sorting algorithm will group each item in the array and sort (alphabetically) its children that starts with the path

Feb 2, 2022

Sort tailwind classes for each elements className list by a given order-config

eslint-plugin-tailwind-classname-order This eslint plugin automatically orders the tailwind classes included in the className tags from each element b

Nov 25, 2022

Send encrypted and decrypted messages with verifiable keys and human readable names.

Send encrypted and decrypted messages with verifiable keys and human readable names.

zooko-msg Encrypt and decrypt messages using AES with a preshared ECDH key generated using keys associated with Handshake names. I noticed that there

Jul 27, 2022

⏱ Simple Alpine.js plugin to display the human-readable distance between a date and now.

⏱ Alpine TimeAgo ⏱ An Alpine.js plugin to return the distance between a given date and now in words (like "3 months ago", "about 2 hours ago" or "in a

Dec 22, 2022

Enhanced interval features for Node.js, such as promisified interval and human readable time parsing.

Interval-next Interval-next is a package that extends Javascript's built-in setInterval() capabilities. You have a plain and promisified interval meth

Jul 28, 2022

Library for readable and manageable Next.js middleware

🧵 Next Compose Middleware This is a library for building Next.js complex middleware declaratively. You can create highly readable and manageable midd

Dec 19, 2022

Convert JSON to human readable HTML

json.human.js: Json Formatting for Human Beings A small library to convert a JSON object into a human readable HTML representation that is easy to sty

Dec 3, 2022

Render readable & responsive tables in the terminal

terminal-columns Readable tables for the terminal. Tables can be automatically responsive! Features Content wrapped to fit column width Column widths

Oct 28, 2022

A compiled-away, type-safe, readable RegExp alternative

🦄 magic-regexp A compiled-away, type-safe, readable RegExp alternative ✨ Changelog 📖 Documentation ▶️ Online playground Features Runtime is zero-dep

Jan 8, 2023
Comments
  • Meta: Bump minimist from 1.2.5 to 1.2.6

    Meta: Bump minimist from 1.2.5 to 1.2.6

    Bumps minimist from 1.2.5 to 1.2.6.

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
Releases(v1.0.0)
Owner
Florent
Making code tools helping coders tool helpers for makers coding tools to help make code tooling.
Florent
Nested Sort is a JavaScript library which helps you to sort a nested list of items via drag and drop.

Nested Sort Nested Sort is a vanilla JavaScript library, without any dependencies, which helps you to sort a nested list of items via drag and drop. U

Hesam Bahrami 40 Dec 7, 2022
Apollo - a JavaScript library to get real-time economic declarations such as inflation rates

Apollo is a JavaScript library to get real-time economic declarations such as inflation rates, unemployment rates or interest rates reported by governments or other entities.

Reiryoku Technologies 77 Dec 10, 2022
A pleasing darker theme made mostly with complementary purple and blue colors, occasionally with a touch of pink or red.

Nebula Float away in space with a beautiful blurple oriented color theme. DISCLAIMER: ⚠️ This theme is not as high contrast as other themes. A pleasin

catgirlkelly 5 Nov 23, 2022
A plugin that can query multiple APIs for movies, series, anime, games, music and wiki articles, and import them into your vault.

Obsidian Media DB Plugin A plugin that can query multiple APIs for movies, series, anime, games, music and wiki articles, and import them into your va

Moritz Jung 58 Dec 21, 2022
Boost is a Microsoft Excel Add-in to help developers import large excel workbooks into their database using SQL queries

Microsoft Excel Add-in for Developers About Us Boost is a Microsoft Excel Add-in to help developers import large excel workbooks into their database u

OSLabs Beta 30 Sep 30, 2022
Group and sort Eleventy’s verbose output by directory (and show file size with benchmarks)

eleventy-plugin-directory-output Group and sort Eleventy’s verbose output by directory (and show file size with benchmarks). Sample output from eleven

Eleventy 16 Oct 27, 2022
Using Htmx, ASP.NET Core, and Marten (postgres document db) to sort list

Using Htmx, ASP.NET Core, and Marten (postgres document db) to sort list

Khalid Abuhakmeh 5 Feb 16, 2022
URL Shortener API in NodeJS supporting pagination, sort params and lot more

node-url-shortener Built with ❤️ in NodeJS A simple URL Shortner REST API that uses shortid npm package to generate short endpoints for your long URL.

Dhairya Ostwal 3 Sep 22, 2022
Sort tsconfig.json compilerOptions

sort-compiler-options Sort tsconfig.json compilerOptions in the same order as the TSConfig Reference (Support v4.5.5 or less) Install npm i sort-compi

P-Chan 6 Oct 19, 2022
A small CLI to sort any specified json files alphabetically

This is a small CLI to sort any specified json files alphabetically. This was created to sort localization files, but maybe you will find another use case.

PLAYT.net 4 Mar 20, 2022