Skip to content

Commit

Permalink
fix: refactor AST parsing for custom ESLint rule
Browse files Browse the repository at this point in the history
  • Loading branch information
doprz committed Mar 6, 2024
1 parent 7ab5b15 commit 62f0851
Show file tree
Hide file tree
Showing 4 changed files with 546 additions and 121 deletions.
13 changes: 5 additions & 8 deletions custom-eslint-rules/restrict-import-depth.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,11 @@ module.exports = {
return {
ImportDeclaration(node) {
const importPath = node.source.value;
if (importPath.startsWith('../')) {
const depth = importPath.match(/\.\.\//g).length;
if (depth > 2) {
context.report({
node,
message: 'Importing files more than 2 directories up is not allowed.',
});
}
if (importPath.startsWith('../../')) {
context.report({
node,
message: 'Importing files more than 2 directories up is not allowed.',
});
}
},
};
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-prefer-function-component": "^3.3.0",
"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-storybook": "^0.6.15",
"path": "^0.12.7",
Expand Down
Loading

0 comments on commit 62f0851

Please sign in to comment.