Skip to content

Instantly share code, notes, and snippets.

@phatnguyenuit
Created May 2, 2022 13:49
Show Gist options
  • Save phatnguyenuit/8ce9c3b6c554d9400bc97e1fe0249cc0 to your computer and use it in GitHub Desktop.
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
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