eslint-plugin-sort-export-all
TypeScript icon, indicating that this package has built-in type declarations

1.4.1 • Public • Published

eslint-plugin-sort-export-all

ESLint rule that sorts exports * with autofix enabled

npm version

Example

Installation

You'll first need to install ESLint:

$ npm i eslint --save-dev
$ yarn add eslint --dev
$ pnpm add -D eslint

Next, install eslint-plugin-sort-export-all:

$ npm install eslint-plugin-sort-export-all --save-dev
$ yarn add eslint-plugin-sort-export-all --dev
$ pnpm add -D eslint-plugin-sort-export-all

Note: If you installed ESLint globally (using the -g flag) then you must also install eslint-plugin-sort-export-all globally.

Usage

Add sort-export-all to the plugins section of your .eslintrc configuration file. You can omit the eslint-plugin- prefix:

{
  "plugins": ["sort-export-all"]
}

Then configure the rule under the rules section.

{
  "rules": {
    "sort-export-all/sort-export-all": "warn"
  }
}

Or enable it with defaults

{
  "extends": ["plugin:sort-export-all/recommended"]
}

Often it makes sense to enable sort-export-all only for certain files/directories. For cases like that, use override key of eslint config:

{
  "plugins": ["sort-export-all"],
  "rules": {
    "sort-export-all/sort-export-all": "off"
  },
  "overrides": [
    {
      "files": ["src/**/index.{ts,js}"],
      "rules": {
        "sort-export-all/sort-export-all": "error"
      }
    }
  ]
}

If you use TypeScript, make sure to use @typescript-eslint/parser as parser for better compatability.

Rule configuration

  • The 1st option is "asc" or "desc".

    "asc" (default) - enforce properties to be in ascending order.

    "desc" - enforce properties to be in descending order.

  • The 2nd option is an object which has 3 properties.

    caseSensitive - if true, enforce properties to be in case-sensitive order. Default is true.

    natural - if true, enforce properties to be in natural order. Default is false. Natural Order compares strings containing a combination of letters and numbers in the way a human being would sort. It basically sorts numerically, instead of sorting alphabetically. So the number 10 comes after the number 3 in Natural Sorting.

    Standard sorting:   Natural order sorting:
        img1.png            img1.png
        img10.png           img2.png
        img12.png           img10.png
        img2.png            img12.png
    

The default config is

[
  "warn",
  "asc",
  {
    caseSensitive: true,
    natural: false,
  },
];

Dependents (13)

Package Sidebar

Install

npm i eslint-plugin-sort-export-all

Weekly Downloads

21,309

Version

1.4.1

License

MIT

Unpacked Size

19.9 kB

Total Files

18

Last publish

Collaborators

  • nirtamir2