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 { 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; context.report({
if (depth > 2) { node,
context.report({ message: 'Importing files more than 2 directories up is not allowed.',
node, });
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

View File

@@ -2,7 +2,7 @@ import createSchedule from '@pages/background/lib/createSchedule';
import switchSchedule from '@pages/background/lib/switchSchedule'; import switchSchedule from '@pages/background/lib/switchSchedule';
import type { UserSchedule } from '@shared/types/UserSchedule'; import type { UserSchedule } from '@shared/types/UserSchedule';
import useSchedules from '@views/hooks/useSchedules'; import useSchedules from '@views/hooks/useSchedules';
import React, { useEffect,useState } from 'react'; import React, { useEffect, useState } from 'react';
import AddSchedule from '~icons/material-symbols/add'; import AddSchedule from '~icons/material-symbols/add';