Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Clarify the description of sort-imports options #18198

Merged
merged 9 commits into from
Mar 22, 2024
86 changes: 74 additions & 12 deletions docs/src/rules/sort-imports.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,33 +194,59 @@ import {b, a, c} from 'foo.js'

When `true` the rule ignores the case-sensitivity of the imports local name.

Examples of **incorrect** code for this rule with the `{ "ignoreCase": true }` option:
Uppercase letters of the alphabet must always precede lowercase letters with default settings.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we want to describe both, I think the default behavior should be first.

When `false` (default), uppercase letters of the alphabet must always precede lowercase letters.

When `true`, the rule ignores the case-sensitivity of the imports local name.


Examples of **incorrect** code for this rule with the default `{ "ignoreCase": false }` option:

::: incorrect

```js
/*eslint sort-imports: ["error", { "ignoreCase": true }]*/

import B from 'foo.js';
/*eslint sort-imports: ["error", { "ignoreCase": false }]*/
import a from 'bar.js';
import B from 'foo.js';
import c from 'baz.js';
```

:::

Examples of **correct** code for this rule with the `{ "ignoreCase": true }` option:
Examples of **correct** code for this rule with the default `{ "ignoreCase": false }` option:

::: correct

```js
/*eslint sort-imports: ["error", { "ignoreCase": true }]*/

import a from 'foo.js';
/*eslint sort-imports: ["error", { "ignoreCase": false }]*/
import B from 'bar.js';
import a from 'foo.js';
import c from 'baz.js';
```

:::

Examples of **correct** code for this rule with `{ "ignoreCase": true }` option:
Tanujkanti4441 marked this conversation as resolved.
Show resolved Hide resolved

::: correct

```js
/*eslint sort-imports: ["error", { "ignoreCase": true }]*/
import a from 'bar.js';
import B from 'foo.js';
import c from 'baz.js';
```

:::

Examples of **incorrect** code for this rule with the `{ "ignoreCase": true }` option:

::: incorrect

```js
/*eslint sort-imports: ["error", { "ignoreCase": true }]*/
import B from 'foo.js';
import a from 'bar.js';
```

:::

Default is `false`.
Tanujkanti4441 marked this conversation as resolved.
Show resolved Hide resolved

### `ignoreDeclarationSort`
Expand All @@ -239,18 +265,20 @@ import a from 'bar.js'

:::

Examples of **correct** code for this rule with the `{ "ignoreDeclarationSort": true }` option:
Examples of **correct** code for this rule with the default `{ "ignoreDeclarationSort": false }` option:

::: correct

```js
/*eslint sort-imports: ["error", { "ignoreDeclarationSort": true }]*/
import a from 'foo.js'
import b from 'bar.js'
/*eslint sort-imports: ["error", { "ignoreDeclarationSort": false }]*/
import a from 'bar.js';
import b from 'foo.js';
```

:::

Examples of **correct** code for this rule with the `{ "ignoreDeclarationSort": true }` option:

::: correct

```js
Expand All @@ -261,6 +289,17 @@ import a from 'bar.js'

:::

Examples of **incorrect** code for this rule with the `{ "ignoreDeclarationSort": true }` option:

::: incorrect

```js
/*eslint sort-imports: ["error", { "ignoreDeclarationSort": true }]*/
import {b, a, c} from 'foo.js';
```

:::

Default is `false`.

### `ignoreMemberSort`
Expand All @@ -278,6 +317,17 @@ import {b, a, c} from 'foo.js'

:::

Examples of **correct** code for this rule with the default `{ "ignoreMemberSort": false }` option:

::: correct

```js
/*eslint sort-imports: ["error", { "ignoreMemberSort": false }]*/
import {a, b, c} from 'foo.js';
```

:::

Examples of **correct** code for this rule with the `{ "ignoreMemberSort": true }` option:

::: correct
Expand All @@ -289,6 +339,18 @@ import {b, a, c} from 'foo.js'

:::

Examples of **incorrect** code for this rule with the `{ "ignoreMemberSort": true }` option:

::: incorrect

```js
/*eslint sort-imports: ["error", { "ignoreMemberSort": true }]*/
import b from 'foo.js';
import a from 'bar.js';
```

:::

Default is `false`.

### `memberSyntaxSortOrder`
Expand Down