Skip to content

Commit 089de81

Browse files
mauricetmeyerJosh Goldberg
authored and
Josh Goldberg
committed
Added missing quotemark converter (#192)
* Added missing quotemark converter * Fixed a typo and renamed a test * Refactored some variable names to better reflect the usage, replaced any with a more specific type * Making eslint stage happy by defining a custom type
1 parent 23a2bfb commit 089de81

File tree

3 files changed

+123
-1
lines changed

3 files changed

+123
-1
lines changed

src/rules/converters.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ import { convertUnifiedSignatures } from "./converters/unified-signatures";
101101
import { convertUnnecessaryBind } from "./converters/unnecessary-bind";
102102
import { convertUnnecessaryConstructor } from "./converters/unnecessary-constructor";
103103
import { convertUseIsnan } from "./converters/use-isnan";
104+
import { convertQuotemark } from "./converters/quotemark";
104105
import { convertTripleEquals } from "./converters/triple-equals";
105106

106107
/**
@@ -210,7 +211,9 @@ export const converters = new Map([
210211
["no-octal-literal", convertNoOctalLiteral],
211212
["no-regex-spaces", convertNoRegexSpaces],
212213
["no-unnecessary-semicolons", convertNoUnnecessarySemicolons],
214+
["quotemark", convertQuotemark],
213215
["triple-equals", convertTripleEquals],
216+
214217
// These converters are all for rules that need more complex option conversions.
215218
// Some of them will likely need to have notices about changed lint behaviors...
216219
// If you're willing to take on that work, that'd be great! Please send PRs! 💖
@@ -225,7 +228,6 @@ export const converters = new Map([
225228
// ["no-trailing-whitespace", convertNoTrailingWhitespace], // no-trailing-spaces
226229
// ["no-unused-expression", convertNoUnusedExpression], // no-unused-expressions
227230
// ["no-void-expression", convertNoVoidExpression], // (no exact equivalent)
228-
// ["quotemark", convertQuotemark], // quotes
229231
// ["space-within-parens", convertSpaceWithinParens], // space-in-parens
230232
// ["variable-name", convertVariableName], // a bunch of rules...
231233

src/rules/converters/quotemark.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { RuleConverter } from "../converter";
2+
3+
type QuotemarkRule = string | { avoidEscape: true };
4+
export const convertQuotemark: RuleConverter = tslintRule => {
5+
const notices: string[] = [];
6+
const ruleArguments: QuotemarkRule[] = [];
7+
8+
["jsx-single", "jsx-double", "avoid-template"].forEach(option => {
9+
if (tslintRule.ruleArguments.includes(option)) {
10+
notices.push(`Option "${option}" is not supported by ESLint.`);
11+
}
12+
});
13+
14+
["single", "double", "backtick"].forEach(option => {
15+
if (tslintRule.ruleArguments.includes(option)) {
16+
ruleArguments.push(option);
17+
}
18+
});
19+
20+
if (tslintRule.ruleArguments.includes("avoid-escape")) {
21+
ruleArguments.push({ avoidEscape: true });
22+
}
23+
24+
return {
25+
rules: [
26+
{
27+
notices,
28+
ruleArguments,
29+
ruleName: "@typescript-eslint/quotes",
30+
},
31+
],
32+
};
33+
};
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import { convertQuotemark } from "../quotemark";
2+
3+
describe(convertQuotemark, () => {
4+
test("conversion without arguments", () => {
5+
const result = convertQuotemark({
6+
ruleArguments: [],
7+
});
8+
9+
expect(result).toEqual({
10+
rules: [
11+
{
12+
ruleName: "@typescript-eslint/quotes",
13+
ruleArguments: [],
14+
notices: [],
15+
},
16+
],
17+
});
18+
});
19+
20+
test("conversion with an argument", () => {
21+
const result = convertQuotemark({
22+
ruleArguments: ["double"],
23+
});
24+
25+
expect(result).toEqual({
26+
rules: [
27+
{
28+
ruleName: "@typescript-eslint/quotes",
29+
ruleArguments: ["double"],
30+
notices: [],
31+
},
32+
],
33+
});
34+
});
35+
36+
test("conversion with an avoid-escape argument", () => {
37+
const result = convertQuotemark({
38+
ruleArguments: ["avoid-escape"],
39+
});
40+
41+
expect(result).toEqual({
42+
rules: [
43+
{
44+
ruleName: "@typescript-eslint/quotes",
45+
ruleArguments: [{ avoidEscape: true }],
46+
notices: [],
47+
},
48+
],
49+
});
50+
});
51+
52+
test("conversion with arguments", () => {
53+
const result = convertQuotemark({
54+
ruleArguments: ["single", "avoid-template"],
55+
});
56+
57+
expect(result).toEqual({
58+
rules: [
59+
{
60+
ruleName: "@typescript-eslint/quotes",
61+
ruleArguments: ["single"],
62+
notices: ['Option "avoid-template" is not supported by ESLint.'],
63+
},
64+
],
65+
});
66+
});
67+
68+
test("conversion with unsupported arguments", () => {
69+
const result = convertQuotemark({
70+
ruleArguments: ["jsx-single", "jsx-double", "avoid-template"],
71+
});
72+
73+
expect(result).toEqual({
74+
rules: [
75+
{
76+
ruleName: "@typescript-eslint/quotes",
77+
ruleArguments: [],
78+
notices: [
79+
'Option "jsx-single" is not supported by ESLint.',
80+
'Option "jsx-double" is not supported by ESLint.',
81+
'Option "avoid-template" is not supported by ESLint.',
82+
],
83+
},
84+
],
85+
});
86+
});
87+
});

0 commit comments

Comments
 (0)