eslint-plugin-esm 0.3.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +20 -0
- package/dist/common.d.ts +2 -2
- package/dist/common.d.ts.map +1 -1
- package/dist/common.js +5 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -5
- package/dist/rules/no-declaration-file-imports.d.ts +5 -0
- package/dist/rules/no-declaration-file-imports.d.ts.map +1 -0
- package/dist/rules/no-declaration-file-imports.js +11 -0
- package/dist/rules/no-directory-imports.js +1 -1
- package/dist/rules/no-dynamic-imports.js +1 -1
- package/dist/rules/no-empty-exports.js +1 -1
- package/dist/rules/no-git-ignored-imports.js +1 -1
- package/dist/rules/no-inexistent-relative-imports.d.ts +5 -0
- package/dist/rules/no-inexistent-relative-imports.d.ts.map +1 -0
- package/dist/rules/no-inexistent-relative-imports.js +64 -0
- package/dist/rules/no-phantom-dep-imports.js +1 -1
- package/dist/rules/no-relative-parent-imports.js +1 -1
- package/dist/rules/no-rename-exports.js +1 -1
- package/dist/rules/no-rename-imports.js +1 -1
- package/dist/rules/no-side-effect-imports.js +1 -1
- package/dist/rules/no-useless-path-segments.d.ts +5 -0
- package/dist/rules/no-useless-path-segments.d.ts.map +1 -0
- package/dist/rules/no-useless-path-segments.js +28 -0
- package/dist/rules/required-exports.js +1 -1
- package/doc/rules/{no-ts-file-imports.md → no-declaration-file-imports.md} +7 -7
- package/doc/rules/no-inexistent-relative-imports.md +28 -0
- package/doc/rules/no-phantom-dep-imports.md +1 -1
- package/doc/rules/{nearest-relative-path.md → no-useless-path-segments.md} +7 -1
- package/package.json +4 -6
- package/src/common.ts +5 -5
- package/src/index.ts +16 -14
- package/src/rules/{no-ts-file-imports.spec.ts → no-declaration-file-imports.spec.ts} +13 -10
- package/src/rules/no-declaration-file-imports.ts +12 -0
- package/src/rules/no-directory-imports.spec.ts +2 -2
- package/src/rules/no-directory-imports.ts +2 -2
- package/src/rules/no-dynamic-imports.spec.ts +2 -2
- package/src/rules/no-dynamic-imports.ts +1 -1
- package/src/rules/no-empty-exports.spec.ts +2 -2
- package/src/rules/no-empty-exports.ts +1 -1
- package/src/rules/no-git-ignored-imports.spec.ts +2 -2
- package/src/rules/no-git-ignored-imports.ts +2 -2
- package/src/rules/no-inexistent-relative-imports.spec.ts +27 -0
- package/src/rules/no-inexistent-relative-imports.ts +72 -0
- package/src/rules/no-phantom-dep-imports.spec.ts +3 -3
- package/src/rules/no-phantom-dep-imports.ts +1 -1
- package/src/rules/no-relative-parent-imports.spec.ts +2 -2
- package/src/rules/no-relative-parent-imports.ts +1 -1
- package/src/rules/no-rename-exports.spec.ts +2 -2
- package/src/rules/no-rename-exports.ts +1 -1
- package/src/rules/no-rename-imports.spec.ts +2 -2
- package/src/rules/no-rename-imports.ts +1 -1
- package/src/rules/no-side-effect-imports.spec.ts +2 -2
- package/src/rules/no-side-effect-imports.ts +1 -1
- package/src/rules/{nearest-relative-path.spec.ts → no-useless-path-segments.spec.ts} +11 -3
- package/src/rules/{nearest-relative-path.ts → no-useless-path-segments.ts} +6 -3
- package/src/rules/required-exports.spec.ts +2 -2
- package/src/rules/required-exports.ts +1 -1
- package/dist/rules/nearest-relative-path.d.ts +0 -5
- package/dist/rules/nearest-relative-path.d.ts.map +0 -1
- package/dist/rules/nearest-relative-path.js +0 -25
- package/dist/rules/no-ts-file-imports.d.ts +0 -5
- package/dist/rules/no-ts-file-imports.d.ts.map +0 -1
- package/dist/rules/no-ts-file-imports.js +0 -14
- package/src/rules/no-ts-file-imports.ts +0 -15
- package/src/test.spec.ts +0 -123
package/src/test.spec.ts
DELETED
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs/promises";
|
|
2
|
-
import { createRequire } from "node:module";
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
import process from "node:process";
|
|
5
|
-
import { describe, it } from "node:test";
|
|
6
|
-
import { fileURLToPath } from "node:url";
|
|
7
|
-
import { RuleTester, type Rule } from "eslint";
|
|
8
|
-
import { outdent } from "outdent";
|
|
9
|
-
|
|
10
|
-
export type TestCase =
|
|
11
|
-
| string
|
|
12
|
-
| { code: string; filename?: string; options?: unknown };
|
|
13
|
-
|
|
14
|
-
const tester = new RuleTester({
|
|
15
|
-
parser: createRequire(import.meta.url).resolve("@typescript-eslint/parser"),
|
|
16
|
-
parserOptions: { ecmaVersion: "latest", sourceType: "module" },
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
export async function test({
|
|
20
|
-
name,
|
|
21
|
-
rule,
|
|
22
|
-
valid,
|
|
23
|
-
invalid,
|
|
24
|
-
errors = 1,
|
|
25
|
-
}: {
|
|
26
|
-
name: string;
|
|
27
|
-
rule: Rule.RuleModule;
|
|
28
|
-
valid: TestCase[];
|
|
29
|
-
invalid: TestCase[];
|
|
30
|
-
errors?: number;
|
|
31
|
-
}) {
|
|
32
|
-
await describe(name, async () => {
|
|
33
|
-
await Promise.all(
|
|
34
|
-
valid.map(async (testCase) => {
|
|
35
|
-
await it(JSON.stringify(testCase), () => {
|
|
36
|
-
tester.run(name, rule, {
|
|
37
|
-
valid: [testCase],
|
|
38
|
-
invalid: [],
|
|
39
|
-
...(typeof testCase === "object" && testCase.options
|
|
40
|
-
? { options: testCase.options }
|
|
41
|
-
: {}),
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
}),
|
|
45
|
-
);
|
|
46
|
-
|
|
47
|
-
await Promise.all(
|
|
48
|
-
invalid.map(async (testCase) => {
|
|
49
|
-
await it(JSON.stringify(testCase), () => {
|
|
50
|
-
const code = typeof testCase === "string" ? testCase : testCase.code;
|
|
51
|
-
const filename =
|
|
52
|
-
typeof testCase === "string" ? undefined : testCase.filename;
|
|
53
|
-
tester.run(name, rule, {
|
|
54
|
-
valid: [],
|
|
55
|
-
invalid: [{ code, errors, filename }],
|
|
56
|
-
...(typeof testCase === "object" && testCase.options
|
|
57
|
-
? { options: testCase.options }
|
|
58
|
-
: {}),
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
}),
|
|
62
|
-
);
|
|
63
|
-
|
|
64
|
-
await genDoc({ name, rule, valid, invalid });
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
async function genDoc({
|
|
69
|
-
name,
|
|
70
|
-
rule,
|
|
71
|
-
valid,
|
|
72
|
-
invalid,
|
|
73
|
-
}: {
|
|
74
|
-
name: string;
|
|
75
|
-
rule: Rule.RuleModule;
|
|
76
|
-
valid: TestCase[];
|
|
77
|
-
invalid: TestCase[];
|
|
78
|
-
}) {
|
|
79
|
-
const handle = (testCases: TestCase[]) =>
|
|
80
|
-
testCases
|
|
81
|
-
.map((testCase) =>
|
|
82
|
-
typeof testCase === "string" ? { code: testCase } : testCase,
|
|
83
|
-
)
|
|
84
|
-
.map((testCase) => {
|
|
85
|
-
if (!testCase.filename && !testCase.options) {
|
|
86
|
-
return testCase.code;
|
|
87
|
-
}
|
|
88
|
-
const filename = testCase.filename && `filename: ${testCase.filename}`;
|
|
89
|
-
const options =
|
|
90
|
-
testCase.options && `options: ${JSON.stringify(testCase.options)}`;
|
|
91
|
-
const comment = [filename, options].filter((i) => !!i).join(", ");
|
|
92
|
-
return `${testCase.code} // ${comment}`;
|
|
93
|
-
})
|
|
94
|
-
.join("\n");
|
|
95
|
-
const mdContent = outdent`
|
|
96
|
-
<!-- prettier-ignore-start -->
|
|
97
|
-
# ${name}
|
|
98
|
-
|
|
99
|
-
${rule.meta?.docs?.description}
|
|
100
|
-
|
|
101
|
-
## Rule Details
|
|
102
|
-
|
|
103
|
-
### Fail
|
|
104
|
-
|
|
105
|
-
\`\`\`ts
|
|
106
|
-
${handle(invalid)}
|
|
107
|
-
\`\`\`
|
|
108
|
-
|
|
109
|
-
### Pass
|
|
110
|
-
|
|
111
|
-
\`\`\`ts
|
|
112
|
-
${handle(valid)}
|
|
113
|
-
\`\`\`
|
|
114
|
-
<!-- prettier-ignore-end -->
|
|
115
|
-
|
|
116
|
-
`.replaceAll(process.cwd(), "/foo");
|
|
117
|
-
|
|
118
|
-
const currentDir = path.dirname(fileURLToPath(import.meta.url));
|
|
119
|
-
await fs.writeFile(
|
|
120
|
-
path.join(currentDir, "..", "doc", "rules", `${name}.md`),
|
|
121
|
-
mdContent,
|
|
122
|
-
);
|
|
123
|
-
}
|