Skip to content

Commit f24d3bc

Browse files
KingDarBojaJosh Goldberg
authored and
Josh Goldberg
committed
Implement no-submodule-imports converter (#223)
* Implement no-submodule-imports converter * Add pattern to rule arguments on submodule imports
1 parent f0308e9 commit f24d3bc

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed

src/rules/converters.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ import { convertNoShadowedVariable } from "./converters/no-shadowed-variable";
7676
import { convertNoSparseArrays } from "./converters/no-sparse-arrays";
7777
import { convertNoStringLiteral } from "./converters/no-string-literal";
7878
import { convertNoStringThrow } from "./converters/no-string-throw";
79+
import { convertNoSubmoduleImports } from "./converters/no-submodule-imports";
7980
import { convertNoSwitchCaseFallThrough } from "./converters/no-switch-case-fall-through";
8081
import { convertNoThisAssignment } from "./converters/no-this-assignment";
8182
import { convertNoTrailingWhitespace } from "./converters/no-trailing-whitespace";
@@ -200,6 +201,7 @@ export const converters = new Map([
200201
["no-sparse-arrays", convertNoSparseArrays],
201202
["no-string-literal", convertNoStringLiteral],
202203
["no-string-throw", convertNoStringThrow],
204+
["no-submodule-imports", convertNoSubmoduleImports],
203205
["no-switch-case-fall-through", convertNoSwitchCaseFallThrough],
204206
["no-this-assignment", convertNoThisAssignment],
205207
["no-trailing-whitespace", convertNoTrailingWhitespace],
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { RuleConverter } from "../converter";
2+
3+
export const convertNoSubmoduleImports: RuleConverter = tslintRule => {
4+
const ruleArguments: string[] = [];
5+
6+
if (
7+
!(
8+
tslintRule.ruleArguments.length === 0 ||
9+
tslintRule.ruleArguments[0] === false ||
10+
tslintRule.ruleArguments.length < 2
11+
)
12+
) {
13+
ruleArguments.push(
14+
...tslintRule.ruleArguments.map(ruleArg => {
15+
if (typeof ruleArg === "string") {
16+
return ruleArg.concat("/*");
17+
}
18+
return ruleArg;
19+
}),
20+
);
21+
}
22+
23+
return {
24+
rules: [
25+
{
26+
ruleName: "import/no-internal-modules",
27+
...{
28+
ruleArguments:
29+
ruleArguments.length > 0 ? [{ allow: ruleArguments }] : undefined,
30+
},
31+
},
32+
],
33+
plugins: ["eslint-plugin-import"],
34+
};
35+
};
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { convertNoSubmoduleImports } from "../no-submodule-imports";
2+
3+
describe(convertNoSubmoduleImports, () => {
4+
test("conversion without arguments", () => {
5+
const result = convertNoSubmoduleImports({
6+
ruleArguments: [],
7+
});
8+
9+
expect(result).toEqual({
10+
rules: [
11+
{
12+
ruleName: "import/no-internal-modules",
13+
},
14+
],
15+
plugins: ["eslint-plugin-import"],
16+
});
17+
});
18+
19+
test("conversion with arguments", () => {
20+
const result = convertNoSubmoduleImports({
21+
ruleArguments: [true, "rxjs"],
22+
});
23+
24+
expect(result).toEqual({
25+
rules: [
26+
{
27+
ruleName: "import/no-internal-modules",
28+
ruleArguments: [{ allow: [true, "rxjs/*"] }],
29+
},
30+
],
31+
plugins: ["eslint-plugin-import"],
32+
});
33+
});
34+
});

0 commit comments

Comments
 (0)