Skip to content

Commit a954b7a

Browse files
author
Josh Goldberg
authored
Added prefer-array-literal converter (#1009)
* Added prefer-array-literal constructor No rule options. Nice and easy. * Post merge touchups * Added no-array-constructor off
1 parent da37e6e commit a954b7a

File tree

4 files changed

+40
-2
lines changed

4 files changed

+40
-2
lines changed

src/api/convertFileCommentsStandalone.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ export type ConvertFileCommentsStandaloneDependencies = {
3333
export const convertFileCommentsStandalone = ({
3434
fileContent,
3535
filePath,
36-
ruleCommentsCache = new Map(),
37-
ruleEquivalents = new Map(),
36+
ruleCommentsCache = new Map<string, string[]>(),
37+
ruleEquivalents = new Map<string, string[]>(),
3838
}: ConvertFileCommentsStandaloneDependencies) => {
3939
const comments = parseFileComments(filePath, fileContent);
4040

src/converters/lintConfigs/rules/ruleConverters.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ import { convertOneLine } from "./ruleConverters/one-line";
112112
import { convertOneVariablePerDeclaration } from "./ruleConverters/one-variable-per-declaration";
113113
import { convertOnlyArrowFunctions } from "./ruleConverters/only-arrow-functions";
114114
import { convertOrderedImports } from "./ruleConverters/ordered-imports";
115+
import { convertPreferArrayLiteral } from "./ruleConverters/prefer-array-literal";
115116
import { convertPreferConditionalExpression } from "./ruleConverters/prefer-conditional-expression";
116117
import { convertPreferConst } from "./ruleConverters/prefer-const";
117118
import { convertPreferForOf } from "./ruleConverters/prefer-for-of";
@@ -376,6 +377,7 @@ export const ruleConverters = new Map([
376377
["only-arrow-functions", convertOnlyArrowFunctions],
377378
["ordered-imports", convertOrderedImports],
378379
["pipe-prefix", convertPipePrefix],
380+
["prefer-array-literal", convertPreferArrayLiteral],
379381
["prefer-conditional-expression", convertPreferConditionalExpression],
380382
["prefer-const", convertPreferConst],
381383
["prefer-for-of", convertPreferForOf],
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { RuleConverter } from "../ruleConverter";
2+
3+
export const convertPreferArrayLiteral: RuleConverter = () => {
4+
return {
5+
rules: [
6+
{
7+
ruleName: "no-array-constructor",
8+
ruleSeverity: "off"
9+
},
10+
{
11+
ruleName: "@typescript-eslint/no-array-constructor",
12+
},
13+
],
14+
};
15+
};
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { convertPreferArrayLiteral } from "../prefer-array-literal";
2+
3+
describe(convertPreferArrayLiteral, () => {
4+
test("conversion without arguments", () => {
5+
const result = convertPreferArrayLiteral({
6+
ruleArguments: [],
7+
});
8+
9+
expect(result).toEqual({
10+
rules: [
11+
{
12+
ruleName: "no-array-constructor",
13+
ruleSeverity: "off"
14+
},
15+
{
16+
ruleName: "@typescript-eslint/no-array-constructor",
17+
},
18+
],
19+
});
20+
});
21+
});

0 commit comments

Comments
 (0)