Skip to content

Instantly share code, notes, and snippets.

@SQReder
Forked from azinit/.eslintrc.js
Created October 4, 2021 12:25
Show Gist options
  • Save SQReder/aaad2e0dcdabfab0e526e651b52bfe77 to your computer and use it in GitHub Desktop.
Save SQReder/aaad2e0dcdabfab0e526e651b52bfe77 to your computer and use it in GitHub Desktop.
imports-linting: order, access
/** Разрешенные импорты (для сортировки) */
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