Skip to content

Commit 8f355e8

Browse files
dimaboryJosh Goldberg
authored and
Josh Goldberg
committed
fix: generating space-before-function-paren (#147) (#273)
1 parent e3f3b86 commit 8f355e8

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

src/rules/converters/space-before-function-paren.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,26 @@
11
import { RuleConverter } from "../converter";
22

3+
const NOT_SUPPORTED_OPTIONS = ["constructor", "method"];
4+
5+
function isExistedESLintOption(rule: string) {
6+
return !NOT_SUPPORTED_OPTIONS.includes(rule);
7+
}
8+
39
export const convertSpaceBeforeFunctionParen: RuleConverter = tslintRule => {
10+
const ruleArguments = tslintRule.ruleArguments.filter(isExistedESLintOption);
11+
const notices = NOT_SUPPORTED_OPTIONS.reduce<string[]>((acc, option) => {
12+
if (tslintRule.ruleArguments.includes(option)) {
13+
acc.push(`Option "${option}" is not supported by ESLint.`);
14+
}
15+
return acc;
16+
}, []);
17+
418
return {
519
rules: [
620
{
721
...(tslintRule.ruleArguments.length !== 0 && {
8-
ruleArguments: tslintRule.ruleArguments,
22+
ruleArguments,
23+
...(notices.length !== 0 && { notices }),
924
}),
1025
ruleName: "space-before-function-paren",
1126
},

src/rules/converters/tests/space-before-function-paren.test.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,42 @@ describe(convertSpaceBeforeFunctionParen, () => {
2929
],
3030
});
3131
});
32+
33+
test("conversion with all existing arguments", () => {
34+
const result = convertSpaceBeforeFunctionParen({
35+
ruleArguments: ["anonymous", "named", "asyncArrow", "method", "constructor"],
36+
});
37+
38+
expect(result).toEqual({
39+
rules: [
40+
{
41+
notices: [
42+
'Option "constructor" is not supported by ESLint.',
43+
'Option "method" is not supported by ESLint.',
44+
],
45+
ruleArguments: ["anonymous", "named", "asyncArrow"],
46+
ruleName: "space-before-function-paren",
47+
},
48+
],
49+
});
50+
});
51+
52+
test('conversion with not supported options ["method", "constructor"]', () => {
53+
const result = convertSpaceBeforeFunctionParen({
54+
ruleArguments: ["method", "constructor"],
55+
});
56+
57+
expect(result).toEqual({
58+
rules: [
59+
{
60+
notices: [
61+
'Option "constructor" is not supported by ESLint.',
62+
'Option "method" is not supported by ESLint.',
63+
],
64+
ruleArguments: [],
65+
ruleName: "space-before-function-paren",
66+
},
67+
],
68+
});
69+
});
3270
});

0 commit comments

Comments
 (0)