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
2 changes: 2 additions & 0 deletions src/rules/converters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ import { convertNoVarRequires } from "./converters/no-var-requires";
import { convertObjectLiteralKeyQuotes } from "./converters/object-literal-key-quotes";
import { convertObjectLiteralShorthand } from "./converters/object-literal-shorthand";
import { convertOneVariablePerDeclaration } from "./converters/one-variable-per-declaration";
import { convertOnlyArrowFunctions } from "./converters/only-arrow-functions";
import { convertPreferConst } from "./converters/prefer-const";
import { convertPreferForOf } from "./converters/prefer-for-of";
import { convertPreferFunctionOverMethod } from "./converters/prefer-function-over-method";
Expand Down Expand Up @@ -193,6 +194,7 @@ export const converters = new Map([
["object-literal-key-quotes", convertObjectLiteralKeyQuotes],
["object-literal-shorthand", convertObjectLiteralShorthand],
["one-variable-per-declaration", convertOneVariablePerDeclaration],
["only-arrow-functions", convertOnlyArrowFunctions],
["prefer-const", convertPreferConst],
["prefer-function-over-method", convertPreferFunctionOverMethod],
["prefer-readonly", convertPreferReadonly],
Expand Down
25 changes: 25 additions & 0 deletions src/rules/converters/only-arrow-functions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { RuleConverter } from "../converter";

export const convertOnlyArrowFunctions: RuleConverter = tslintRule => {
const notices: string[] = [];

if (tslintRule.ruleArguments.includes("allow-declarations")) {
notices.push("ESLint does not support allowing standalone function declarations.");
}

if (tslintRule.ruleArguments.includes("allow-named-functions")) {
notices.push(
"ESLint does not support allowing named functions defined with the function keyword.",
);
}

return {
rules: [
{
...(notices.length > 0 && { notices }),
ruleName: "prefer-arrow/prefer-arrow-functions",
},
],
plugins: ["prefer-arrow"],
};
};
71 changes: 71 additions & 0 deletions src/rules/converters/tests/only-arrow-functions.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { convertOnlyArrowFunctions } from "../only-arrow-functions";

describe(convertOnlyArrowFunctions, () => {
test("conversion without arguments", () => {
const result = convertOnlyArrowFunctions({
ruleArguments: [],
});

expect(result).toEqual({
rules: [
{
ruleName: "prefer-arrow/prefer-arrow-functions",
},
],
plugins: ["prefer-arrow"],
});
});

test("conversion with allow-declarations argument", () => {
const result = convertOnlyArrowFunctions({
ruleArguments: ["allow-declarations"],
});

expect(result).toEqual({
rules: [
{
notices: ["ESLint does not support allowing standalone function declarations."],
ruleName: "prefer-arrow/prefer-arrow-functions",
},
],
plugins: ["prefer-arrow"],
});
});

test("conversion with allow-named-functions argument", () => {
const result = convertOnlyArrowFunctions({
ruleArguments: ["allow-named-functions"],
});

expect(result).toEqual({
rules: [
{
notices: [
"ESLint does not support allowing named functions defined with the function keyword.",
],
ruleName: "prefer-arrow/prefer-arrow-functions",
},
],
plugins: ["prefer-arrow"],
});
});

test("conversion with all arguments", () => {
const result = convertOnlyArrowFunctions({
ruleArguments: ["allow-declarations", "allow-named-functions"],
});

expect(result).toEqual({
rules: [
{
notices: [
"ESLint does not support allowing standalone function declarations.",
"ESLint does not support allowing named functions defined with the function keyword.",
],
ruleName: "prefer-arrow/prefer-arrow-functions",
},
],
plugins: ["prefer-arrow"],
});
});
});