Skip to content

Commit 09cf55f

Browse files
mauricetmeyerJosh Goldberg
authored and
Josh Goldberg
committed
Added missing prefer-readonly converter (#191)
1 parent c77f1b1 commit 09cf55f

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

src/rules/converters.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ import { convertPreferConst } from "./converters/prefer-const";
8686
import { convertPreferForOf } from "./converters/prefer-for-of";
8787
import { convertPreferFunctionOverMethod } from "./converters/prefer-function-over-method";
8888
import { convertPreferObjectSpread } from "./converters/prefer-object-spread";
89+
import { convertPreferReadonly } from "./converters/prefer-readonly";
8990
import { convertPreferTemplate } from "./converters/prefer-template";
9091
import { convertPromiseFunctionAsync } from "./converters/promise-function-async";
9192
import { convertRadix } from "./converters/radix";
@@ -194,6 +195,7 @@ export const converters = new Map([
194195
["one-variable-per-declaration", convertOneVariablePerDeclaration],
195196
["prefer-const", convertPreferConst],
196197
["prefer-function-over-method", convertPreferFunctionOverMethod],
198+
["prefer-readonly", convertPreferReadonly],
197199
["prefer-template", convertPreferTemplate],
198200
["space-before-function-paren", convertSpaceBeforeFunctionParen],
199201
["switch-default", convertSwitchDefault],
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { RuleConverter } from "../converter";
2+
3+
export const convertPreferReadonly: RuleConverter = tslintRule => {
4+
return {
5+
rules: [
6+
{
7+
...(tslintRule.ruleArguments.length !== 0 &&
8+
tslintRule.ruleArguments[0] === "only-inline-lambdas" && {
9+
ruleArguments: [{ onlyInlineLambdas: true }],
10+
}),
11+
ruleName: "prefer-readonly",
12+
},
13+
],
14+
};
15+
};
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { convertPreferReadonly } from "../prefer-readonly";
2+
3+
describe(convertPreferReadonly, () => {
4+
test("conversion without arguments", () => {
5+
const result = convertPreferReadonly({
6+
ruleArguments: [],
7+
});
8+
9+
expect(result).toEqual({
10+
rules: [
11+
{
12+
ruleName: "prefer-readonly",
13+
},
14+
],
15+
});
16+
});
17+
18+
test("conversion with an argument", () => {
19+
const result = convertPreferReadonly({
20+
ruleArguments: ["only-inline-lambdas"],
21+
});
22+
23+
expect(result).toEqual({
24+
rules: [
25+
{
26+
ruleArguments: [{ onlyInlineLambdas: true }],
27+
ruleName: "prefer-readonly",
28+
},
29+
],
30+
});
31+
});
32+
});

0 commit comments

Comments
 (0)