Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/rules/converters/space-before-function-paren.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
import { RuleConverter } from "../converter";

const NOT_SUPPORTED_OPTIONS = ["constructor", "method"];

function isExistedESLintOption(rule: string) {
return !NOT_SUPPORTED_OPTIONS.includes(rule);
}

export const convertSpaceBeforeFunctionParen: RuleConverter = tslintRule => {
const ruleArguments = tslintRule.ruleArguments.filter(isExistedESLintOption);
const notices = NOT_SUPPORTED_OPTIONS.reduce<string[]>((acc, option) => {
if (tslintRule.ruleArguments.includes(option)) {
acc.push(`Option "${option}" is not supported by ESLint.`);
}
return acc;
}, []);

return {
rules: [
{
...(tslintRule.ruleArguments.length !== 0 && {
ruleArguments: tslintRule.ruleArguments,
ruleArguments,
...(notices.length !== 0 && { notices }),
}),
ruleName: "space-before-function-paren",
},
Expand Down
38 changes: 38 additions & 0 deletions src/rules/converters/tests/space-before-function-paren.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,42 @@ describe(convertSpaceBeforeFunctionParen, () => {
],
});
});

test("conversion with all existing arguments", () => {
const result = convertSpaceBeforeFunctionParen({
ruleArguments: ["anonymous", "named", "asyncArrow", "method", "constructor"],
});

expect(result).toEqual({
rules: [
{
notices: [
'Option "constructor" is not supported by ESLint.',
'Option "method" is not supported by ESLint.',
],
ruleArguments: ["anonymous", "named", "asyncArrow"],
ruleName: "space-before-function-paren",
},
],
});
});

test('conversion with not supported options ["method", "constructor"]', () => {
const result = convertSpaceBeforeFunctionParen({
ruleArguments: ["method", "constructor"],
});

expect(result).toEqual({
rules: [
{
notices: [
'Option "constructor" is not supported by ESLint.',
'Option "method" is not supported by ESLint.',
],
ruleArguments: [],
ruleName: "space-before-function-paren",
},
],
});
});
});