@simplysm/lint 13.0.69 → 13.0.71
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/README.md +12 -490
- package/dist/eslint-recommended.js +41 -41
- package/dist/rules/no-hard-private.d.ts +6 -6
- package/dist/rules/no-hard-private.js +6 -6
- package/dist/rules/no-subpath-imports-from-simplysm.d.ts +5 -5
- package/dist/rules/no-subpath-imports-from-simplysm.js +6 -6
- package/dist/rules/ts-no-throw-not-implemented-error.d.ts +5 -5
- package/dist/rules/ts-no-throw-not-implemented-error.js +2 -2
- package/dist/stylelint-recommended.js +3 -3
- package/dist/utils/create-rule.d.ts +3 -3
- package/package.json +5 -4
- package/src/eslint-recommended.ts +54 -54
- 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 +13 -13
- package/src/stylelint-recommended.ts +3 -3
- package/src/utils/create-rule.ts +3 -3
- package/tests/no-hard-private.spec.ts +961 -0
- package/tests/no-subpath-imports-from-simplysm.spec.ts +352 -0
- package/tests/recommended.spec.ts +155 -0
- package/tests/ts-no-throw-not-implemented-error.spec.ts +386 -0
- package/tests/vitest.setup.ts +10 -0
|
@@ -0,0 +1,386 @@
|
|
|
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 throw", () => {
|
|
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();
|
|
77
|
+
`,
|
|
78
|
+
errors: [{ messageId: "noThrowNotImplementedError" }],
|
|
79
|
+
},
|
|
80
|
+
],
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
describe("usage with message", () => {
|
|
85
|
+
ruleTester.run("ts-no-throw-not-implemented-error", rule, {
|
|
86
|
+
valid: [],
|
|
87
|
+
invalid: [
|
|
88
|
+
{
|
|
89
|
+
code: `
|
|
90
|
+
import { NotImplementedError } from "@simplysm/core-common";
|
|
91
|
+
throw new NotImplementedError("This feature is not yet implemented");
|
|
92
|
+
`,
|
|
93
|
+
errors: [
|
|
94
|
+
{
|
|
95
|
+
messageId: "noThrowNotImplementedError",
|
|
96
|
+
data: { text: "This feature is not yet implemented" },
|
|
97
|
+
},
|
|
98
|
+
],
|
|
99
|
+
},
|
|
100
|
+
],
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
describe("also detects when imported as alias", () => {
|
|
105
|
+
ruleTester.run("ts-no-throw-not-implemented-error", rule, {
|
|
106
|
+
valid: [],
|
|
107
|
+
invalid: [
|
|
108
|
+
{
|
|
109
|
+
code: `
|
|
110
|
+
import { NotImplementedError as NIE } from "@simplysm/core-common";
|
|
111
|
+
new NIE();
|
|
112
|
+
`,
|
|
113
|
+
errors: [{ messageId: "noThrowNotImplementedError" }],
|
|
114
|
+
},
|
|
115
|
+
],
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
describe("also detects when assigned to variable", () => {
|
|
120
|
+
ruleTester.run("ts-no-throw-not-implemented-error", rule, {
|
|
121
|
+
valid: [],
|
|
122
|
+
invalid: [
|
|
123
|
+
{
|
|
124
|
+
code: `
|
|
125
|
+
import { NotImplementedError } from "@simplysm/core-common";
|
|
126
|
+
const err = new NotImplementedError();
|
|
127
|
+
`,
|
|
128
|
+
errors: [{ messageId: "noThrowNotImplementedError" }],
|
|
129
|
+
},
|
|
130
|
+
],
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
describe("also detects when passed as function argument", () => {
|
|
135
|
+
ruleTester.run("ts-no-throw-not-implemented-error", rule, {
|
|
136
|
+
valid: [],
|
|
137
|
+
invalid: [
|
|
138
|
+
{
|
|
139
|
+
code: `
|
|
140
|
+
import { NotImplementedError } from "@simplysm/core-common";
|
|
141
|
+
function handleError(err: Error) {}
|
|
142
|
+
handleError(new NotImplementedError());
|
|
143
|
+
`,
|
|
144
|
+
errors: [{ messageId: "noThrowNotImplementedError" }],
|
|
145
|
+
},
|
|
146
|
+
],
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
describe("usage with other imports", () => {
|
|
151
|
+
ruleTester.run("ts-no-throw-not-implemented-error", rule, {
|
|
152
|
+
valid: [],
|
|
153
|
+
invalid: [
|
|
154
|
+
{
|
|
155
|
+
code: `
|
|
156
|
+
import { SdError, NotImplementedError } from "@simplysm/core-common";
|
|
157
|
+
throw new NotImplementedError();
|
|
158
|
+
`,
|
|
159
|
+
errors: [{ messageId: "noThrowNotImplementedError" }],
|
|
160
|
+
},
|
|
161
|
+
],
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
describe("multiple usages produce errors for each", () => {
|
|
166
|
+
ruleTester.run("ts-no-throw-not-implemented-error", rule, {
|
|
167
|
+
valid: [],
|
|
168
|
+
invalid: [
|
|
169
|
+
{
|
|
170
|
+
code: `
|
|
171
|
+
import { NotImplementedError } from "@simplysm/core-common";
|
|
172
|
+
new NotImplementedError("first");
|
|
173
|
+
new NotImplementedError("second");
|
|
174
|
+
`,
|
|
175
|
+
errors: [
|
|
176
|
+
{ messageId: "noThrowNotImplementedError", data: { text: "first" } },
|
|
177
|
+
{ messageId: "noThrowNotImplementedError", data: { text: "second" } },
|
|
178
|
+
],
|
|
179
|
+
},
|
|
180
|
+
],
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
describe("usage with namespace import", () => {
|
|
185
|
+
ruleTester.run("ts-no-throw-not-implemented-error", rule, {
|
|
186
|
+
valid: [],
|
|
187
|
+
invalid: [
|
|
188
|
+
{
|
|
189
|
+
code: `
|
|
190
|
+
import * as CoreCommon from "@simplysm/core-common";
|
|
191
|
+
throw new CoreCommon.NotImplementedError();
|
|
192
|
+
`,
|
|
193
|
+
errors: [{ messageId: "noThrowNotImplementedError" }],
|
|
194
|
+
},
|
|
195
|
+
],
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
describe("namespace import with message", () => {
|
|
200
|
+
ruleTester.run("ts-no-throw-not-implemented-error", rule, {
|
|
201
|
+
valid: [],
|
|
202
|
+
invalid: [
|
|
203
|
+
{
|
|
204
|
+
code: `
|
|
205
|
+
import * as CC from "@simplysm/core-common";
|
|
206
|
+
new CC.NotImplementedError("not yet implemented");
|
|
207
|
+
`,
|
|
208
|
+
errors: [
|
|
209
|
+
{
|
|
210
|
+
messageId: "noThrowNotImplementedError",
|
|
211
|
+
data: { text: "not yet implemented" },
|
|
212
|
+
},
|
|
213
|
+
],
|
|
214
|
+
},
|
|
215
|
+
],
|
|
216
|
+
});
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
describe("template literal argument falls back to default message", () => {
|
|
220
|
+
ruleTester.run("ts-no-throw-not-implemented-error", rule, {
|
|
221
|
+
valid: [],
|
|
222
|
+
invalid: [
|
|
223
|
+
{
|
|
224
|
+
code: `
|
|
225
|
+
import { NotImplementedError } from "@simplysm/core-common";
|
|
226
|
+
throw new NotImplementedError(\`dynamic message\`);
|
|
227
|
+
`,
|
|
228
|
+
errors: [
|
|
229
|
+
{
|
|
230
|
+
messageId: "noThrowNotImplementedError",
|
|
231
|
+
data: { text: "Not implemented" },
|
|
232
|
+
},
|
|
233
|
+
],
|
|
234
|
+
},
|
|
235
|
+
],
|
|
236
|
+
});
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
describe("variable argument falls back to default message", () => {
|
|
240
|
+
ruleTester.run("ts-no-throw-not-implemented-error", rule, {
|
|
241
|
+
valid: [],
|
|
242
|
+
invalid: [
|
|
243
|
+
{
|
|
244
|
+
code: `
|
|
245
|
+
import { NotImplementedError } from "@simplysm/core-common";
|
|
246
|
+
const msg = "dynamic message";
|
|
247
|
+
throw new NotImplementedError(msg);
|
|
248
|
+
`,
|
|
249
|
+
errors: [
|
|
250
|
+
{
|
|
251
|
+
messageId: "noThrowNotImplementedError",
|
|
252
|
+
data: { text: "Not implemented" },
|
|
253
|
+
},
|
|
254
|
+
],
|
|
255
|
+
},
|
|
256
|
+
],
|
|
257
|
+
});
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
describe("numeric argument falls back to default message", () => {
|
|
261
|
+
ruleTester.run("ts-no-throw-not-implemented-error", rule, {
|
|
262
|
+
valid: [],
|
|
263
|
+
invalid: [
|
|
264
|
+
{
|
|
265
|
+
code: `
|
|
266
|
+
import { NotImplementedError } from "@simplysm/core-common";
|
|
267
|
+
throw new NotImplementedError(123);
|
|
268
|
+
`,
|
|
269
|
+
errors: [
|
|
270
|
+
{
|
|
271
|
+
messageId: "noThrowNotImplementedError",
|
|
272
|
+
data: { text: "Not implemented" },
|
|
273
|
+
},
|
|
274
|
+
],
|
|
275
|
+
},
|
|
276
|
+
],
|
|
277
|
+
});
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
describe("empty string argument falls back to default message", () => {
|
|
281
|
+
ruleTester.run("ts-no-throw-not-implemented-error", rule, {
|
|
282
|
+
valid: [],
|
|
283
|
+
invalid: [
|
|
284
|
+
{
|
|
285
|
+
code: `
|
|
286
|
+
import { NotImplementedError } from "@simplysm/core-common";
|
|
287
|
+
throw new NotImplementedError("");
|
|
288
|
+
`,
|
|
289
|
+
errors: [
|
|
290
|
+
{
|
|
291
|
+
messageId: "noThrowNotImplementedError",
|
|
292
|
+
data: { text: "Not implemented" },
|
|
293
|
+
},
|
|
294
|
+
],
|
|
295
|
+
},
|
|
296
|
+
],
|
|
297
|
+
});
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
describe("null argument falls back to default message", () => {
|
|
301
|
+
ruleTester.run("ts-no-throw-not-implemented-error", rule, {
|
|
302
|
+
valid: [],
|
|
303
|
+
invalid: [
|
|
304
|
+
{
|
|
305
|
+
code: `
|
|
306
|
+
import { NotImplementedError } from "@simplysm/core-common";
|
|
307
|
+
throw new NotImplementedError(null);
|
|
308
|
+
`,
|
|
309
|
+
errors: [
|
|
310
|
+
{
|
|
311
|
+
messageId: "noThrowNotImplementedError",
|
|
312
|
+
data: { text: "Not implemented" },
|
|
313
|
+
},
|
|
314
|
+
],
|
|
315
|
+
},
|
|
316
|
+
],
|
|
317
|
+
});
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
describe("undefined argument falls back to default message", () => {
|
|
321
|
+
ruleTester.run("ts-no-throw-not-implemented-error", rule, {
|
|
322
|
+
valid: [],
|
|
323
|
+
invalid: [
|
|
324
|
+
{
|
|
325
|
+
code: `
|
|
326
|
+
import { NotImplementedError } from "@simplysm/core-common";
|
|
327
|
+
throw new NotImplementedError(undefined);
|
|
328
|
+
`,
|
|
329
|
+
errors: [
|
|
330
|
+
{
|
|
331
|
+
messageId: "noThrowNotImplementedError",
|
|
332
|
+
data: { text: "Not implemented" },
|
|
333
|
+
},
|
|
334
|
+
],
|
|
335
|
+
},
|
|
336
|
+
],
|
|
337
|
+
});
|
|
338
|
+
});
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
describe("namespace import from other packages is allowed", () => {
|
|
342
|
+
ruleTester.run("ts-no-throw-not-implemented-error", rule, {
|
|
343
|
+
valid: [
|
|
344
|
+
{
|
|
345
|
+
code: `
|
|
346
|
+
import * as OtherPkg from "other-package";
|
|
347
|
+
new OtherPkg.NotImplementedError();
|
|
348
|
+
`,
|
|
349
|
+
},
|
|
350
|
+
],
|
|
351
|
+
invalid: [],
|
|
352
|
+
});
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
describe("limitation: re-exported NotImplementedError is not detected", () => {
|
|
356
|
+
ruleTester.run("ts-no-throw-not-implemented-error", rule, {
|
|
357
|
+
valid: [
|
|
358
|
+
{
|
|
359
|
+
// re-exported from another module is not detected
|
|
360
|
+
code: `
|
|
361
|
+
import { NotImplementedError } from "./my-errors";
|
|
362
|
+
throw new NotImplementedError();
|
|
363
|
+
`,
|
|
364
|
+
},
|
|
365
|
+
],
|
|
366
|
+
invalid: [],
|
|
367
|
+
});
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
describe("limitation: dynamic import is not detected", () => {
|
|
371
|
+
ruleTester.run("ts-no-throw-not-implemented-error", rule, {
|
|
372
|
+
valid: [
|
|
373
|
+
{
|
|
374
|
+
// dynamic import usage is not detected
|
|
375
|
+
code: `
|
|
376
|
+
async function test() {
|
|
377
|
+
const { NotImplementedError } = await import("@simplysm/core-common");
|
|
378
|
+
throw new NotImplementedError();
|
|
379
|
+
}
|
|
380
|
+
`,
|
|
381
|
+
},
|
|
382
|
+
],
|
|
383
|
+
invalid: [],
|
|
384
|
+
});
|
|
385
|
+
});
|
|
386
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { afterAll, describe, it } from "vitest";
|
|
2
|
+
import { RuleTester } from "@typescript-eslint/rule-tester";
|
|
3
|
+
|
|
4
|
+
// @typescript-eslint/rule-tester does not directly support Vitest,
|
|
5
|
+
// so we need to manually bind Vitest's test functions.
|
|
6
|
+
RuleTester.afterAll = afterAll;
|
|
7
|
+
RuleTester.describe = describe;
|
|
8
|
+
RuleTester.it = it;
|
|
9
|
+
RuleTester.itOnly = it.only;
|
|
10
|
+
RuleTester.itSkip = it.skip;
|