@simplysm/eslint-plugin 12.9.17 → 12.9.18
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/package.json +4 -2
- package/src/configs/root.js +109 -12
- package/src/index.js +1 -5
- package/src/plugin.js +5 -1
- package/src/rules/ng-template-no-todo-comments.js +11 -17
- package/src/rules/ts-no-buffer-in-typedarray-context.js +165 -0
- package/src/rules/ts-no-exported-types.js +199 -0
- package/src/rules/ts-no-throw-not-implement-error.js +31 -19
- package/tests/ng-template-no-todo-comments.spec.js +54 -55
- package/tests/ts-no-buffer-in-typedarray-context.spec.js +213 -0
- package/tests/ts-no-exported-types.spec.js +307 -0
- package/vitest.config.js +9 -0
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
import { afterAll, describe, it } from 'vitest';
|
|
2
|
+
import { RuleTester } from '@typescript-eslint/rule-tester';
|
|
3
|
+
import rule from '../src/rules/ts-no-exported-types.js';
|
|
4
|
+
|
|
5
|
+
RuleTester.afterAll = afterAll;
|
|
6
|
+
RuleTester.it = it;
|
|
7
|
+
RuleTester.itOnly = it.only;
|
|
8
|
+
RuleTester.describe = describe;
|
|
9
|
+
|
|
10
|
+
const ruleTester = new RuleTester({
|
|
11
|
+
languageOptions: {
|
|
12
|
+
parserOptions: {
|
|
13
|
+
projectService: {
|
|
14
|
+
allowDefaultProject: ['*.ts*'],
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
describe('ts-no-exported-types 규칙', () => {
|
|
21
|
+
describe('허용되는 코드들 (valid)', () => {
|
|
22
|
+
describe('제한된 타입을 내부 함수에서만 사용하는 경우', () => {
|
|
23
|
+
ruleTester.run('ts-no-exported-types', rule, {
|
|
24
|
+
valid: [
|
|
25
|
+
{
|
|
26
|
+
code: `
|
|
27
|
+
type Internal = string;
|
|
28
|
+
function internalFunc(x: Internal) {}
|
|
29
|
+
`,
|
|
30
|
+
options: [{ types: [{ ban: 'Foo' }] }],
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
invalid: [],
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
describe('export 함수가 안전한 타입만 사용하는 경우', () => {
|
|
38
|
+
ruleTester.run('ts-no-exported-types', rule, {
|
|
39
|
+
valid: [
|
|
40
|
+
{
|
|
41
|
+
code: `
|
|
42
|
+
export function safeFunc(x: string): number {
|
|
43
|
+
return 1;
|
|
44
|
+
}
|
|
45
|
+
`,
|
|
46
|
+
options: [{ types: [{ ban: 'Foo' }] }],
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
invalid: [],
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
describe('제한된 타입을 private 속성으로만 사용하는 경우', () => {
|
|
54
|
+
ruleTester.run('ts-no-exported-types', rule, {
|
|
55
|
+
valid: [
|
|
56
|
+
{
|
|
57
|
+
code: `
|
|
58
|
+
class MyClass {
|
|
59
|
+
private prop: Foo;
|
|
60
|
+
}
|
|
61
|
+
`,
|
|
62
|
+
options: [{ types: [{ ban: 'Foo' }] }],
|
|
63
|
+
},
|
|
64
|
+
],
|
|
65
|
+
invalid: [],
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
describe('오류가 발생해야 하는 코드들 (invalid)', () => {
|
|
71
|
+
describe('제한된 타입을 export 함수의 파라미터로 사용하는 경우', () => {
|
|
72
|
+
ruleTester.run('ts-no-exported-types', rule, {
|
|
73
|
+
valid: [],
|
|
74
|
+
invalid: [
|
|
75
|
+
{
|
|
76
|
+
code: `
|
|
77
|
+
export function exposedFunc(x: Foo): number {
|
|
78
|
+
return 1;
|
|
79
|
+
}
|
|
80
|
+
`,
|
|
81
|
+
options: [{ types: [{ ban: 'Foo' }] }],
|
|
82
|
+
errors: [
|
|
83
|
+
{
|
|
84
|
+
messageId: 'noExportedTypes',
|
|
85
|
+
data: { typeName: 'Foo', safeSuggestion: '' },
|
|
86
|
+
},
|
|
87
|
+
],
|
|
88
|
+
},
|
|
89
|
+
],
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
describe('제한된 타입을 반환값으로 사용하는 export 함수', () => {
|
|
94
|
+
ruleTester.run('ts-no-exported-types', rule, {
|
|
95
|
+
valid: [],
|
|
96
|
+
invalid: [
|
|
97
|
+
{
|
|
98
|
+
code: `
|
|
99
|
+
export function anotherExposed(): Foo {
|
|
100
|
+
return {} as Foo;
|
|
101
|
+
}
|
|
102
|
+
`,
|
|
103
|
+
options: [{ types: [{ ban: 'Foo' }] }],
|
|
104
|
+
errors: [
|
|
105
|
+
{
|
|
106
|
+
messageId: 'noExportedTypes',
|
|
107
|
+
data: { typeName: 'Foo', safeSuggestion: '' },
|
|
108
|
+
},
|
|
109
|
+
],
|
|
110
|
+
},
|
|
111
|
+
],
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
describe('제한된 타입을 public 속성으로 사용하는 export 클래스', () => {
|
|
116
|
+
ruleTester.run('ts-no-exported-types', rule, {
|
|
117
|
+
valid: [],
|
|
118
|
+
invalid: [
|
|
119
|
+
{
|
|
120
|
+
code: `
|
|
121
|
+
export class MyClass {
|
|
122
|
+
public prop: Foo;
|
|
123
|
+
}
|
|
124
|
+
`,
|
|
125
|
+
options: [{ types: [{ ban: 'Foo' }] }],
|
|
126
|
+
errors: [
|
|
127
|
+
{
|
|
128
|
+
messageId: 'noExportedTypes',
|
|
129
|
+
data: { typeName: 'Foo', safeSuggestion: '' },
|
|
130
|
+
},
|
|
131
|
+
],
|
|
132
|
+
},
|
|
133
|
+
],
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
describe('제한된 타입을 public 메서드의 파라미터로 사용하는 경우', () => {
|
|
138
|
+
ruleTester.run('ts-no-exported-types', rule, {
|
|
139
|
+
valid: [],
|
|
140
|
+
invalid: [
|
|
141
|
+
{
|
|
142
|
+
code: `
|
|
143
|
+
export class MyClass {
|
|
144
|
+
method(x: Foo): void {}
|
|
145
|
+
}
|
|
146
|
+
`,
|
|
147
|
+
options: [{ types: [{ ban: 'Foo' }] }],
|
|
148
|
+
errors: [
|
|
149
|
+
{
|
|
150
|
+
messageId: 'noExportedTypes',
|
|
151
|
+
data: { typeName: 'Foo', safeSuggestion: '' },
|
|
152
|
+
},
|
|
153
|
+
],
|
|
154
|
+
},
|
|
155
|
+
],
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
describe('제한된 타입을 사용하는 export const 선언', () => {
|
|
160
|
+
ruleTester.run('ts-no-exported-types', rule, {
|
|
161
|
+
valid: [],
|
|
162
|
+
invalid: [
|
|
163
|
+
{
|
|
164
|
+
code: `
|
|
165
|
+
export const myValue: Foo = {} as Foo;
|
|
166
|
+
`,
|
|
167
|
+
options: [{ types: [{ ban: 'Foo' }] }],
|
|
168
|
+
errors: [
|
|
169
|
+
{
|
|
170
|
+
messageId: 'noExportedTypes',
|
|
171
|
+
data: { typeName: 'Foo', safeSuggestion: '' },
|
|
172
|
+
},
|
|
173
|
+
],
|
|
174
|
+
},
|
|
175
|
+
],
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
describe('제한된 타입을 생성자의 파라미터로 사용하는 경우', () => {
|
|
180
|
+
ruleTester.run('ts-no-exported-types', rule, {
|
|
181
|
+
valid: [],
|
|
182
|
+
invalid: [
|
|
183
|
+
{
|
|
184
|
+
code: `
|
|
185
|
+
export class ZipCache {
|
|
186
|
+
constructor(arg?: Blob | Uint8Array) {}
|
|
187
|
+
}
|
|
188
|
+
`,
|
|
189
|
+
options: [{ types: [{ ban: 'Uint8Array' }] }],
|
|
190
|
+
errors: [{ messageId: 'noExportedTypes' }],
|
|
191
|
+
},
|
|
192
|
+
],
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
describe('유니언 타입 중 하나가 제한된 타입이면 오류 발생해야 함 (파라미터)', () => {
|
|
197
|
+
ruleTester.run('ts-no-exported-types', rule, {
|
|
198
|
+
valid: [],
|
|
199
|
+
invalid: [
|
|
200
|
+
{
|
|
201
|
+
code: `
|
|
202
|
+
export function readData(x: Uint8Array | string): void {}
|
|
203
|
+
`,
|
|
204
|
+
options: [{ types: [{ ban: 'Uint8Array' }] }],
|
|
205
|
+
errors: [{ messageId: 'noExportedTypes' }],
|
|
206
|
+
},
|
|
207
|
+
],
|
|
208
|
+
});
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
describe('유니언 타입 중 하나가 제한된 타입이면 오류 발생해야 함 (반환값)', () => {
|
|
212
|
+
ruleTester.run('ts-no-exported-types', rule, {
|
|
213
|
+
valid: [],
|
|
214
|
+
invalid: [
|
|
215
|
+
{
|
|
216
|
+
code: `
|
|
217
|
+
export function getBuffer(): Uint8Array | null {
|
|
218
|
+
return new Uint8Array();
|
|
219
|
+
}
|
|
220
|
+
`,
|
|
221
|
+
options: [{ types: [{ ban: 'Uint8Array' }] }],
|
|
222
|
+
errors: [{ messageId: 'noExportedTypes' }],
|
|
223
|
+
},
|
|
224
|
+
],
|
|
225
|
+
});
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
describe('유니언 타입 속성에서도 제한된 타입이면 오류 발생해야 함', () => {
|
|
229
|
+
ruleTester.run('ts-no-exported-types', rule, {
|
|
230
|
+
valid: [],
|
|
231
|
+
invalid: [
|
|
232
|
+
{
|
|
233
|
+
code: `
|
|
234
|
+
export class MyClass {
|
|
235
|
+
public buffer: string | Uint8Array;
|
|
236
|
+
}
|
|
237
|
+
`,
|
|
238
|
+
options: [{ types: [{ ban: 'Uint8Array' }] }],
|
|
239
|
+
errors: [
|
|
240
|
+
{
|
|
241
|
+
messageId: 'noExportedTypes',
|
|
242
|
+
data: { typeName: 'Uint8Array', safeSuggestion: '' },
|
|
243
|
+
},
|
|
244
|
+
],
|
|
245
|
+
},
|
|
246
|
+
],
|
|
247
|
+
});
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
describe('export const 선언에서도 유니언 타입 중 제한된 타입이 있으면 오류', () => {
|
|
251
|
+
ruleTester.run('ts-no-exported-types', rule, {
|
|
252
|
+
valid: [],
|
|
253
|
+
invalid: [
|
|
254
|
+
{
|
|
255
|
+
code: `
|
|
256
|
+
export const data: Uint8Array | number = new Uint8Array();
|
|
257
|
+
`,
|
|
258
|
+
options: [{ types: [{ ban: 'Uint8Array', safe: 'Buffer' }] }],
|
|
259
|
+
errors: [
|
|
260
|
+
{
|
|
261
|
+
messageId: 'noExportedTypes',
|
|
262
|
+
data: {
|
|
263
|
+
typeName: 'Uint8Array',
|
|
264
|
+
safeSuggestion: ' 더 안전한 대체 타입 "Buffer"을(를) 사용하세요.',
|
|
265
|
+
},
|
|
266
|
+
},
|
|
267
|
+
],
|
|
268
|
+
},
|
|
269
|
+
],
|
|
270
|
+
});
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
describe('Generic 안쪽에도 없어야함', () => {
|
|
274
|
+
ruleTester.run('ts-no-exported-types', rule, {
|
|
275
|
+
valid: [],
|
|
276
|
+
invalid: [
|
|
277
|
+
{
|
|
278
|
+
code: `
|
|
279
|
+
export const myValue: Foo<Bar> = {};
|
|
280
|
+
`,
|
|
281
|
+
options: [{ types: [{ ban: 'Bar' }] }],
|
|
282
|
+
errors: [
|
|
283
|
+
{
|
|
284
|
+
messageId: 'noExportedTypes',
|
|
285
|
+
data: { typeName: 'Bar', safeSuggestion: '' },
|
|
286
|
+
},
|
|
287
|
+
],
|
|
288
|
+
},
|
|
289
|
+
],
|
|
290
|
+
});
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
describe('Generic 안쪽에 있어도 ignoreInGeneric 이면 허용됨', () => {
|
|
294
|
+
ruleTester.run('ts-no-exported-types', rule, {
|
|
295
|
+
valid: [
|
|
296
|
+
{
|
|
297
|
+
code: `
|
|
298
|
+
export const myValue: Foo<Bar> = {};
|
|
299
|
+
`,
|
|
300
|
+
options: [{ types: [{ ban: 'Bar', ignoreInGeneric: true }] }],
|
|
301
|
+
},
|
|
302
|
+
],
|
|
303
|
+
invalid: [],
|
|
304
|
+
});
|
|
305
|
+
});
|
|
306
|
+
});
|
|
307
|
+
});
|