feat: check-path-alias autofix (#124)

* feat: add autofix

* chore: autofix repo with new custom ESLint rule
This commit is contained in:
doprz
2024-03-02 12:28:28 -06:00
parent 208103d708
commit 265652c420
12 changed files with 27 additions and 20 deletions

View File

@@ -12,7 +12,7 @@ module.exports = {
category: 'Possible Errors',
recommended: true,
},
fixable: null,
fixable: 'code', // Enable autofix
schema: [],
},
@@ -43,9 +43,16 @@ module.exports = {
}
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: 'Use a path alias here',
message: `Run autofix to use path alias: ${alias}`,
fix: fixer => {
return fixer.replaceText(node.source, `'${updatedImportPath}'`);
},
});
}
},