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
Update: Add sort-imports ignoreDeclarationSort (fixes #11019) #11040
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,7 @@ The `--fix` option on the command line automatically fixes some problems reporte | |
This rule accepts an object with its properties as | ||
|
||
* `ignoreCase` (default: `false`) | ||
* `ignoreDeclarationSort` (default: `false`) | ||
* `ignoreMemberSort` (default: `false`) | ||
* `memberSyntaxSortOrder` (default: `["none", "all", "multiple", "single"]`); all 4 items must be present in the array, but you can change the order: | ||
* `none` = import module without exported bindings. | ||
|
@@ -47,6 +48,7 @@ Default option settings are: | |
{ | ||
"sort-imports": ["error", { | ||
"ignoreCase": false, | ||
"ignoreDeclarationSort": false, | ||
"ignoreMemberSort": false, | ||
"memberSyntaxSortOrder": ["none", "all", "multiple", "single"] | ||
}] | ||
|
@@ -136,6 +138,34 @@ import c from 'baz.js'; | |
|
||
Default is `false`. | ||
|
||
### `ignoreDeclarationSort` | ||
|
||
Ignores the sorting of import declaration statements. | ||
|
||
Examples of **incorrect** code for this rule with the default `{ "ignoreMemberSort": false }` option: | ||
remcohaszing marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```js | ||
/*eslint sort-imports: ["error", { "ignoreDeclarationSort": false }]*/ | ||
import 'foo.js' | ||
import 'bar.js' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This examples of incorrect code wasn't warned: https://eslint.org/demo/#eyJ0ZXh0IjoiLyplc2xpbnQgc29ydC1pbXBvcnRzOiBbXCJlcnJvclwiLCB7IFwiaWdub3JlRGVjbGFyYXRpb25Tb3J0XCI6IGZhbHNlIH1dKi9cclxuaW1wb3J0ICdmb28uanMnXHJcbmltcG9ydCAnYmFyLmpzJ1xyXG4iLCJvcHRpb25zIjp7InBhcnNlck9wdGlvbnMiOnsiZWNtYVZlcnNpb24iOjgsInNvdXJjZVR5cGUiOiJtb2R1bGUiLCJlY21hRmVhdHVyZXMiOnt9fSwicnVsZXMiOnt9LCJlbnYiOnt9fX0= Is this intentional? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for pointing this out. I fixed it in #11242. |
||
``` | ||
|
||
Examples of **correct** code for this rule with the `{ "ignoreMemberSort": true }` option: | ||
remcohaszing marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```js | ||
/*eslint sort-imports: ["error", { "ignoreDeclarationSort": true }]*/ | ||
import 'foo.js' | ||
import 'bar.js' | ||
``` | ||
|
||
```js | ||
/*eslint sort-imports: ["error", { "ignoreDeclarationSort": true }]*/ | ||
import 'bar.js' | ||
import 'foo.js' | ||
``` | ||
|
||
Default is `false`. | ||
|
||
### `ignoreMemberSort` | ||
|
||
Ignores the member sorting within a `multiple` member import declaration. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a note that the default is false here. (I see the note below, but I think it's important enough to be included in the intro/summary of the section.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I decided to keep it at the end for consistency with the other sections.
Please let me know if this really needs to be changed.