sort-imports: support ordering relative imports vs package imports
See original GitHub issueProposal
Either extend the existing sort-imports
rule, or create a new rule which will enforce ordering / separation of relative imports vs package imports.
This is a stylistic rule and provides developer the means to keep clear separation between groups of imports helping visually seperate external dependencies (eg: React) from internal code.
Good
import moment from 'moment';
import React, { PropTypes } from 'react';
import styles from './ArchiveDetails.css';
import { SHOWN, HIDDEN } from '../actions/error';
Bad
import moment from 'moment';
import styles from './ArchiveDetails.css';
import React, { PropTypes } from 'react';
import { SHOWN, HIDDEN } from '../actions/error';
Why the rule should be in the core instead of creating a custom rule.
Feel like a logical extension of the sort-imports
rule; although happy to be informed otherwise.
Are you willing to create the rule yourself?
Possibly; although I don’t have a lot of free time to dedicate to the cause 😦
Issue Analytics
- State:
- Created 8 years ago
- Reactions:11
- Comments:16 (10 by maintainers)
Top Results From Across the Web
Relative imports vs package imports in Dart - Medium
You are forced to sort imports alphabetically. With package imports, it means there first will be some foreign packages, then your imports, then...
Read more >Sorting your imports with ESLint - DEV Community
The "react" import should always come first; Package imports should come next, sorted by alphabetical order; The named imports should be sorted ...
Read more >Sort order of relatives imports? - python - Stack Overflow
I got some answers to this question. According to with PEP 328 [1], has Guido pronounced saying that "relative imports will use leading...
Read more >Sort Typescript imports - Visual Studio Marketplace
Extension for Visual Studio Code - Sorts import statements in ... by the import path, sorting relative-path imports above package imports.
Read more >How to Sort Imports in React Project - Level Up Coding
npm install --save-dev @trivago/prettier-plugin-sort-imports// or use yarn ... The plugin is very flexible and has some apis that help us custom the order....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
For those who are wondering how to combine
eslint-plugin-import
with alphabetical order likesort-import
does, this is not possible yet with the plugin. An issue is open on the plugin as a feature suggestion. So unfortunately, we can’t currently both lint for alphabetical order and import type (absolute/relative).Re-reading this issue. I think this should go into
eslint-plugin-import
instead of the core. And it seem this rule already exists there. @eslint/eslint-team anyone feels differently?