Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
86 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,38 @@ | ||
import { RuleConverter } from "../converter"; | ||
|
||
const NOT_SUPPORTED_OPTIONS = ["constructor", "method"]; | ||
const SUPPORTED_OPTIONS: string[] = ["anonymous", "asyncArrow", "named"]; | ||
|
||
function isExistedESLintOption(rule: string) { | ||
return !NOT_SUPPORTED_OPTIONS.includes(rule); | ||
} | ||
type ObjectArgument = Record<string, "always" | "never">; | ||
|
||
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; | ||
}, []); | ||
const isObjectArgument = (argument: unknown): argument is ObjectArgument => | ||
typeof argument === "object" && argument !== null; | ||
|
||
return { | ||
rules: [ | ||
{ | ||
...(tslintRule.ruleArguments.length !== 0 && { | ||
ruleArguments, | ||
export const convertSpaceBeforeFunctionParen: RuleConverter = tslintRule => { | ||
const argument: unknown = tslintRule.ruleArguments[0]; | ||
const ruleName = "space-before-function-paren"; | ||
if (argument === "always" || argument === "never") { | ||
return { rules: [{ ruleArguments: [argument], ruleName }] }; | ||
} | ||
if (isObjectArgument(argument)) { | ||
const notices = Object.keys(argument) | ||
.filter(option => !SUPPORTED_OPTIONS.includes(option)) | ||
.map(option => `Option "${option}" is not supported by ESLint.`); | ||
const filtered = Object.keys(argument) | ||
.filter(option => SUPPORTED_OPTIONS.includes(option)) | ||
.reduce<ObjectArgument>((obj, option) => { | ||
return { ...obj, [option]: argument[option] }; | ||
}, {}); | ||
return { | ||
rules: [ | ||
{ | ||
...(notices.length !== 0 && { notices }), | ||
}), | ||
ruleName: "space-before-function-paren", | ||
}, | ||
], | ||
}; | ||
...(Object.keys(filtered).length !== 0 && { | ||
ruleArguments: [filtered], | ||
}), | ||
ruleName, | ||
}, | ||
], | ||
}; | ||
} | ||
return { rules: [{ ruleName }] }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters