Skip to content

Commit ead9ab5

Browse files
committed
fix: generating space-before-function-paren (#147)
1 parent 2cccfd0 commit ead9ab5

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed

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

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

3+
function isExistedESLintOption(rule: string) {
4+
return ["anonymous", "named", "asyncArrow"].includes(rule);
5+
}
6+
37
export const convertSpaceBeforeFunctionParen: RuleConverter = tslintRule => {
8+
const tslintRuleArguments = tslintRule.ruleArguments;
9+
const ruleArguments = tslintRuleArguments.filter(isExistedESLintOption);
410
return {
511
rules: [
612
{
7-
...(tslintRule.ruleArguments.length !== 0 && {
8-
ruleArguments: tslintRule.ruleArguments,
13+
...(tslintRuleArguments.length !== 0 && {
14+
ruleArguments,
15+
...(tslintRuleArguments.length > ruleArguments.length && {
16+
notices: [
17+
'ESLint doesn\'t support the following options: "method" and "constructor". These two options can be covered by "named" therefore make sure you have set this option.',
18+
],
19+
}),
920
}),
1021
ruleName: "space-before-function-paren",
1122
},

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,40 @@ 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+
'ESLint doesn\'t support the following options: "method" and "constructor". These two options can be covered by "named" therefore make sure you have set this option.',
43+
],
44+
ruleArguments: ["anonymous", "named", "asyncArrow"],
45+
ruleName: "space-before-function-paren",
46+
},
47+
],
48+
});
49+
});
50+
51+
test('conversion with not supported options ["method", "constructor"]', () => {
52+
const result = convertSpaceBeforeFunctionParen({
53+
ruleArguments: ["method", "constructor"],
54+
});
55+
56+
expect(result).toEqual({
57+
rules: [
58+
{
59+
notices: [
60+
'ESLint doesn\'t support the following options: "method" and "constructor". These two options can be covered by "named" therefore make sure you have set this option.',
61+
],
62+
ruleArguments: [],
63+
ruleName: "space-before-function-paren",
64+
},
65+
],
66+
});
67+
});
3268
});

0 commit comments

Comments
 (0)