Skip to content
This repository has been archived by the owner on Feb 21, 2022. It is now read-only.

Sort-Imports fails when 'none' is first sort option #363

Open
worldlee78 opened this issue Dec 6, 2018 · 1 comment
Open

Sort-Imports fails when 'none' is first sort option #363

worldlee78 opened this issue Dec 6, 2018 · 1 comment

Comments

@worldlee78
Copy link

tslint and typescript versions

$ tslint --version
5.11.0
$ tsc --version
Version 3.2.1

tslint.json configuration

{
  extends: [
    'tslint-react',
    'tslint-eslint-rules',
    'tslint-config-prettier'
  ],
  defaultSeverity: 'error',
  rulesDirectory: 'tslint-microsoft-contrib',
  rules: {
    'sort-imports': [true, { 'member-syntax-sort-order': ['none', 'all', 'single', 'multiple', 'alias'], 'ignore-case': true }],
  }
};

Typescript code being linted:

import './index.css';
import * as React from 'react';
import App from './App';
import ReactDOM from 'react-dom';

ReactDOM.render(<App />, document.getElementById('root'));

Actual Behavior:
ERROR: src/index.tsx[1, 1]: All imports of type "None" must occur before all imports of type "All"

Expected Behavior:
Should not have any errors

@worldlee78
Copy link
Author

If you look at the code, inside the _processMemberSyntaxSortOrder method, the sortOptions does not add the 'none' option to the order array because the if statement of (memberSyntaxTypeMap['none']) evaluates to 0, which is false, and thus is skips adding the option. Changing this to explicitly check for undefined instead of using the "evaluates to false" shortcut should resolve this issue.

It was causing sort-imports to incorrectly state that none must occur before all imports of type all in the above member-syntax-sort-order: ['none', 'all', 'single', 'multiple', 'alias'] even though all none imports were above all imports.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant