Created
May 2, 2022 13:49
-
-
Save phatnguyenuit/8ce9c3b6c554d9400bc97e1fe0249cc0 to your computer and use it in GitHub Desktop.
How to sort imports like a pro in TypeScript | .eslintrc.js | import rules
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
// <--! Previous configuration comes here !--> | |
plugins: ['@typescript-eslint', 'prettier', 'import'], // Add "import" plugin | |
extends: [ | |
'eslint:recommended', | |
'plugin:@typescript-eslint/recommended', | |
'plugin:prettier/recommended', | |
// Extends two more configuration from "import" plugin | |
'plugin:import/recommended', | |
'plugin:import/typescript', | |
], | |
rules: { | |
// <--! Previous rules come here !--> | |
// turn on errors for missing imports | |
'import/no-unresolved': 'error', | |
// 'import/no-named-as-default-member': 'off', | |
'import/order': [ | |
'error', | |
{ | |
groups: [ | |
'builtin', // Built-in imports (come from NodeJS native) go first | |
'external', // <- External imports | |
'internal', // <- Absolute imports | |
['sibling', 'parent'], // <- Relative imports, the sibling and parent types they can be mingled together | |
'index', // <- index imports | |
'unknown', // <- unknown | |
], | |
'newlines-between': 'always', | |
alphabetize: { | |
/* sort in ascending order. Options: ["ignore", "asc", "desc"] */ | |
order: 'asc', | |
/* ignore case. Options: [true, false] */ | |
caseInsensitive: true, | |
}, | |
}, | |
], | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment