Created
May 19, 2021 07:23
-
-
Save azinit/4cb940a1d4a3e05ef47e15aa18a9ecc5 to your computer and use it in GitHub Desktop.
imports-linting: order, access
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
/** Разрешенные импорты (для сортировки) */ | |
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
This is a config for the boundaries plugin to get started from. Take a note that
~/
prefix is used for absolute imports, so extra configuration in tsconfig.json is required. If you won't use this prefix for just remove~/
from rules configEslint plugins:
eslintrc.js
tsconfig.json