Skip to content

Commit a6da0ec

Browse files
authored
fix: converters now uses naming-convention (#617)
* fix: converters now uses naming-convention * Fix interface-name converter
1 parent 7018689 commit a6da0ec

File tree

6 files changed

+233
-64
lines changed

6 files changed

+233
-64
lines changed

src/rules/converters/class-name.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export const convertClassName: RuleConverter = () => {
44
return {
55
rules: [
66
{
7-
ruleName: "@typescript-eslint/class-name-casing",
7+
ruleName: "@typescript-eslint/naming-convention",
88
},
99
],
1010
};

src/rules/converters/interface-name.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
11
import { RuleConverter } from "../converter";
22

3-
export const convertInterfaceName: RuleConverter = () => {
3+
export const convertInterfaceName: RuleConverter = (tslintRule) => {
44
return {
55
rules: [
66
{
7-
ruleName: "@typescript-eslint/interface-name-prefix",
7+
ruleName: "@typescript-eslint/naming-convention",
8+
...(tslintRule.ruleArguments.length !== 0 && {
9+
rules: [
10+
{
11+
selector: "interface",
12+
format: ["PascalCase"],
13+
custom: {
14+
regex: "^I[A-Z]",
15+
match:
16+
tslintRule.ruleArguments[0] === "always-prefix" ? true : false,
17+
},
18+
},
19+
],
20+
}),
821
},
922
],
1023
};

src/rules/converters/tests/class-name.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ describe(convertClassName, () => {
99
expect(result).toEqual({
1010
rules: [
1111
{
12-
ruleName: "@typescript-eslint/class-name-casing",
12+
ruleName: "@typescript-eslint/naming-convention",
1313
},
1414
],
1515
});

src/rules/converters/tests/interface-name.test.ts

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,55 @@ describe(convertInterfaceName, () => {
99
expect(result).toEqual({
1010
rules: [
1111
{
12-
ruleName: "@typescript-eslint/interface-name-prefix",
12+
ruleName: "@typescript-eslint/naming-convention",
13+
},
14+
],
15+
});
16+
});
17+
18+
test("conversion with 'always-prefix' argument", () => {
19+
const result = convertInterfaceName({
20+
ruleArguments: ["always-prefix"],
21+
});
22+
23+
expect(result).toEqual({
24+
rules: [
25+
{
26+
ruleName: "@typescript-eslint/naming-convention",
27+
rules: [
28+
{
29+
selector: "interface",
30+
format: ["PascalCase"],
31+
custom: {
32+
regex: "^I[A-Z]",
33+
match: true,
34+
},
35+
},
36+
],
37+
},
38+
],
39+
});
40+
});
41+
42+
test("conversion with 'never-prefix' argument", () => {
43+
const result = convertInterfaceName({
44+
ruleArguments: ["never-prefix"],
45+
});
46+
47+
expect(result).toEqual({
48+
rules: [
49+
{
50+
ruleName: "@typescript-eslint/naming-convention",
51+
rules: [
52+
{
53+
selector: "interface",
54+
format: ["PascalCase"],
55+
custom: {
56+
regex: "^I[A-Z]",
57+
match: false,
58+
},
59+
},
60+
],
1361
},
1462
],
1563
});

src/rules/converters/tests/variable-name.test.ts

Lines changed: 137 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
import {
22
convertVariableName,
3-
IgnoreLeadingTrailingUnderscoreMsg,
3+
ConstRequiredForAllCapsMsg,
44
ForbiddenLeadingTrailingIdentifierMsg,
55
IgnoreLeadingTrailingIdentifierMsg,
6-
ForbiddenPascalSnakeMsg,
7-
ConstRequiredForAllCapsMsg,
8-
IgnoreOnlyLeadingUnderscoreMsg,
9-
IgnoreOnlyTrailingUnderscoreMsg,
106
} from "../variable-name";
117

128
describe(convertVariableName, () => {
@@ -18,8 +14,15 @@ describe(convertVariableName, () => {
1814
expect(result).toEqual({
1915
rules: [
2016
{
21-
notices: [IgnoreLeadingTrailingUnderscoreMsg],
22-
ruleName: "camelcase",
17+
ruleName: "@typescript-eslint/naming-convention",
18+
rules: [
19+
{
20+
selector: "variable",
21+
format: ["camelCase", "UPPER_CASE"],
22+
leadingUnderscore: "forbid",
23+
trailingUnderscore: "forbid",
24+
},
25+
],
2326
},
2427
{
2528
notices: [ForbiddenLeadingTrailingIdentifierMsg],
@@ -35,16 +38,23 @@ describe(convertVariableName, () => {
3538
});
3639
});
3740

38-
test("conversion with require-const-for-all-caps argument", () => {
41+
test("conversion with require-const-for-all-caps argument without check-format argument", () => {
3942
const result = convertVariableName({
4043
ruleArguments: ["require-const-for-all-caps"],
4144
});
4245

4346
expect(result).toEqual({
4447
rules: [
4548
{
46-
notices: [IgnoreLeadingTrailingUnderscoreMsg, ConstRequiredForAllCapsMsg],
47-
ruleName: "camelcase",
49+
ruleName: "@typescript-eslint/naming-convention",
50+
rules: [
51+
{
52+
selector: "variable",
53+
format: ["camelCase", "UPPER_CASE"],
54+
leadingUnderscore: "forbid",
55+
trailingUnderscore: "forbid",
56+
},
57+
],
4858
},
4959
{
5060
notices: [ForbiddenLeadingTrailingIdentifierMsg],
@@ -60,16 +70,23 @@ describe(convertVariableName, () => {
6070
});
6171
});
6272

63-
test("conversion with allow-pascal-case argument", () => {
73+
test("conversion with allow-pascal-case argument without check-format argument", () => {
6474
const result = convertVariableName({
6575
ruleArguments: ["allow-pascal-case"],
6676
});
6777

6878
expect(result).toEqual({
6979
rules: [
7080
{
71-
notices: [IgnoreLeadingTrailingUnderscoreMsg, ForbiddenPascalSnakeMsg],
72-
ruleName: "camelcase",
81+
ruleName: "@typescript-eslint/naming-convention",
82+
rules: [
83+
{
84+
selector: "variable",
85+
format: ["camelCase", "UPPER_CASE"],
86+
leadingUnderscore: "forbid",
87+
trailingUnderscore: "forbid",
88+
},
89+
],
7390
},
7491
{
7592
notices: [ForbiddenLeadingTrailingIdentifierMsg],
@@ -85,16 +102,23 @@ describe(convertVariableName, () => {
85102
});
86103
});
87104

88-
test("conversion with allow-snake-case argument", () => {
105+
test("conversion with allow-snake-case argument without check-format argument", () => {
89106
const result = convertVariableName({
90107
ruleArguments: ["allow-snake-case"],
91108
});
92109

93110
expect(result).toEqual({
94111
rules: [
95112
{
96-
ruleName: "camelcase",
97-
notices: [IgnoreLeadingTrailingUnderscoreMsg, ForbiddenPascalSnakeMsg],
113+
ruleName: "@typescript-eslint/naming-convention",
114+
rules: [
115+
{
116+
selector: "variable",
117+
format: ["camelCase", "UPPER_CASE"],
118+
leadingUnderscore: "forbid",
119+
trailingUnderscore: "forbid",
120+
},
121+
],
98122
},
99123
{
100124
notices: [ForbiddenLeadingTrailingIdentifierMsg],
@@ -118,8 +142,15 @@ describe(convertVariableName, () => {
118142
expect(result).toEqual({
119143
rules: [
120144
{
121-
ruleName: "camelcase",
122-
notices: [IgnoreLeadingTrailingUnderscoreMsg],
145+
ruleName: "@typescript-eslint/naming-convention",
146+
rules: [
147+
{
148+
selector: "variable",
149+
format: ["camelCase", "UPPER_CASE"],
150+
leadingUnderscore: "forbid",
151+
trailingUnderscore: "forbid",
152+
},
153+
],
123154
},
124155
{
125156
ruleName: "no-underscore-dangle",
@@ -143,8 +174,15 @@ describe(convertVariableName, () => {
143174
expect(result).toEqual({
144175
rules: [
145176
{
146-
notices: [IgnoreLeadingTrailingUnderscoreMsg],
147-
ruleName: "camelcase",
177+
ruleName: "@typescript-eslint/naming-convention",
178+
rules: [
179+
{
180+
selector: "variable",
181+
format: ["camelCase", "UPPER_CASE"],
182+
leadingUnderscore: "forbid",
183+
trailingUnderscore: "forbid",
184+
},
185+
],
148186
},
149187
{
150188
notices: [ForbiddenLeadingTrailingIdentifierMsg],
@@ -168,8 +206,48 @@ describe(convertVariableName, () => {
168206
expect(result).toEqual({
169207
rules: [
170208
{
171-
notices: [IgnoreLeadingTrailingUnderscoreMsg],
172-
ruleName: "camelcase",
209+
ruleName: "@typescript-eslint/naming-convention",
210+
rules: [
211+
{
212+
selector: "variable",
213+
format: ["camelCase", "UPPER_CASE"],
214+
leadingUnderscore: "forbid",
215+
trailingUnderscore: "forbid",
216+
},
217+
],
218+
},
219+
{
220+
notices: [ForbiddenLeadingTrailingIdentifierMsg],
221+
ruleName: "no-underscore-dangle",
222+
},
223+
{
224+
ruleName: "id-blacklist",
225+
},
226+
{
227+
ruleName: "id-match",
228+
},
229+
],
230+
});
231+
});
232+
233+
test("conversion with require-const-for-all-caps argument and check-format argument", () => {
234+
const result = convertVariableName({
235+
ruleArguments: ["check-format", "require-const-for-all-caps"],
236+
});
237+
238+
expect(result).toEqual({
239+
rules: [
240+
{
241+
notices: [ConstRequiredForAllCapsMsg],
242+
ruleName: "@typescript-eslint/naming-convention",
243+
rules: [
244+
{
245+
selector: "variable",
246+
format: ["camelCase", "UPPER_CASE"],
247+
leadingUnderscore: "forbid",
248+
trailingUnderscore: "forbid",
249+
},
250+
],
173251
},
174252
{
175253
notices: [ForbiddenLeadingTrailingIdentifierMsg],
@@ -193,8 +271,15 @@ describe(convertVariableName, () => {
193271
expect(result).toEqual({
194272
rules: [
195273
{
196-
notices: [IgnoreOnlyLeadingUnderscoreMsg],
197-
ruleName: "camelcase",
274+
ruleName: "@typescript-eslint/naming-convention",
275+
rules: [
276+
{
277+
selector: "variable",
278+
format: ["camelCase", "UPPER_CASE"],
279+
leadingUnderscore: "allow",
280+
trailingUnderscore: "forbid",
281+
},
282+
],
198283
},
199284
{
200285
notices: [IgnoreLeadingTrailingIdentifierMsg],
@@ -219,8 +304,15 @@ describe(convertVariableName, () => {
219304
expect(result).toEqual({
220305
rules: [
221306
{
222-
notices: [IgnoreOnlyTrailingUnderscoreMsg],
223-
ruleName: "camelcase",
307+
ruleName: "@typescript-eslint/naming-convention",
308+
rules: [
309+
{
310+
selector: "variable",
311+
format: ["camelCase", "UPPER_CASE"],
312+
leadingUnderscore: "forbid",
313+
trailingUnderscore: "allow",
314+
},
315+
],
224316
},
225317
{
226318
notices: [IgnoreLeadingTrailingIdentifierMsg],
@@ -249,8 +341,15 @@ describe(convertVariableName, () => {
249341
expect(result).toEqual({
250342
rules: [
251343
{
252-
notices: [],
253-
ruleName: "camelcase",
344+
ruleName: "@typescript-eslint/naming-convention",
345+
rules: [
346+
{
347+
selector: "variable",
348+
format: ["camelCase", "UPPER_CASE"],
349+
leadingUnderscore: "allow",
350+
trailingUnderscore: "allow",
351+
},
352+
],
254353
},
255354
{
256355
notices: [IgnoreLeadingTrailingIdentifierMsg],
@@ -283,8 +382,16 @@ describe(convertVariableName, () => {
283382
expect(result).toEqual({
284383
rules: [
285384
{
286-
ruleName: "camelcase",
287-
notices: [ConstRequiredForAllCapsMsg, ForbiddenPascalSnakeMsg],
385+
ruleName: "@typescript-eslint/naming-convention",
386+
rules: [
387+
{
388+
selector: "variable",
389+
format: ["camelCase", "UPPER_CASE"],
390+
leadingUnderscore: "allow",
391+
trailingUnderscore: "allow",
392+
},
393+
],
394+
notices: [ConstRequiredForAllCapsMsg],
288395
},
289396
{
290397
ruleName: "no-underscore-dangle",

0 commit comments

Comments
 (0)