Skip to content

Commit f5dbe8d

Browse files
committed
add ObjectArgument type
1 parent d6d72ce commit f5dbe8d

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,24 @@ import { RuleConverter } from "../converter";
22

33
const SUPPORTED_OPTIONS: string[] = ["anonymous", "asyncArrow", "named"];
44

5+
type ObjectArgument = Record<string, "always" | "never">;
6+
7+
const isObjectArgument = (argument: unknown): argument is ObjectArgument =>
8+
typeof argument === "object" && argument !== null;
9+
510
export const convertSpaceBeforeFunctionParen: RuleConverter = tslintRule => {
6-
const argument: "always" | "never" | { [key: string]: "always" | "never" } | undefined =
7-
tslintRule.ruleArguments[0];
11+
const argument: unknown = tslintRule.ruleArguments[0];
812
const ruleName = "space-before-function-paren";
913
if (argument === "always" || argument === "never") {
1014
return { rules: [{ ruleArguments: [argument], ruleName }] };
11-
} else if (typeof argument === "object" && argument !== null) {
15+
}
16+
if (isObjectArgument(argument)) {
1217
const notices = Object.keys(argument)
1318
.filter(option => !SUPPORTED_OPTIONS.includes(option))
1419
.map(option => `Option "${option}" is not supported by ESLint.`);
1520
const filtered = Object.keys(argument)
1621
.filter(option => SUPPORTED_OPTIONS.includes(option))
17-
.reduce<Record<string, "always" | "never">>((obj, option) => {
22+
.reduce<ObjectArgument>((obj, option) => {
1823
return { ...obj, [option]: argument[option] };
1924
}, {});
2025
return {

0 commit comments

Comments
 (0)