Update
This commit is contained in:
39
src/custom/no-import-dot.ts
Normal file
39
src/custom/no-import-dot.ts
Normal file
@ -0,0 +1,39 @@
|
||||
import type { Rule } from 'eslint';
|
||||
|
||||
const rule: Rule.RuleModule = {
|
||||
meta: {
|
||||
type: 'problem',
|
||||
docs: {
|
||||
description:
|
||||
"Bans import from the specifier '.' and '..' and replaces it with '.+/index'",
|
||||
category: 'Best Practices',
|
||||
recommended: true,
|
||||
},
|
||||
fixable: 'code',
|
||||
},
|
||||
create: context => ({
|
||||
ImportDeclaration(node) {
|
||||
if (node.source.value === '.') {
|
||||
context.report({
|
||||
node: node.source,
|
||||
message:
|
||||
"Importing from the specifier '.' is not allowed. Use './index' instead.",
|
||||
fix(fixer) {
|
||||
return fixer.replaceText(node.source, '"./index"');
|
||||
},
|
||||
});
|
||||
} else if (node.source.value === '..') {
|
||||
context.report({
|
||||
node: node.source,
|
||||
message:
|
||||
"Importing from the specifier '..' is not allowed. Use '../index' instead.",
|
||||
fix(fixer) {
|
||||
return fixer.replaceText(node.source, '"../index"');
|
||||
},
|
||||
});
|
||||
}
|
||||
},
|
||||
}),
|
||||
};
|
||||
|
||||
export default rule;
|
Reference in New Issue
Block a user