@simplysm/lint 13.0.100 → 14.0.1
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/dist/eslint-plugin.js +7 -10
- package/dist/eslint-plugin.js.map +1 -6
- package/dist/eslint-recommended.d.ts +2 -1
- package/dist/eslint-recommended.d.ts.map +1 -1
- package/dist/eslint-recommended.js +147 -244
- package/dist/eslint-recommended.js.map +1 -6
- package/dist/rules/no-hard-private.d.ts +6 -6
- package/dist/rules/no-hard-private.js +109 -88
- package/dist/rules/no-hard-private.js.map +1 -6
- package/dist/rules/no-subpath-imports-from-simplysm.d.ts +5 -5
- package/dist/rules/no-subpath-imports-from-simplysm.js +72 -60
- package/dist/rules/no-subpath-imports-from-simplysm.js.map +1 -6
- package/dist/rules/ts-no-throw-not-implemented-error.d.ts +5 -5
- package/dist/rules/ts-no-throw-not-implemented-error.js +92 -58
- package/dist/rules/ts-no-throw-not-implemented-error.js.map +1 -6
- package/dist/utils/create-rule.d.ts +3 -3
- package/dist/utils/create-rule.js +19 -7
- package/dist/utils/create-rule.js.map +1 -6
- package/package.json +9 -12
- package/src/eslint-recommended.ts +28 -115
- package/src/rules/no-hard-private.ts +23 -23
- package/src/rules/no-subpath-imports-from-simplysm.ts +13 -13
- package/src/rules/ts-no-throw-not-implemented-error.ts +14 -14
- package/src/utils/create-rule.ts +3 -3
- package/README.md +0 -81
- package/tests/no-hard-private.spec.ts +0 -888
- package/tests/no-subpath-imports-from-simplysm.spec.ts +0 -311
- package/tests/recommended.spec.ts +0 -145
- package/tests/ts-no-throw-not-implemented-error.spec.ts +0 -245
- package/tests/vitest.setup.ts +0 -10
|
@@ -1,311 +0,0 @@
|
|
|
1
|
-
import "./vitest.setup";
|
|
2
|
-
import { describe } from "vitest";
|
|
3
|
-
import { RuleTester } from "@typescript-eslint/rule-tester";
|
|
4
|
-
import rule from "../src/rules/no-subpath-imports-from-simplysm";
|
|
5
|
-
|
|
6
|
-
const ruleTester = new RuleTester();
|
|
7
|
-
|
|
8
|
-
describe("no-subpath-imports-from-simplysm rule", () => {
|
|
9
|
-
describe("allowed code (valid)", () => {
|
|
10
|
-
describe("package root import is allowed", () => {
|
|
11
|
-
ruleTester.run("no-subpath-imports-from-simplysm", rule, {
|
|
12
|
-
valid: [
|
|
13
|
-
{
|
|
14
|
-
code: `import { Something } from "@simplysm/sd-core-common";`,
|
|
15
|
-
},
|
|
16
|
-
],
|
|
17
|
-
invalid: [],
|
|
18
|
-
});
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
describe("subpath import other than src is allowed", () => {
|
|
22
|
-
ruleTester.run("no-subpath-imports-from-simplysm", rule, {
|
|
23
|
-
valid: [
|
|
24
|
-
{
|
|
25
|
-
code: `import { Something } from "@simplysm/sd-core-common/utils";`,
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
code: `import { Something } from "@simplysm/sd-core-common/types/DateOnly";`,
|
|
29
|
-
},
|
|
30
|
-
],
|
|
31
|
-
invalid: [],
|
|
32
|
-
});
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
describe("packages other than @simplysm are allowed", () => {
|
|
36
|
-
ruleTester.run("no-subpath-imports-from-simplysm", rule, {
|
|
37
|
-
valid: [
|
|
38
|
-
{
|
|
39
|
-
code: `import { Something } from "@angular/core";`,
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
code: `import { Something } from "lodash/src/utils";`,
|
|
43
|
-
},
|
|
44
|
-
],
|
|
45
|
-
invalid: [],
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
describe("dynamic import - path other than src is allowed", () => {
|
|
50
|
-
ruleTester.run("no-subpath-imports-from-simplysm", rule, {
|
|
51
|
-
valid: [
|
|
52
|
-
{
|
|
53
|
-
code: `const mod = await import("@simplysm/sd-core-common");`,
|
|
54
|
-
},
|
|
55
|
-
{
|
|
56
|
-
code: `const mod = await import("@simplysm/sd-core-common/utils");`,
|
|
57
|
-
},
|
|
58
|
-
],
|
|
59
|
-
invalid: [],
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
describe("re-export - path other than src is allowed", () => {
|
|
64
|
-
ruleTester.run("no-subpath-imports-from-simplysm", rule, {
|
|
65
|
-
valid: [
|
|
66
|
-
{
|
|
67
|
-
code: `export { Something } from "@simplysm/sd-core-common";`,
|
|
68
|
-
},
|
|
69
|
-
{
|
|
70
|
-
code: `export * from "@simplysm/sd-core-common/utils";`,
|
|
71
|
-
},
|
|
72
|
-
],
|
|
73
|
-
invalid: [],
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
describe("code that should cause errors (invalid)", () => {
|
|
79
|
-
describe("@simplysm/*/src import is prohibited", () => {
|
|
80
|
-
ruleTester.run("no-subpath-imports-from-simplysm", rule, {
|
|
81
|
-
valid: [],
|
|
82
|
-
invalid: [
|
|
83
|
-
{
|
|
84
|
-
code: `import { Something } from "@simplysm/sd-core-common/src";`,
|
|
85
|
-
output: `import { Something } from "@simplysm/sd-core-common";`,
|
|
86
|
-
errors: [
|
|
87
|
-
{
|
|
88
|
-
messageId: "noSubpathImport",
|
|
89
|
-
data: {
|
|
90
|
-
pkg: "sd-core-common",
|
|
91
|
-
importPath: "@simplysm/sd-core-common/src",
|
|
92
|
-
},
|
|
93
|
-
},
|
|
94
|
-
],
|
|
95
|
-
},
|
|
96
|
-
],
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
describe("@simplysm/*/src/xxx import is prohibited", () => {
|
|
101
|
-
ruleTester.run("no-subpath-imports-from-simplysm", rule, {
|
|
102
|
-
valid: [],
|
|
103
|
-
invalid: [
|
|
104
|
-
{
|
|
105
|
-
code: `import { DateOnly } from "@simplysm/sd-core-common/src/types/DateOnly";`,
|
|
106
|
-
output: `import { DateOnly } from "@simplysm/sd-core-common";`,
|
|
107
|
-
errors: [
|
|
108
|
-
{
|
|
109
|
-
messageId: "noSubpathImport",
|
|
110
|
-
data: {
|
|
111
|
-
pkg: "sd-core-common",
|
|
112
|
-
importPath: "@simplysm/sd-core-common/src/types/DateOnly",
|
|
113
|
-
},
|
|
114
|
-
},
|
|
115
|
-
],
|
|
116
|
-
},
|
|
117
|
-
],
|
|
118
|
-
});
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
describe("src import prohibited from multiple packages", () => {
|
|
122
|
-
ruleTester.run("no-subpath-imports-from-simplysm", rule, {
|
|
123
|
-
valid: [],
|
|
124
|
-
invalid: [
|
|
125
|
-
{
|
|
126
|
-
code: `import { SdServiceClient } from "@simplysm/sd-service-client/src/SdServiceClient";`,
|
|
127
|
-
output: `import { SdServiceClient } from "@simplysm/sd-service-client";`,
|
|
128
|
-
errors: [
|
|
129
|
-
{
|
|
130
|
-
messageId: "noSubpathImport",
|
|
131
|
-
data: {
|
|
132
|
-
pkg: "sd-service-client",
|
|
133
|
-
importPath: "@simplysm/sd-service-client/src/SdServiceClient",
|
|
134
|
-
},
|
|
135
|
-
},
|
|
136
|
-
],
|
|
137
|
-
},
|
|
138
|
-
],
|
|
139
|
-
});
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
describe("src path prohibited in dynamic import", () => {
|
|
143
|
-
ruleTester.run("no-subpath-imports-from-simplysm", rule, {
|
|
144
|
-
valid: [],
|
|
145
|
-
invalid: [
|
|
146
|
-
{
|
|
147
|
-
code: `const mod = await import("@simplysm/sd-core-common/src/utils");`,
|
|
148
|
-
output: `const mod = await import("@simplysm/sd-core-common");`,
|
|
149
|
-
errors: [
|
|
150
|
-
{
|
|
151
|
-
messageId: "noSubpathImport",
|
|
152
|
-
data: {
|
|
153
|
-
pkg: "sd-core-common",
|
|
154
|
-
importPath: "@simplysm/sd-core-common/src/utils",
|
|
155
|
-
},
|
|
156
|
-
},
|
|
157
|
-
],
|
|
158
|
-
},
|
|
159
|
-
],
|
|
160
|
-
});
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
describe("src path prohibited in re-export", () => {
|
|
164
|
-
ruleTester.run("no-subpath-imports-from-simplysm", rule, {
|
|
165
|
-
valid: [],
|
|
166
|
-
invalid: [
|
|
167
|
-
{
|
|
168
|
-
code: `export { Something } from "@simplysm/sd-core-common/src/types";`,
|
|
169
|
-
output: `export { Something } from "@simplysm/sd-core-common";`,
|
|
170
|
-
errors: [
|
|
171
|
-
{
|
|
172
|
-
messageId: "noSubpathImport",
|
|
173
|
-
data: {
|
|
174
|
-
pkg: "sd-core-common",
|
|
175
|
-
importPath: "@simplysm/sd-core-common/src/types",
|
|
176
|
-
},
|
|
177
|
-
},
|
|
178
|
-
],
|
|
179
|
-
},
|
|
180
|
-
],
|
|
181
|
-
});
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
describe("src path prohibited in export * from", () => {
|
|
185
|
-
ruleTester.run("no-subpath-imports-from-simplysm", rule, {
|
|
186
|
-
valid: [],
|
|
187
|
-
invalid: [
|
|
188
|
-
{
|
|
189
|
-
code: `export * from "@simplysm/sd-core-common/src/types";`,
|
|
190
|
-
output: `export * from "@simplysm/sd-core-common";`,
|
|
191
|
-
errors: [
|
|
192
|
-
{
|
|
193
|
-
messageId: "noSubpathImport",
|
|
194
|
-
data: {
|
|
195
|
-
pkg: "sd-core-common",
|
|
196
|
-
importPath: "@simplysm/sd-core-common/src/types",
|
|
197
|
-
},
|
|
198
|
-
},
|
|
199
|
-
],
|
|
200
|
-
},
|
|
201
|
-
],
|
|
202
|
-
});
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
describe("preserve quote style when using single quotes", () => {
|
|
206
|
-
ruleTester.run("no-subpath-imports-from-simplysm", rule, {
|
|
207
|
-
valid: [],
|
|
208
|
-
invalid: [
|
|
209
|
-
{
|
|
210
|
-
code: `import { Something } from '@simplysm/sd-core-common/src';`,
|
|
211
|
-
output: `import { Something } from '@simplysm/sd-core-common';`,
|
|
212
|
-
errors: [
|
|
213
|
-
{
|
|
214
|
-
messageId: "noSubpathImport",
|
|
215
|
-
data: {
|
|
216
|
-
pkg: "sd-core-common",
|
|
217
|
-
importPath: "@simplysm/sd-core-common/src",
|
|
218
|
-
},
|
|
219
|
-
},
|
|
220
|
-
],
|
|
221
|
-
},
|
|
222
|
-
],
|
|
223
|
-
});
|
|
224
|
-
});
|
|
225
|
-
|
|
226
|
-
describe("src path prohibited in type-only import", () => {
|
|
227
|
-
ruleTester.run("no-subpath-imports-from-simplysm", rule, {
|
|
228
|
-
valid: [],
|
|
229
|
-
invalid: [
|
|
230
|
-
{
|
|
231
|
-
code: `import type { DateOnly } from "@simplysm/sd-core-common/src/types";`,
|
|
232
|
-
output: `import type { DateOnly } from "@simplysm/sd-core-common";`,
|
|
233
|
-
errors: [
|
|
234
|
-
{
|
|
235
|
-
messageId: "noSubpathImport",
|
|
236
|
-
data: {
|
|
237
|
-
pkg: "sd-core-common",
|
|
238
|
-
importPath: "@simplysm/sd-core-common/src/types",
|
|
239
|
-
},
|
|
240
|
-
},
|
|
241
|
-
],
|
|
242
|
-
},
|
|
243
|
-
],
|
|
244
|
-
});
|
|
245
|
-
});
|
|
246
|
-
|
|
247
|
-
describe("src path prohibited in export type", () => {
|
|
248
|
-
ruleTester.run("no-subpath-imports-from-simplysm", rule, {
|
|
249
|
-
valid: [],
|
|
250
|
-
invalid: [
|
|
251
|
-
{
|
|
252
|
-
code: `export type { DateOnly } from "@simplysm/sd-core-common/src/types";`,
|
|
253
|
-
output: `export type { DateOnly } from "@simplysm/sd-core-common";`,
|
|
254
|
-
errors: [
|
|
255
|
-
{
|
|
256
|
-
messageId: "noSubpathImport",
|
|
257
|
-
data: {
|
|
258
|
-
pkg: "sd-core-common",
|
|
259
|
-
importPath: "@simplysm/sd-core-common/src/types",
|
|
260
|
-
},
|
|
261
|
-
},
|
|
262
|
-
],
|
|
263
|
-
},
|
|
264
|
-
],
|
|
265
|
-
});
|
|
266
|
-
});
|
|
267
|
-
|
|
268
|
-
describe("src path prohibited in namespace import", () => {
|
|
269
|
-
ruleTester.run("no-subpath-imports-from-simplysm", rule, {
|
|
270
|
-
valid: [],
|
|
271
|
-
invalid: [
|
|
272
|
-
{
|
|
273
|
-
code: `import * as CoreCommon from "@simplysm/sd-core-common/src";`,
|
|
274
|
-
output: `import * as CoreCommon from "@simplysm/sd-core-common";`,
|
|
275
|
-
errors: [
|
|
276
|
-
{
|
|
277
|
-
messageId: "noSubpathImport",
|
|
278
|
-
data: {
|
|
279
|
-
pkg: "sd-core-common",
|
|
280
|
-
importPath: "@simplysm/sd-core-common/src",
|
|
281
|
-
},
|
|
282
|
-
},
|
|
283
|
-
],
|
|
284
|
-
},
|
|
285
|
-
],
|
|
286
|
-
});
|
|
287
|
-
});
|
|
288
|
-
|
|
289
|
-
describe("src path prohibited in side-effect import", () => {
|
|
290
|
-
ruleTester.run("no-subpath-imports-from-simplysm", rule, {
|
|
291
|
-
valid: [],
|
|
292
|
-
invalid: [
|
|
293
|
-
{
|
|
294
|
-
code: `import "@simplysm/sd-core-common/src/polyfills";`,
|
|
295
|
-
output: `import "@simplysm/sd-core-common";`,
|
|
296
|
-
errors: [
|
|
297
|
-
{
|
|
298
|
-
messageId: "noSubpathImport",
|
|
299
|
-
data: {
|
|
300
|
-
pkg: "sd-core-common",
|
|
301
|
-
importPath: "@simplysm/sd-core-common/src/polyfills",
|
|
302
|
-
},
|
|
303
|
-
},
|
|
304
|
-
],
|
|
305
|
-
},
|
|
306
|
-
],
|
|
307
|
-
});
|
|
308
|
-
});
|
|
309
|
-
|
|
310
|
-
});
|
|
311
|
-
});
|
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from "vitest";
|
|
2
|
-
import recommended from "../src/eslint-recommended";
|
|
3
|
-
import plugin from "../src/eslint-plugin";
|
|
4
|
-
|
|
5
|
-
// ESLint config type helper
|
|
6
|
-
type ConfigItem = (typeof recommended)[number];
|
|
7
|
-
|
|
8
|
-
const hasIgnores = (config: ConfigItem): config is ConfigItem & { ignores: string[] } => {
|
|
9
|
-
return "ignores" in config && Array.isArray(config.ignores);
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
const hasFiles = (config: ConfigItem): config is ConfigItem & { files: (string | string[])[] } => {
|
|
13
|
-
return "files" in config && Array.isArray(config.files);
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
const hasRules = (
|
|
17
|
-
config: ConfigItem,
|
|
18
|
-
): config is ConfigItem & { rules: Record<string, unknown> } => {
|
|
19
|
-
return "rules" in config && config.rules != null;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
const hasPlugins = (
|
|
23
|
-
config: ConfigItem,
|
|
24
|
-
): config is ConfigItem & { plugins: Record<string, unknown> } => {
|
|
25
|
-
return "plugins" in config && config.plugins != null;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
const flattenFiles = (files: (string | string[])[]): string[] => {
|
|
29
|
-
return files.flat();
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
describe("recommended config", () => {
|
|
33
|
-
it("should export as array", () => {
|
|
34
|
-
expect(Array.isArray(recommended)).toBe(true);
|
|
35
|
-
expect(recommended.length).toBeGreaterThan(0);
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it("should include globalIgnores config", () => {
|
|
39
|
-
const ignoresConfig = recommended.find(hasIgnores);
|
|
40
|
-
expect(ignoresConfig).toBeDefined();
|
|
41
|
-
if (ignoresConfig == null) return;
|
|
42
|
-
|
|
43
|
-
const expectedPatterns = ["**/node_modules/**", "**/dist/**", "**/.*/**", "**/_*/**"];
|
|
44
|
-
expect(ignoresConfig.ignores).toEqual(expect.arrayContaining(expectedPatterns));
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it("should include JS file config", () => {
|
|
48
|
-
const jsConfig = recommended.find(
|
|
49
|
-
(config) => hasFiles(config) && flattenFiles(config.files).some((f) => f.includes("*.js")),
|
|
50
|
-
);
|
|
51
|
-
expect(jsConfig).toBeDefined();
|
|
52
|
-
if (jsConfig == null) return;
|
|
53
|
-
if (hasPlugins(jsConfig)) {
|
|
54
|
-
expect(jsConfig.plugins).toHaveProperty("@simplysm");
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it("should include TS file config", () => {
|
|
59
|
-
const tsConfig = recommended.find(
|
|
60
|
-
(config) => hasFiles(config) && flattenFiles(config.files).some((f) => f.includes("*.ts")),
|
|
61
|
-
);
|
|
62
|
-
expect(tsConfig).toBeDefined();
|
|
63
|
-
if (tsConfig == null) return;
|
|
64
|
-
if (hasPlugins(tsConfig)) {
|
|
65
|
-
expect(tsConfig.plugins).toHaveProperty("@typescript-eslint");
|
|
66
|
-
expect(tsConfig.plugins).toHaveProperty("@simplysm");
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
it("should enable @simplysm custom rules with correct severity in TS config", () => {
|
|
71
|
-
const tsConfig = recommended.find(
|
|
72
|
-
(config) => hasFiles(config) && flattenFiles(config.files).some((f) => f.includes("*.ts")),
|
|
73
|
-
);
|
|
74
|
-
expect(tsConfig).toBeDefined();
|
|
75
|
-
if (tsConfig == null) return;
|
|
76
|
-
if (hasRules(tsConfig)) {
|
|
77
|
-
expect(tsConfig.rules).toHaveProperty("@simplysm/no-hard-private", "error");
|
|
78
|
-
expect(tsConfig.rules).toHaveProperty("@simplysm/no-subpath-imports-from-simplysm", "error");
|
|
79
|
-
expect(tsConfig.rules).toHaveProperty("@simplysm/ts-no-throw-not-implemented-error", "warn");
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
it("should enable @simplysm custom rules in JS config", () => {
|
|
84
|
-
const jsConfig = recommended.find(
|
|
85
|
-
(config) => hasFiles(config) && flattenFiles(config.files).some((f) => f.includes("*.js")),
|
|
86
|
-
);
|
|
87
|
-
expect(jsConfig).toBeDefined();
|
|
88
|
-
if (jsConfig == null) return;
|
|
89
|
-
if (hasRules(jsConfig)) {
|
|
90
|
-
expect(jsConfig.rules).toHaveProperty("@simplysm/no-hard-private", "error");
|
|
91
|
-
expect(jsConfig.rules).toHaveProperty("@simplysm/no-subpath-imports-from-simplysm", "error");
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
it("should disable import/no-extraneous-dependencies in test folder", () => {
|
|
96
|
-
const testConfig = recommended.find(
|
|
97
|
-
(config) =>
|
|
98
|
-
hasFiles(config) && flattenFiles(config.files).some((f) => f.includes("**/tests/**")),
|
|
99
|
-
);
|
|
100
|
-
expect(testConfig).toBeDefined();
|
|
101
|
-
if (testConfig == null) return;
|
|
102
|
-
if (hasRules(testConfig)) {
|
|
103
|
-
expect(testConfig.rules).toHaveProperty("import/no-extraneous-dependencies", "off");
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
it("should include all plugin.rules in recommended config", () => {
|
|
108
|
-
const tsConfig = recommended.find(
|
|
109
|
-
(config) => hasFiles(config) && flattenFiles(config.files).some((f) => f.includes("*.ts")),
|
|
110
|
-
);
|
|
111
|
-
expect(tsConfig).toBeDefined();
|
|
112
|
-
if (tsConfig == null) return;
|
|
113
|
-
|
|
114
|
-
if (hasRules(tsConfig)) {
|
|
115
|
-
const ruleNames = Object.keys(plugin.rules);
|
|
116
|
-
for (const ruleName of ruleNames) {
|
|
117
|
-
const fullRuleName = `@simplysm/${ruleName}`;
|
|
118
|
-
expect(tsConfig.rules, `rule '${fullRuleName}' should be included in TS config`).toHaveProperty(
|
|
119
|
-
fullRuleName,
|
|
120
|
-
);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
it("should apply solid plugin to TSX files", () => {
|
|
126
|
-
// Find config that includes solid plugin and handles .tsx files
|
|
127
|
-
// (in current implementation, **/*.ts and **/*.tsx are handled together)
|
|
128
|
-
const tsxSolidConfig = recommended.find(
|
|
129
|
-
(config) =>
|
|
130
|
-
hasFiles(config) &&
|
|
131
|
-
flattenFiles(config.files).some((f) => f.includes(".tsx")) &&
|
|
132
|
-
hasPlugins(config) &&
|
|
133
|
-
"solid" in config.plugins,
|
|
134
|
-
);
|
|
135
|
-
expect(tsxSolidConfig).toBeDefined();
|
|
136
|
-
if (tsxSolidConfig == null) return;
|
|
137
|
-
if (hasPlugins(tsxSolidConfig)) {
|
|
138
|
-
expect(tsxSolidConfig.plugins).toHaveProperty("solid");
|
|
139
|
-
}
|
|
140
|
-
if (hasRules(tsxSolidConfig)) {
|
|
141
|
-
// eslint-plugin-solid flat/typescript rules should be applied
|
|
142
|
-
expect(tsxSolidConfig.rules).toHaveProperty("solid/jsx-no-undef");
|
|
143
|
-
}
|
|
144
|
-
});
|
|
145
|
-
});
|
|
@@ -1,245 +0,0 @@
|
|
|
1
|
-
import "./vitest.setup";
|
|
2
|
-
import { describe } from "vitest";
|
|
3
|
-
import { RuleTester } from "@typescript-eslint/rule-tester";
|
|
4
|
-
import rule from "../src/rules/ts-no-throw-not-implemented-error";
|
|
5
|
-
|
|
6
|
-
const ruleTester = new RuleTester();
|
|
7
|
-
|
|
8
|
-
describe("ts-no-throw-not-implemented-error rule", () => {
|
|
9
|
-
describe("allowed code (valid)", () => {
|
|
10
|
-
describe("NotImplementedError from other modules is allowed", () => {
|
|
11
|
-
ruleTester.run("ts-no-throw-not-implemented-error", rule, {
|
|
12
|
-
valid: [
|
|
13
|
-
{
|
|
14
|
-
code: `
|
|
15
|
-
class NotImplementedError extends Error {}
|
|
16
|
-
throw new NotImplementedError();
|
|
17
|
-
`,
|
|
18
|
-
},
|
|
19
|
-
],
|
|
20
|
-
invalid: [],
|
|
21
|
-
});
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
describe("NotImplementedError from packages other than @simplysm/core-common is allowed", () => {
|
|
25
|
-
ruleTester.run("ts-no-throw-not-implemented-error", rule, {
|
|
26
|
-
valid: [
|
|
27
|
-
{
|
|
28
|
-
code: `
|
|
29
|
-
import { NotImplementedError } from "other-package";
|
|
30
|
-
throw new NotImplementedError();
|
|
31
|
-
`,
|
|
32
|
-
},
|
|
33
|
-
],
|
|
34
|
-
invalid: [],
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
describe("usage without import is allowed", () => {
|
|
39
|
-
ruleTester.run("ts-no-throw-not-implemented-error", rule, {
|
|
40
|
-
valid: [
|
|
41
|
-
{
|
|
42
|
-
code: `
|
|
43
|
-
declare const NotImplementedError: new (msg?: string) => Error;
|
|
44
|
-
new NotImplementedError();
|
|
45
|
-
`,
|
|
46
|
-
},
|
|
47
|
-
],
|
|
48
|
-
invalid: [],
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
describe("code that should cause errors (invalid)", () => {
|
|
54
|
-
describe("creating NotImplementedError imported from @simplysm/core-common with new", () => {
|
|
55
|
-
ruleTester.run("ts-no-throw-not-implemented-error", rule, {
|
|
56
|
-
valid: [],
|
|
57
|
-
invalid: [
|
|
58
|
-
{
|
|
59
|
-
code: `
|
|
60
|
-
import { NotImplementedError } from "@simplysm/core-common";
|
|
61
|
-
new NotImplementedError();
|
|
62
|
-
`,
|
|
63
|
-
errors: [{ messageId: "noThrowNotImplementedError" }],
|
|
64
|
-
},
|
|
65
|
-
],
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
describe("usage with message", () => {
|
|
70
|
-
ruleTester.run("ts-no-throw-not-implemented-error", rule, {
|
|
71
|
-
valid: [],
|
|
72
|
-
invalid: [
|
|
73
|
-
{
|
|
74
|
-
code: `
|
|
75
|
-
import { NotImplementedError } from "@simplysm/core-common";
|
|
76
|
-
throw new NotImplementedError("This feature is not yet implemented");
|
|
77
|
-
`,
|
|
78
|
-
errors: [
|
|
79
|
-
{
|
|
80
|
-
messageId: "noThrowNotImplementedError",
|
|
81
|
-
data: { text: "This feature is not yet implemented" },
|
|
82
|
-
},
|
|
83
|
-
],
|
|
84
|
-
},
|
|
85
|
-
],
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
describe("also detects when imported as alias", () => {
|
|
90
|
-
ruleTester.run("ts-no-throw-not-implemented-error", rule, {
|
|
91
|
-
valid: [],
|
|
92
|
-
invalid: [
|
|
93
|
-
{
|
|
94
|
-
code: `
|
|
95
|
-
import { NotImplementedError as NIE } from "@simplysm/core-common";
|
|
96
|
-
new NIE();
|
|
97
|
-
`,
|
|
98
|
-
errors: [{ messageId: "noThrowNotImplementedError" }],
|
|
99
|
-
},
|
|
100
|
-
],
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
describe("multiple usages produce errors for each", () => {
|
|
105
|
-
ruleTester.run("ts-no-throw-not-implemented-error", rule, {
|
|
106
|
-
valid: [],
|
|
107
|
-
invalid: [
|
|
108
|
-
{
|
|
109
|
-
code: `
|
|
110
|
-
import { NotImplementedError } from "@simplysm/core-common";
|
|
111
|
-
new NotImplementedError("first");
|
|
112
|
-
new NotImplementedError("second");
|
|
113
|
-
`,
|
|
114
|
-
errors: [
|
|
115
|
-
{ messageId: "noThrowNotImplementedError", data: { text: "first" } },
|
|
116
|
-
{ messageId: "noThrowNotImplementedError", data: { text: "second" } },
|
|
117
|
-
],
|
|
118
|
-
},
|
|
119
|
-
],
|
|
120
|
-
});
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
describe("usage with namespace import", () => {
|
|
124
|
-
ruleTester.run("ts-no-throw-not-implemented-error", rule, {
|
|
125
|
-
valid: [],
|
|
126
|
-
invalid: [
|
|
127
|
-
{
|
|
128
|
-
code: `
|
|
129
|
-
import * as CoreCommon from "@simplysm/core-common";
|
|
130
|
-
throw new CoreCommon.NotImplementedError();
|
|
131
|
-
`,
|
|
132
|
-
errors: [{ messageId: "noThrowNotImplementedError" }],
|
|
133
|
-
},
|
|
134
|
-
],
|
|
135
|
-
});
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
describe("template literal argument falls back to default message", () => {
|
|
139
|
-
ruleTester.run("ts-no-throw-not-implemented-error", rule, {
|
|
140
|
-
valid: [],
|
|
141
|
-
invalid: [
|
|
142
|
-
{
|
|
143
|
-
code: `
|
|
144
|
-
import { NotImplementedError } from "@simplysm/core-common";
|
|
145
|
-
throw new NotImplementedError(\`dynamic message\`);
|
|
146
|
-
`,
|
|
147
|
-
errors: [
|
|
148
|
-
{
|
|
149
|
-
messageId: "noThrowNotImplementedError",
|
|
150
|
-
data: { text: "Not implemented" },
|
|
151
|
-
},
|
|
152
|
-
],
|
|
153
|
-
},
|
|
154
|
-
],
|
|
155
|
-
});
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
describe("numeric argument falls back to default message", () => {
|
|
159
|
-
ruleTester.run("ts-no-throw-not-implemented-error", rule, {
|
|
160
|
-
valid: [],
|
|
161
|
-
invalid: [
|
|
162
|
-
{
|
|
163
|
-
code: `
|
|
164
|
-
import { NotImplementedError } from "@simplysm/core-common";
|
|
165
|
-
throw new NotImplementedError(123);
|
|
166
|
-
`,
|
|
167
|
-
errors: [
|
|
168
|
-
{
|
|
169
|
-
messageId: "noThrowNotImplementedError",
|
|
170
|
-
data: { text: "Not implemented" },
|
|
171
|
-
},
|
|
172
|
-
],
|
|
173
|
-
},
|
|
174
|
-
],
|
|
175
|
-
});
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
describe("empty string argument falls back to default message", () => {
|
|
179
|
-
ruleTester.run("ts-no-throw-not-implemented-error", rule, {
|
|
180
|
-
valid: [],
|
|
181
|
-
invalid: [
|
|
182
|
-
{
|
|
183
|
-
code: `
|
|
184
|
-
import { NotImplementedError } from "@simplysm/core-common";
|
|
185
|
-
throw new NotImplementedError("");
|
|
186
|
-
`,
|
|
187
|
-
errors: [
|
|
188
|
-
{
|
|
189
|
-
messageId: "noThrowNotImplementedError",
|
|
190
|
-
data: { text: "Not implemented" },
|
|
191
|
-
},
|
|
192
|
-
],
|
|
193
|
-
},
|
|
194
|
-
],
|
|
195
|
-
});
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
describe("namespace import from other packages is allowed", () => {
|
|
201
|
-
ruleTester.run("ts-no-throw-not-implemented-error", rule, {
|
|
202
|
-
valid: [
|
|
203
|
-
{
|
|
204
|
-
code: `
|
|
205
|
-
import * as OtherPkg from "other-package";
|
|
206
|
-
new OtherPkg.NotImplementedError();
|
|
207
|
-
`,
|
|
208
|
-
},
|
|
209
|
-
],
|
|
210
|
-
invalid: [],
|
|
211
|
-
});
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
describe("limitation: re-exported NotImplementedError is not detected", () => {
|
|
215
|
-
ruleTester.run("ts-no-throw-not-implemented-error", rule, {
|
|
216
|
-
valid: [
|
|
217
|
-
{
|
|
218
|
-
// re-exported from another module is not detected
|
|
219
|
-
code: `
|
|
220
|
-
import { NotImplementedError } from "./my-errors";
|
|
221
|
-
throw new NotImplementedError();
|
|
222
|
-
`,
|
|
223
|
-
},
|
|
224
|
-
],
|
|
225
|
-
invalid: [],
|
|
226
|
-
});
|
|
227
|
-
});
|
|
228
|
-
|
|
229
|
-
describe("limitation: dynamic import is not detected", () => {
|
|
230
|
-
ruleTester.run("ts-no-throw-not-implemented-error", rule, {
|
|
231
|
-
valid: [
|
|
232
|
-
{
|
|
233
|
-
// dynamic import usage is not detected
|
|
234
|
-
code: `
|
|
235
|
-
async function test() {
|
|
236
|
-
const { NotImplementedError } = await import("@simplysm/core-common");
|
|
237
|
-
throw new NotImplementedError();
|
|
238
|
-
}
|
|
239
|
-
`,
|
|
240
|
-
},
|
|
241
|
-
],
|
|
242
|
-
invalid: [],
|
|
243
|
-
});
|
|
244
|
-
});
|
|
245
|
-
});
|