-
-
Save vitalybaev/51d0f0264f4d5443d97348e37c5f6755 to your computer and use it in GitHub Desktop.
imports-linting: order, access
This file contains hidden or 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
/** Разрешенные импорты (для сортировки) */ | |
const ALLOWED_PATH_GROUPS = ["pages/**", "features/**", "entities/**", "shared/**"].map( | |
(pattern) => ({ | |
pattern, | |
group: "internal", | |
position: "after", | |
}), | |
); | |
/** Для запрета приватных путей */ | |
const DENIED_PATH_GROUPS = [ | |
// Private imports are prohibited, use public imports instead | |
"app/**", | |
"pages/*/**", | |
"features/*/**", | |
"entities/*/**", | |
"shared/*/*/**", // Для shared +1 уровень, т.к. там чаще мы обращаемся к конкретной библиотеке/компоненты | |
// Prefer absolute imports instead of relatives (for root modules) | |
"../**/app", | |
"../**/pages", | |
"../**/features", | |
"../**/entities", | |
"../**/shared", | |
]; | |
module.exports = { | |
parser: "@typescript-eslint/parser", | |
parserOptions: { | |
ecmaVersion: 2020, | |
ecmaFeatures: { | |
jsx: true, | |
modules: true, | |
}, | |
sourceType: "module", | |
}, | |
env: { | |
browser: true, | |
es6: true, | |
}, | |
plugins: ["react", "@typescript-eslint"], | |
extends: [ | |
"react-app", | |
"eslint:recommended", | |
"plugin:import/errors", | |
"plugin:import/warnings", | |
"plugin:import/typescript", | |
"plugin:prettier/recommended", | |
"plugin:react/recommended", | |
"prettier", | |
], | |
rules: { | |
// TODO: eslint-plugin-boundaries | |
"import/order": [ | |
2, | |
{ | |
pathGroups: ALLOWED_PATH_GROUPS, | |
pathGroupsExcludedImportTypes: ["builtin"], | |
groups: ["builtin", "external", "internal", "parent", "sibling", "index"], | |
}, | |
], | |
"no-restricted-imports": [ | |
2, | |
{ | |
patterns: DENIED_PATH_GROUPS | |
} | |
], | |
}, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment