Skip to content

Commit 2f6c160

Browse files
cthompson527Josh Goldberg
authored and
Josh Goldberg
committed
added no-trailing-whitespace converter and unit tests (#196)
1 parent e6b3818 commit 2f6c160

File tree

3 files changed

+135
-0
lines changed

3 files changed

+135
-0
lines changed

src/rules/converters.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ import { convertNoStringLiteral } from "./converters/no-string-literal";
7171
import { convertNoStringThrow } from "./converters/no-string-throw";
7272
import { convertNoSwitchCaseFallThrough } from "./converters/no-switch-case-fall-through";
7373
import { convertNoThisAssignment } from "./converters/no-this-assignment";
74+
import { convertNoTrailingWhitespace } from "./converters/no-trailing-whitespace";
7475
import { convertNoUnboundMethod } from "./converters/no-unbound-method";
7576
import { convertNoUnnecessaryClass } from "./converters/no-unnecessary-class";
7677
import { convertNoUnnecessaryInitializer } from "./converters/no-unnecessary-initializer";
@@ -161,6 +162,7 @@ export const converters = new Map([
161162
["no-string-literal", convertNoStringLiteral],
162163
["no-string-throw", convertNoStringThrow],
163164
["no-switch-case-fall-through", convertNoSwitchCaseFallThrough],
165+
["no-trailing-whitespace", convertNoTrailingWhitespace],
164166
["no-this-assignment", convertNoThisAssignment],
165167
["no-unbound-method", convertNoUnboundMethod],
166168
["no-unnecessary-class", convertNoUnnecessaryClass],
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { RuleConverter } from "../converter";
2+
3+
export const convertNoTrailingWhitespace: RuleConverter = tslintRule => {
4+
const ruleArguments: { [eslintOption in "ignoreComments" | "skipBlankLines"]?: true }[] = [];
5+
const notices: string[] = [];
6+
7+
if (tslintRule.ruleArguments.includes("ignore-comments")) {
8+
ruleArguments.push({ ignoreComments: true });
9+
}
10+
11+
if (tslintRule.ruleArguments.includes("ignore-blank-lines")) {
12+
ruleArguments.push({ skipBlankLines: true });
13+
}
14+
15+
if (tslintRule.ruleArguments.includes("ignore-template-strings")) {
16+
notices.push("ESLint does not support ignoring template strings.");
17+
}
18+
19+
if (tslintRule.ruleArguments.includes("ignore-jsdoc")) {
20+
notices.push("ESLint does not support ignoring JSDoc.");
21+
}
22+
23+
return {
24+
rules: [
25+
{
26+
...(notices.length > 0 && { notices }),
27+
...(ruleArguments.length > 0 && { ruleArguments }),
28+
ruleName: "no-trailing-spaces",
29+
},
30+
],
31+
};
32+
};
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
import { convertNoTrailingWhitespace } from "../no-trailing-whitespace";
2+
3+
describe(convertNoTrailingWhitespace, () => {
4+
test("conversion without arguments", () => {
5+
const result = convertNoTrailingWhitespace({
6+
ruleArguments: [],
7+
});
8+
9+
expect(result).toEqual({
10+
rules: [
11+
{
12+
ruleName: "no-trailing-spaces",
13+
},
14+
],
15+
});
16+
});
17+
18+
test("conversion with ignore-template-strings argument", () => {
19+
const result = convertNoTrailingWhitespace({
20+
ruleArguments: ["ignore-template-strings"],
21+
});
22+
23+
expect(result).toEqual({
24+
rules: [
25+
{
26+
notices: ["ESLint does not support ignoring template strings."],
27+
ruleName: "no-trailing-spaces",
28+
},
29+
],
30+
});
31+
});
32+
33+
test("conversion with ignore-comments argument", () => {
34+
const result = convertNoTrailingWhitespace({
35+
ruleArguments: ["ignore-comments"],
36+
});
37+
38+
expect(result).toEqual({
39+
rules: [
40+
{
41+
ruleArguments: [{ ignoreComments: true }],
42+
ruleName: "no-trailing-spaces",
43+
},
44+
],
45+
});
46+
});
47+
48+
test("conversion with ignore-jsdoc argument", () => {
49+
const result = convertNoTrailingWhitespace({
50+
ruleArguments: ["ignore-jsdoc"],
51+
});
52+
53+
expect(result).toEqual({
54+
rules: [
55+
{
56+
notices: ["ESLint does not support ignoring JSDoc."],
57+
ruleName: "no-trailing-spaces",
58+
},
59+
],
60+
});
61+
});
62+
63+
test("conversion with ignore-blank-lines argument", () => {
64+
const result = convertNoTrailingWhitespace({
65+
ruleArguments: ["ignore-blank-lines"],
66+
});
67+
68+
expect(result).toEqual({
69+
rules: [
70+
{
71+
ruleArguments: [{ skipBlankLines: true }],
72+
ruleName: "no-trailing-spaces",
73+
},
74+
],
75+
});
76+
});
77+
78+
test("conversion with all arguments", () => {
79+
const result = convertNoTrailingWhitespace({
80+
ruleArguments: [
81+
"ignore-template-strings",
82+
"ignore-comments",
83+
"ignore-jsdoc",
84+
"ignore-blank-lines",
85+
],
86+
});
87+
88+
expect(result).toEqual({
89+
rules: [
90+
{
91+
notices: [
92+
"ESLint does not support ignoring template strings.",
93+
"ESLint does not support ignoring JSDoc.",
94+
],
95+
ruleArguments: [{ ignoreComments: true }, { skipBlankLines: true }],
96+
ruleName: "no-trailing-spaces",
97+
},
98+
],
99+
});
100+
});
101+
});

0 commit comments

Comments
 (0)