Files
NapCatQQ/.pnpm-store/v3/files/31/90da054e106a468b397288d1eab3a6439f6429de39ed3e7a1f7c92348beeef32f20c2e00953fa9135ac3b81008810d4e9ad05b7748a79dc2693b29e4c6b223
T
TanTan e311ca3275
Build NapCat Artifacts / Type Check & Test (push) Waiting to run
docs: 仓库链接指向本镜像仓库
2026-11-13 09:25:58 +08:00

38 lines
1.3 KiB
Plaintext

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