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.

Usefulness of distinct 'single' and 'multiple' styles for sort-imports

See original GitHub issue

What rule do you want to change?

sort-imports

The issue

Currently, the ‘single’ style from the ‘memberSyntaxSortOrder’ option, covers both of these lines:

import a from 'a';
import {b} from 'b';

This means that this:

import {a} from 'a';
import {b, c} from 'b';

Would be incorrect, as the first line is considered ‘single’, while the second line is considered ‘multiple’, yet clearly they’re the same import style and all that differs is the number of imported members. I don’t see much value in this. I expected that ‘single’ imports would mean ‘default imports’, i.e. the first line in the first example, but not the second line, which I would consider ‘multiple’ (even though it is only importing one member) as it is a different style. However, it is also possible to import the default export and other members within the same line, e.g.

import React, {useEffect, useState} from 'react';

Perhaps this is the reasoning for the distinction between single and multiple, rather than between default and non-default. However, I don’t see the value in treating the two import lines in the first example as the same style (clearly they aren’t), and grouping on the number of imported members (which does not feel much like a ‘style’). I feel that it would be better to either remove the distinction between single and multiple, or change the groups/styles to something like ‘none’, ‘all’, withDefault’, and ‘withoutDefault’, so that you’d end up with something like this:

import 'none';
import * from 'all1';
import * from 'all2';
import a from 'a'; // has a default import
import b, {f, g} from 'b'; // has a default import
import {d} from 'd'; // does not have a default import
import {e} from 'e'; // does not have a default import

Are you willing to submit a pull request to implement this change?

Possibly.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
mdjermanoviccommented, Sep 5, 2020

A backward-compatible change then would be to treat that as an alternate set of options, as the previous issue suggests, rather than modifying the existing set?

Exactly! I think we shouldn’t even deprecate the existing set of items (["none", "all", "multiple", "single"]), but just allow the alternate set instead, so the users could choose either based on their preferences.

0reactions
eslint-deprecated[bot]commented, Oct 6, 2020

Unfortunately, it looks like there wasn’t enough interest from the team or community to implement this change. While we wish we’d be able to accommodate everyone’s requests, we do need to prioritize. We’ve found that issues failing to reach accepted status after 21 days tend to never be accepted, and as such, we close those issues. This doesn’t mean the idea isn’t interesting or useful, just that it’s not something the team can commit to.

Thanks for contributing to ESLint and we appreciate your understanding.

Read more comments on GitHub >

github_iconTop Results From Across the Web

lydell/eslint-plugin-simple-import-sort - GitHub
This plugin gives you a single error for each chunk of imports/exports, while import/order can give multiple (see Can I use this without...
Read more >
sort-imports - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >
How to Sort Imports in React Project - Level Up Coding
In my project, I use importOrder to custom the order of imports, and importOrderSeparation to separate different parts: // .prettierrc.json
Read more >
Sort Typescript imports - Visual Studio Marketplace
Extension for Visual Studio Code - Sorts import statements in Typescript code.
Read more >
Using eslint, prettier and sort-imports vscode extensions for ...
Many open source projects use its own customized eslint rules. which is essential ... various coding styles) are contributing to one repository.
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