question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

sort-imports: support ordering relative imports vs package imports

See original GitHub issue

Proposal

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:closed
  • Created 8 years ago
  • Reactions:11
  • Comments:16 (10 by maintainers)

github_iconTop GitHub Comments

4reactions
verekiacommented, Sep 30, 2016

For those who are wondering how to combine eslint-plugin-import with alphabetical order like sort-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).

3reactions
ilyavolodincommented, May 12, 2016

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?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found