first commit
This commit is contained in:
38
node_modules/eslint-plugin-import-x/lib/rules/no-absolute-path.js
generated
vendored
Normal file
38
node_modules/eslint-plugin-import-x/lib/rules/no-absolute-path.js
generated
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
import path from 'node:path';
|
||||
import { isAbsolute, createRule, moduleVisitor, makeOptionsSchema, } from '../utils/index.js';
|
||||
export default createRule({
|
||||
name: 'no-absolute-path',
|
||||
meta: {
|
||||
type: 'suggestion',
|
||||
docs: {
|
||||
category: 'Static analysis',
|
||||
description: 'Forbid import of modules using absolute paths.',
|
||||
},
|
||||
fixable: 'code',
|
||||
schema: [makeOptionsSchema()],
|
||||
messages: {
|
||||
absolute: 'Do not import modules using an absolute path',
|
||||
},
|
||||
},
|
||||
defaultOptions: [],
|
||||
create(context) {
|
||||
const options = { esmodule: true, commonjs: true, ...context.options[0] };
|
||||
return moduleVisitor(source => {
|
||||
if (!isAbsolute(source.value)) {
|
||||
return;
|
||||
}
|
||||
context.report({
|
||||
node: source,
|
||||
messageId: 'absolute',
|
||||
fix(fixer) {
|
||||
let relativePath = path.posix.relative(path.dirname(context.physicalFilename), source.value);
|
||||
if (!relativePath.startsWith('.')) {
|
||||
relativePath = `./${relativePath}`;
|
||||
}
|
||||
return fixer.replaceText(source, JSON.stringify(relativePath));
|
||||
},
|
||||
});
|
||||
}, options);
|
||||
},
|
||||
});
|
||||
//# sourceMappingURL=no-absolute-path.js.map
|
||||
Reference in New Issue
Block a user