fix: refactor AST parsing for custom ESLint rule

This commit is contained in:
doprz
2024-02-29 20:49:24 -06:00
parent 7ab5b157b1
commit 62f0851406
4 changed files with 546 additions and 121 deletions

View File

@@ -20,15 +20,12 @@ module.exports = {
return { return {
ImportDeclaration(node) { ImportDeclaration(node) {
const importPath = node.source.value; const importPath = node.source.value;
if (importPath.startsWith('../')) { if (importPath.startsWith('../../')) {
const depth = importPath.match(/\.\.\//g).length;
if (depth > 2) {
context.report({ context.report({
node, node,
message: 'Importing files more than 2 directories up is not allowed.', message: 'Importing files more than 2 directories up is not allowed.',
}); });
} }
}
}, },
}; };
}, },

View File

@@ -94,7 +94,7 @@
"eslint-plugin-react-hooks": "^4.6.0", "eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-prefer-function-component": "^3.3.0", "eslint-plugin-react-prefer-function-component": "^3.3.0",
"eslint-plugin-react-refresh": "^0.4.5", "eslint-plugin-react-refresh": "^0.4.5",
"eslint-plugin-restrict-import-depth": "file:custom-eslint-rules", "eslint-plugin-restrict-import-depth": "link:./custom-eslint-rules",
"eslint-plugin-simple-import-sort": "^12.0.0", "eslint-plugin-simple-import-sort": "^12.0.0",
"eslint-plugin-storybook": "^0.6.15", "eslint-plugin-storybook": "^0.6.15",
"path": "^0.12.7", "path": "^0.12.7",

650
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff