1.0.2 • Published 2 years ago

eslint-plugin-import-curly v1.0.2

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

eslint-plugin-import-curly

import curly

Installation

You'll first need to install ESLint:

npm i eslint --save-dev

Next, install eslint-plugin-import-curly:

npm install eslint-plugin-import-curly --save-dev

Usage

Add import-curly to the plugins section of your .eslintrc configuration file. You can omit the eslint-plugin- prefix:

{
    "plugins": ["import-curly"]
}

RULE import-curly/newline

options

nametypedefaultdescription
countnumber3If it exceeds count, each attribute will be wrapped.
{
  "rules": {
    "import-curly/newline": [
      "error",
      {
        "count": 4
      }
    ]
  }
}

valid

import A from 'C'
import * as A from 'C'
// count defalut 3
import {A, B} from 'C'
import {
  A as AA,
  B
} from 'C'
import A, {
  AA as AAA,
  B as BB,
  C,
} from 'D'
import {
  A as AA,
  B,
} from 'C'
import A, {
  AA as AAA,
  B as BB,
  C,
} from 'D'

invalid

// invalid
import {
  A as AA,B, C} from 'C'

// ||
// \/

// valid
import {
  A as AA,
  B,
  C
} from 'C'

// invalid
import {
  A as AA,B, 
  C,
} from 'C'

// ||
// \/

// valid, Commas will be preserved
import {
  A as AA,
  B,
  C,
} from 'C'

RULE import-curly/sort-params

options

nametypedefaultenumdescription
typeLocationstringignoreignore,first,lastignore: ignore 'type' location, first: 'type' is at the front, last: 'type' is at the end
orderBystringalphabeticalOrderalphabeticalOrder,letterNumberalphabeticalOrder: order by alpha, letterNumber: order by letter number. when order by letterNumber, if the letterNumber is the same, order by alpha
sortBystringaecaec,descaec: sort in ascending order, desc: sort in descending order
ignoreCasebooleantruetrue: ignore case, false: don't ignore case
{
  "rules": {
    "import-curly/sort-params": "error",
    "import-curly/sort-params": [
      "error",
      {
        "typeLocation": "first",
        "orderBy": "letterNumber",
        "sortBy": "desc",
        "ignoreCase": false
      }
    ]
  }
}

default options

{
  "rules": {
    "import-curly/sort-params": "error",
    "import-curly/sort-params": [
      "error",
      {
        "typeLocation": "ignore",
        "orderBy": "alphabeticalOrder",
        "sortBy": "aec",
        "ignoreCase": true
      }
    ]
  }
}

valid

import type {a,b,c,d} from 'a'
import {A,B,C,D} from 'a'
import type {a,B,c,D} from 'a'
import {A,b,c,D} from 'a'
import {type a,b,type c,d} from 'a'
import {a,type b,c,default as d} from 'a'

invalid

// invalid
import {type A,type c,d,B} from 'a'
// ||
// \/
// valid
import {type A,B,type c,d} from 'a'


// invalid, ignore type, compare with 'default'
import {c,default as d,type b,a} from 'a'
// ||
// \/
// valid
import {a,type b,c,default as d} from 'a'

typeLocation first

{
  "rules": {
    "import-curly/sort-params": [
      "error",
      {
        "typeLocation": "first"
      }
    ],
    "import-curly/sort-params": [
      "error",
      {
        "typeLocation": "first",
        "orderBy": "alphabeticalOrder",
        "sortBy": "aec",
        "ignoreCase": true
      }
    ]
  }
}

valid

// type first
import {type B,type c,A, d} from 'a'
import {type b,type d,a,c} from 'a'

invalid

// invalid, compare with 'default'
import {c,a,default as d,type b} from 'a'
// ||
// \/
// valid
import {type b,a,c,default as d} from 'a'

orderBy letterNumber

{
  "rules": {
    "import-curly/sort-params": [
      "error",
      {
        "orderBy": "letterNumber"
      }
    ],
    "import-curly/sort-params": [
      "error",
      {
        "typeLocation": "ignore",
        "orderBy": "letterNumber",
        "sortBy": "aec",
        "ignoreCase": true
      }
    ]
  }
}

valid

import {a, ba, bb, ccc} from 'a'
import {a, ba, bb, bbb} from 'a'

invalid

// invalid bb ba letterNumber is the same, should order by alpha
import {a, bb, ba} from 'a'
// ||
// \/
// valid
import {a, ba, bb} from 'a'

orderBy alphabeticalOrder and sortBy desc

{
  "rules": {
    "import-curly/sort-params": [
      "error",
      {
        "sortBy": "desc"
      }
    ],
    "import-curly/sort-params": [
      "error",
      {
        "typeLocation": "ignore",
        "orderBy": "alphabeticalOrder",
        "sortBy": "desc",
        "ignoreCase": true
      }
    ]
  }
}

valid

import {d, c, b, a} from 'a'

orderBy letterNumber and sortBy desc

{
  "rules": {
    "import-curly/sort-params": [
      "error",
      {
        "orderBy": "letterNumber",
        "sortBy": "desc"
      }
    ],
    "import-curly/sort-params": [
      "error",
      {
        "typeLocation": "ignore",
        "orderBy": "letterNumber",
        "sortBy": "desc",
        "ignoreCase": true
      }
    ]
  }
}

valid

import {aaa, cc, aa, d} from 'a'

ignoreCase false

{
  "rules": {
    "import-curly/sort-params": [
      "error",
      {
        "ignoreCase": false
      }
    ],
    "import-curly/sort-params": [
      "error",
      {
        "typeLocation": "ignore",
        "orderBy": "alphabeticalOrder",
        "sortBy": "aec",
        "ignoreCase": false
      }
    ]
  }
}

valid

import {A, B, C, a, b, c} from 'a'
import {A, B, C, a, b, c, default as d} from 'a'