chore: use eslint-plugin-import-essentials and update packages
This commit is contained in:
@@ -20,11 +20,11 @@
|
|||||||
],
|
],
|
||||||
"plugins": [
|
"plugins": [
|
||||||
"import",
|
"import",
|
||||||
|
"import-essentials",
|
||||||
"jsdoc",
|
"jsdoc",
|
||||||
"react-prefer-function-component",
|
"react-prefer-function-component",
|
||||||
"@typescript-eslint",
|
"@typescript-eslint",
|
||||||
"simple-import-sort",
|
"simple-import-sort",
|
||||||
"custom-utrp",
|
|
||||||
],
|
],
|
||||||
"globals": {
|
"globals": {
|
||||||
"Atomics": "readonly",
|
"Atomics": "readonly",
|
||||||
@@ -208,7 +208,7 @@
|
|||||||
"@typescript-eslint/consistent-type-imports": "error",
|
"@typescript-eslint/consistent-type-imports": "error",
|
||||||
"simple-import-sort/imports": "error",
|
"simple-import-sort/imports": "error",
|
||||||
"simple-import-sort/exports": "error",
|
"simple-import-sort/exports": "error",
|
||||||
"custom-utrp/restrict-import-depth": "error",
|
"import-essentials/restrict-import-depth": "error",
|
||||||
"custom-utrp/check-path-alias": "error",
|
"import-essentials/check-path-alias": "error",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,61 +0,0 @@
|
|||||||
/**
|
|
||||||
* @fileoverview Check if imports match the path aliases defined in tsconfig.
|
|
||||||
*/
|
|
||||||
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
meta: {
|
|
||||||
type: 'problem',
|
|
||||||
docs: {
|
|
||||||
description: 'Check if imports match the path aliases defined in tsconfig',
|
|
||||||
category: 'Possible Errors',
|
|
||||||
recommended: true,
|
|
||||||
},
|
|
||||||
fixable: 'code', // Enable autofix
|
|
||||||
schema: [],
|
|
||||||
},
|
|
||||||
|
|
||||||
create: function (context) {
|
|
||||||
return {
|
|
||||||
ImportDeclaration(node) {
|
|
||||||
const importPath = node.source.value;
|
|
||||||
// Get aliases from tsconfig and check if the import matches any of them
|
|
||||||
// "paths": {
|
|
||||||
// "src/*": ["src/*"],
|
|
||||||
// "@assets/*": ["src/assets/*"],
|
|
||||||
// "@pages/*": ["src/pages/*"],
|
|
||||||
// "@public/*": ["public/*"],
|
|
||||||
// "@shared/*": ["src/shared/*"],
|
|
||||||
// "@background/*": ["src/pages/background/*"],
|
|
||||||
// "@views/*": ["src/views/*"]
|
|
||||||
// }
|
|
||||||
const tsconfig = require('../tsconfig.json');
|
|
||||||
const paths = tsconfig.compilerOptions.paths;
|
|
||||||
let pathList = [];
|
|
||||||
|
|
||||||
for (let key in paths) {
|
|
||||||
paths[key].forEach(value => {
|
|
||||||
if (key.startsWith('@')) {
|
|
||||||
pathList.push(value.replace('/*', ''));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pathList.some(path => importPath.startsWith(path))) {
|
|
||||||
const matchingPath = pathList.find(path => importPath.startsWith(path));
|
|
||||||
const alias = Object.keys(paths).find(key => paths[key].includes(matchingPath + '/*'));
|
|
||||||
const aliasParsed = alias.replace('/*', '');
|
|
||||||
const updatedImportPath = importPath.replace(matchingPath, aliasParsed);
|
|
||||||
context.report({
|
|
||||||
node,
|
|
||||||
message: `Run autofix to use path alias: ${alias}`,
|
|
||||||
fix: fixer => {
|
|
||||||
return fixer.replaceText(node.source, `'${updatedImportPath}'`);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
};
|
|
||||||
},
|
|
||||||
};
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
module.exports = {
|
|
||||||
rules: {
|
|
||||||
'restrict-import-depth': require('./restrict-import-depth'),
|
|
||||||
'check-path-alias': require('./check-path-alias'),
|
|
||||||
},
|
|
||||||
};
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "eslint-plugin-custom-utrp",
|
|
||||||
"version": "0.1.0",
|
|
||||||
"description": "Custom ESLint rules for UTRP",
|
|
||||||
"main": "index.js"
|
|
||||||
}
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
/**
|
|
||||||
* @fileoverview Custom ESLint rule to restrict imports from accessing files more than 2 directories up.
|
|
||||||
*/
|
|
||||||
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
meta: {
|
|
||||||
type: 'problem',
|
|
||||||
docs: {
|
|
||||||
description: 'Restrict imports from accessing files more than 2 directories up.',
|
|
||||||
category: 'Best Practices',
|
|
||||||
recommended: true,
|
|
||||||
},
|
|
||||||
fixable: null,
|
|
||||||
schema: [],
|
|
||||||
},
|
|
||||||
|
|
||||||
create: function (context) {
|
|
||||||
return {
|
|
||||||
ImportDeclaration(node) {
|
|
||||||
const importPath = node.source.value;
|
|
||||||
if (importPath.startsWith('../../')) {
|
|
||||||
context.report({
|
|
||||||
node,
|
|
||||||
message: 'Importing files more than 2 directories up is not allowed',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
};
|
|
||||||
},
|
|
||||||
};
|
|
||||||
15
package.json
15
package.json
@@ -58,11 +58,11 @@
|
|||||||
"@svgr/core": "^8.1.0",
|
"@svgr/core": "^8.1.0",
|
||||||
"@svgr/plugin-jsx": "^8.1.0",
|
"@svgr/plugin-jsx": "^8.1.0",
|
||||||
"@types/chrome": "^0.0.260",
|
"@types/chrome": "^0.0.260",
|
||||||
"@types/node": "^20.11.20",
|
"@types/node": "^20.11.24",
|
||||||
"@types/prompts": "^2.4.9",
|
"@types/prompts": "^2.4.9",
|
||||||
"@types/react": "^18.2.57",
|
"@types/react": "^18.2.61",
|
||||||
"@types/react-dom": "^18.2.19",
|
"@types/react-dom": "^18.2.19",
|
||||||
"@types/semver": "^7.5.7",
|
"@types/semver": "^7.5.8",
|
||||||
"@types/uuid": "^9.0.8",
|
"@types/uuid": "^9.0.8",
|
||||||
"@typescript-eslint/eslint-plugin": "^6.21.0",
|
"@typescript-eslint/eslint-plugin": "^6.21.0",
|
||||||
"@typescript-eslint/parser": "^6.21.0",
|
"@typescript-eslint/parser": "^6.21.0",
|
||||||
@@ -77,24 +77,25 @@
|
|||||||
"@vitest/coverage-v8": "^1.3.1",
|
"@vitest/coverage-v8": "^1.3.1",
|
||||||
"@vitest/ui": "^1.3.1",
|
"@vitest/ui": "^1.3.1",
|
||||||
"chromatic": "^10.9.6",
|
"chromatic": "^10.9.6",
|
||||||
"cssnano": "^6.0.4",
|
"cssnano": "^6.0.5",
|
||||||
"cssnano-preset-advanced": "^6.0.4",
|
"cssnano-preset-advanced": "^6.0.5",
|
||||||
"dotenv": "^16.4.5",
|
"dotenv": "^16.4.5",
|
||||||
"es-module-lexer": "^1.4.1",
|
"es-module-lexer": "^1.4.1",
|
||||||
"eslint": "^8.56.0",
|
"eslint": "^8.57.0",
|
||||||
"eslint-config-airbnb": "^19.0.4",
|
"eslint-config-airbnb": "^19.0.4",
|
||||||
"eslint-config-airbnb-base": "^15.0.0",
|
"eslint-config-airbnb-base": "^15.0.0",
|
||||||
"eslint-config-airbnb-typescript": "^17.1.0",
|
"eslint-config-airbnb-typescript": "^17.1.0",
|
||||||
"eslint-config-prettier": "^9.1.0",
|
"eslint-config-prettier": "^9.1.0",
|
||||||
"eslint-import-resolver-typescript": "^3.6.1",
|
"eslint-import-resolver-typescript": "^3.6.1",
|
||||||
|
"eslint-plugin-custom-utrp": "link:custom-eslint-rules",
|
||||||
"eslint-plugin-import": "^2.29.1",
|
"eslint-plugin-import": "^2.29.1",
|
||||||
|
"eslint-plugin-import-essentials": "^0.2.1",
|
||||||
"eslint-plugin-jsdoc": "^48.2.0",
|
"eslint-plugin-jsdoc": "^48.2.0",
|
||||||
"eslint-plugin-prettier": "^5.1.3",
|
"eslint-plugin-prettier": "^5.1.3",
|
||||||
"eslint-plugin-react": "^7.33.2",
|
"eslint-plugin-react": "^7.33.2",
|
||||||
"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-custom-utrp": "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",
|
||||||
|
|||||||
2114
pnpm-lock.yaml
generated
2114
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user