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,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.',
});
}
},
};