Skip to content

Commit d8d34d8

Browse files
bmeverettJosh Goldberg
authored and
Josh Goldberg
committed
add converter for space-within-parens rule (#193)
* add converter for space-within-parens rule * convert rule to eslint equivalent * fix eslint error * add notices for space-within-parens * add notice only if parameter supplied * fix duplicates from conflict * make sure converter is actually used
1 parent f24d3bc commit d8d34d8

File tree

3 files changed

+61
-1
lines changed

3 files changed

+61
-1
lines changed

src/rules/converters.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ import { convertRadix } from "./converters/radix";
107107
import { convertRestrictPlusOperands } from "./converters/restrict-plus-operands";
108108
import { convertSemicolon } from "./converters/semicolon";
109109
import { convertSpaceBeforeFunctionParen } from "./converters/space-before-function-paren";
110+
import { convertSpaceWithinParens } from "./converters/space-within-parens";
110111
import { convertSwitchDefault } from "./converters/switch-default";
111112
import { convertTypedefWhitespace } from "./converters/typedef-whitespace";
112113
import { convertTypeLiteralDelimiter } from "./converters/type-literal-delimiter";
@@ -233,6 +234,7 @@ export const converters = new Map([
233234
["restrict-plus-operands", convertRestrictPlusOperands],
234235
["semicolon", convertSemicolon],
235236
["space-before-function-paren", convertSpaceBeforeFunctionParen],
237+
["space-within-parens", convertSpaceWithinParens],
236238
["switch-default", convertSwitchDefault],
237239
["triple-equals", convertTripleEquals],
238240
["type-literal-delimiter", convertTypeLiteralDelimiter],
@@ -254,7 +256,9 @@ export const converters = new Map([
254256
// ["import-blacklist", convertImportBlacklist], // no-restricted-imports
255257
// ["no-duplicate-variable", convertNoDuplicateVariable], // no-redeclare
256258
// ["no-unused-expression", convertNoUnusedExpression], // no-unused-expressions
257-
// ["space-within-parens", convertSpaceWithinParens], // space-in-parens
259+
// ["no-void-expression", convertNoVoidExpression], // (no exact equivalent)
260+
// ["quotemark", convertQuotemark], // quotes
261+
// ["triple-equals", convertTripleEquals], // eqeqeq
258262
// ["variable-name", convertVariableName], // a bunch of rules...
259263

260264
// tslint-microsoft-contrib rules:
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { RuleConverter } from "../converter";
2+
3+
export const convertSpaceWithinParens: RuleConverter = tslintRule => {
4+
let arg = "never";
5+
const notices = [];
6+
7+
if (tslintRule.ruleArguments.length === 1) {
8+
arg = "always";
9+
notices.push("The number of spaces will be ignored");
10+
}
11+
12+
return {
13+
rules: [
14+
{
15+
ruleArguments: [arg],
16+
ruleName: "@typescript-eslint/space-within-parens",
17+
notices,
18+
},
19+
],
20+
};
21+
};
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { convertSpaceWithinParens } from "../space-within-parens";
2+
3+
describe(convertSpaceWithinParens, () => {
4+
test("conversion without arguments", () => {
5+
const result = convertSpaceWithinParens({
6+
ruleArguments: [],
7+
});
8+
9+
expect(result).toEqual({
10+
rules: [
11+
{
12+
ruleArguments: ["never"],
13+
ruleName: "@typescript-eslint/space-within-parens",
14+
notices: [],
15+
},
16+
],
17+
});
18+
});
19+
20+
test("conversion with min spaces arguement", () => {
21+
const result = convertSpaceWithinParens({
22+
ruleArguments: [5],
23+
});
24+
25+
expect(result).toEqual({
26+
rules: [
27+
{
28+
ruleArguments: ["always"],
29+
ruleName: "@typescript-eslint/space-within-parens",
30+
notices: ["The number of spaces will be ignored"],
31+
},
32+
],
33+
});
34+
});
35+
});

0 commit comments

Comments
 (0)