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

45 lines
1.7 KiB
Plaintext

import path from 'node:path';
import { importType, createRule, moduleVisitor, makeOptionsSchema, resolve, } from '../utils/index.js';
export default createRule({
name: 'no-relative-parent-imports',
meta: {
type: 'suggestion',
docs: {
category: 'Static analysis',
description: 'Forbid importing modules from parent directories.',
},
schema: [makeOptionsSchema()],
messages: {
noAllowed: "Relative imports from parent directories are not allowed. Please either pass what you're importing through at runtime (dependency injection), move `{{filename}}` to same directory as `{{depPath}}` or consider making `{{depPath}}` a package.",
},
},
defaultOptions: [],
create(context) {
const filename = context.physicalFilename;
if (filename === '<text>') {
return {};
}
return moduleVisitor(sourceNode => {
const depPath = sourceNode.value;
if (importType(depPath, context) === 'external') {
return;
}
const absDepPath = resolve(depPath, context);
if (!absDepPath) {
return;
}
const relDepPath = path.relative(path.dirname(filename), absDepPath);
if (importType(relDepPath, context) === 'parent') {
context.report({
node: sourceNode,
messageId: 'noAllowed',
data: {
filename: path.basename(filename),
depPath,
},
});
}
}, context.options[0]);
},
});
//# sourceMappingURL=no-relative-parent-imports.js.map