-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
[New] add named-order
rule to sort specifiers of import, export, require
#2552
Conversation
named-order
rule to sort specifiers of importnamed-order
rule to sort specifiers of import, export, require
Please discuss things in issues before sending a PR. What’s your use case where you have that many named imports? Things should be deep-imported from granular modules. |
import { alpha, Alpha, ALPHA } from 'foo' // <- will not report | ||
``` | ||
|
||
#### `order` |
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.
Shall we adopt https://palantir.github.io/tslint/rules/ordered-imports?
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.
Thanks to you, I realized the weirdness in some cases. I think it should consider the options below.
- "case-insensitive': Correct order is "Bar", "baz", "Foo". (This is the default.)
- "lowercase-first": Correct order is "baz", "Bar", "Foo".
- "lowercase-last": Correct order is "Bar", "Foo", "baz".
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.
Oh I see, I will write an issue about this. So Is it ok to change to draft, or should be closed this PR? |
It is a good to have feature when using something like import {
BehaviorSubject,
combineLatest,
distinctUntilChanged,
map,
switchMap,
tap,
} from 'rxjs'; It will reduce conflicts when collaborating with others. |
I wrote an issue for discussion about this 😄 |
…nsitive, lowercaseFirst, uppercaseFirst values
@ronparkdev hi, if we have an import like TypeError: Cannot read properties of undefined (reading 'name')
Occurred while linting /project/sandbox/src/server.ts:2
at /project/sandbox/node_modules/eslint-plugin-eslint-custom-rules/rules/named-order.js:53:49
at Array.reduce (<anonymous>)
at getNormalizedValue (/project/sandbox/node_modules/eslint-plugin-eslint-custom-rules/rules/named-order.js:53:21)
at sorter (/project/sandbox/node_modules/eslint-plugin-eslint-custom-rules/rules/named-order.js:70:24)
at Array.sort (<anonymous>)
at handleImports (/project/sandbox/node_modules/eslint-plugin-eslint-custom-rules/rules/named-order.js:130:50)
at /project/sandbox/node_modules/eslint/lib/linter/safe-emitter.js:45:58
at Array.forEach (<anonymous>)
at Object.emit (/project/sandbox/node_modules/eslint/lib/linter/safe-emitter.js:45:38)
at NodeEventGenerator.applySelector (/project/sandbox/node_modules/eslint/lib/linter/node-event-generator.js:293:26)
error Command failed with exit code 2. |
Examples
✅ Valid with
named-order
❌ Invalid with
named-order
Why?
I experienced a significant decrease in readability as the number of specifiers increased in the named import. So, I made this rule. Tell me if there's anything weird in this rule 😄