Skip to content

Commit 3acdba1

Browse files
gzuzmarkJosh Goldberg
authored and
Josh Goldberg
committed
Added ordered-imports converter (#211)
1 parent eca2977 commit 3acdba1

File tree

3 files changed

+98
-0
lines changed

3 files changed

+98
-0
lines changed

src/rules/converters.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ import { convertObjectLiteralKeyQuotes } from "./converters/object-literal-key-q
9090
import { convertObjectLiteralShorthand } from "./converters/object-literal-shorthand";
9191
import { convertOneVariablePerDeclaration } from "./converters/one-variable-per-declaration";
9292
import { convertOnlyArrowFunctions } from "./converters/only-arrow-functions";
93+
import { convertOrderedImports } from "./converters/ordered-imports";
9394
import { convertPreferConst } from "./converters/prefer-const";
9495
import { convertPreferForOf } from "./converters/prefer-for-of";
9596
import { convertPreferFunctionOverMethod } from "./converters/prefer-function-over-method";
@@ -207,6 +208,7 @@ export const converters = new Map([
207208
["object-literal-shorthand", convertObjectLiteralShorthand],
208209
["one-variable-per-declaration", convertOneVariablePerDeclaration],
209210
["only-arrow-functions", convertOnlyArrowFunctions],
211+
["ordered-imports", convertOrderedImports],
210212
["prefer-const", convertPreferConst],
211213
["prefer-for-of", convertPreferForOf],
212214
["prefer-function-over-method", convertPreferFunctionOverMethod],
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { RuleConverter } from "../converter";
2+
3+
export const convertOrderedImports: RuleConverter = tslintRule => {
4+
const notices: string[] = [];
5+
const unsupportedtslintOptions = [
6+
"import-sources-order",
7+
"named-imports-order",
8+
"module-source-path",
9+
];
10+
11+
unsupportedtslintOptions.forEach(option => {
12+
if (tslintRule.ruleArguments.includes(option)) {
13+
notices.push(`Option "${option}" is not supported by ESLint.`);
14+
}
15+
});
16+
17+
return {
18+
rules: [
19+
{
20+
...(notices.length > 0 && { notices }),
21+
ruleName: "import/order",
22+
},
23+
],
24+
plugins: ["import"],
25+
};
26+
};
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import { convertOrderedImports } from "../ordered-imports";
2+
3+
describe(convertOrderedImports, () => {
4+
test("conversion without arguments", () => {
5+
const result = convertOrderedImports({
6+
ruleArguments: [],
7+
});
8+
9+
expect(result).toEqual({
10+
rules: [
11+
{
12+
ruleName: "import/order",
13+
},
14+
],
15+
plugins: ["import"],
16+
});
17+
});
18+
19+
test("conversion with allow-declarations argument", () => {
20+
const result = convertOrderedImports({
21+
ruleArguments: ["import-sources-order"],
22+
});
23+
24+
expect(result).toEqual({
25+
rules: [
26+
{
27+
notices: ['Option "import-sources-order" is not supported by ESLint.'],
28+
ruleName: "import/order",
29+
},
30+
],
31+
plugins: ["import"],
32+
});
33+
});
34+
35+
test("conversion with allow-declarations argument", () => {
36+
const result = convertOrderedImports({
37+
ruleArguments: ["named-imports-order"],
38+
});
39+
40+
expect(result).toEqual({
41+
rules: [
42+
{
43+
notices: ['Option "named-imports-order" is not supported by ESLint.'],
44+
ruleName: "import/order",
45+
},
46+
],
47+
plugins: ["import"],
48+
});
49+
});
50+
51+
test("conversion with unsupported arguments", () => {
52+
const result = convertOrderedImports({
53+
ruleArguments: ["import-sources-order", "named-imports-order", "module-source-path"],
54+
});
55+
56+
expect(result).toEqual({
57+
rules: [
58+
{
59+
notices: [
60+
'Option "import-sources-order" is not supported by ESLint.',
61+
'Option "named-imports-order" is not supported by ESLint.',
62+
'Option "module-source-path" is not supported by ESLint.',
63+
],
64+
ruleName: "import/order",
65+
},
66+
],
67+
plugins: ["import"],
68+
});
69+
});
70+
});

0 commit comments

Comments
 (0)