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.

[Bug] No Fix for `sort-imports` ?

See original GitHub issue

Tell us about your environment

  • ESLint Version: v5.16.10
  • Node Version: v11.13.0
  • npm Version: v6.9.0

What parser (default, Babel-ESLint, etc.) are you using?

Please show your full configuration:

Configuration
module.exports = {
  parser: '@typescript-eslint/parser',
  extends: [
    'plugin:react/recommended',
    // 'plugin:@typescript-eslint/recommended',
    'prettier/@typescript-eslint',
    'plugin:prettier/recommended',
  ],
  parserOptions: {
    sourceType: 'module',
    ecmaVersion: 2019,
    ecmaFeatures: {
      jsx: true,
    },
  },
  rules: {
    '@typescript-eslint/arrow-parens': [true],
    '@typescript-eslint/await-promise': [true],
    '@typescript-eslint/max-classes-per-file': false,
    '@typescript-eslint/no-console': [false],
    '@typescript-eslint/no-floating-promises': [true],
    '@typescript-eslint/object-literal-key-quotes': [false],
    '@typescript-eslint/object-literal-sort-keys': [false],
    '@typescript-eslint/ordered-imports': [false],
    '@typescript-eslint/quotemark': [true, 'single', 'avoid-escape'],
    '@typescript-eslint/semicolon': [true, 'never'],
    '@typescript-eslint/trailing-comma': [true],
    'jsx-quotes': ['error', 'prefer-single'],
    'sort-imports': [
      'error',
      {
        ignoreCase: false,
        ignoreDeclarationSort: false,
        ignoreMemberSort: false,
        memberSyntaxSortOrder: ['none', 'all', 'single', 'multiple'],
      },
    ],
  },
  settings: {
    react: {
      version: 'detect',
    },
  },
}

What did you expect to happen? imports to be sorted with --fix

What actually happened? Please include the actual, raw output from ESLint. Not that.

Are you willing to submit a pull request to fix this bug? No.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
ljharbcommented, Aug 12, 2019

@Industrial it’s not always. Polyfills and shims are supposed to cause side effects and be written in that way.

However, typically the only imports with side effects are ones without a binding - just like it’s safe to reorganize properties as long as nothing crosses a spread, it’s safe to sort imports as long as nothing crosses a bindingless import.

0reactions
Industrialcommented, Aug 12, 2019

The imported modules can have toplevel side effects, and rearranging the imports will then run them in different order, which could potentially break stuff.

@lydell

That should be a code smell. An indicator for people to not write their code in this way. I don’t think it should be a problem to be prevented by not implementing the sorting :S

Read more comments on GitHub >

github_iconTop Results From Across the Web

sort-import does not auto fix · Issue #11542 · eslint/eslint · GitHub
Hi, thanks for the proposal. However, I don't think it would be safe for sort-imports to autofix code because it could change the...
Read more >
Add ESLint Rules to Sort Imports And Audit Accessibility
Adding ESLint rules to sort imports statements and audit accessibility will ensure code consistency across the team and catch some errors early.
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 >
Bug #1894078 “PyLint 2.3.0 isort attribute error” : Bugs : Cinder
AttributeError: module 'isort' has no attribute 'SortImports'. Cinder PyLint result with 2.3.0: michael@unit-test:~/OpenStack/unit_tests$ ...
Read more >
ESLint sort imports - remarkablemark
How to automatically sort imports with ESLint. ... As a result, there's no automatic fix for this rule. You'll either need to manually...
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