Skip to content

Commit 10cac29

Browse files
author
Josh Goldberg
authored
Added converter for jsx-ban-props (#864)
* Added converter for jsx-ban-props * Nest inside a forbid member
1 parent f9eef67 commit 10cac29

File tree

3 files changed

+89
-0
lines changed

3 files changed

+89
-0
lines changed

src/converters/lintConfigs/rules/ruleConverters.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ import { convertUsePipeDecorator } from "./ruleConverters/codelyzer/use-pipe-dec
176176
import { convertUsePipeTransformInterface } from "./ruleConverters/codelyzer/use-pipe-transform-interface";
177177

178178
// ESLint-React converters
179+
import { convertJsxBanProps } from "./ruleConverters/eslint-plugin-react/jsx-ban-props";
179180
import { convertJsxBooleanValue } from "./ruleConverters/eslint-plugin-react/jsx-boolean-value";
180181
import { convertJsxCurlySpacing } from "./ruleConverters/eslint-plugin-react/jsx-curly-spacing";
181182
import { convertJsxEqualsSpacing } from "./ruleConverters/eslint-plugin-react/jsx-equals-spacing";
@@ -239,6 +240,7 @@ export const ruleConverters = new Map([
239240
["interface-name", convertInterfaceName],
240241
["interface-over-type-literal", convertInterfaceOverTypeLiteral],
241242
["jsdoc-format", convertJSDocFormat],
243+
["jsx-ban-props", convertJsxBanProps],
242244
["jsx-boolean-value", convertJsxBooleanValue],
243245
["jsx-curly-spacing", convertJsxCurlySpacing],
244246
["jsx-equals-spacing", convertJsxEqualsSpacing],
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { RuleConverter } from "../../ruleConverter";
2+
3+
export const convertJsxBanProps: RuleConverter = (tslintRule) => {
4+
return {
5+
rules: [
6+
{
7+
...(tslintRule.ruleArguments.length !== 0 && {
8+
ruleArguments: tslintRule.ruleArguments.map((ruleArgument) => ({
9+
forbid:
10+
ruleArgument.length === 1
11+
? ruleArgument[0]
12+
: {
13+
message: ruleArgument[1],
14+
propName: ruleArgument[0],
15+
},
16+
})),
17+
}),
18+
ruleName: "react/forbid-component-props",
19+
},
20+
],
21+
plugins: ["eslint-plugin-react"],
22+
};
23+
};
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import { convertJsxBanProps } from "../jsx-ban-props";
2+
3+
describe(convertJsxBanProps, () => {
4+
test("conversion without arguments", () => {
5+
const result = convertJsxBanProps({
6+
ruleArguments: [],
7+
});
8+
9+
expect(result).toEqual({
10+
rules: [
11+
{
12+
ruleName: "react/forbid-component-props",
13+
},
14+
],
15+
plugins: ["eslint-plugin-react"],
16+
});
17+
});
18+
19+
test("conversion with a single prop", () => {
20+
const result = convertJsxBanProps({
21+
ruleArguments: [["someProp"]],
22+
});
23+
24+
expect(result).toEqual({
25+
rules: [
26+
{
27+
ruleArguments: [
28+
{
29+
forbid: "someProp",
30+
},
31+
],
32+
ruleName: "react/forbid-component-props",
33+
},
34+
],
35+
plugins: ["eslint-plugin-react"],
36+
});
37+
});
38+
39+
test("conversion with a message", () => {
40+
const result = convertJsxBanProps({
41+
ruleArguments: [["someProp"], ["anotherProp", "Optional explanation"]],
42+
});
43+
44+
expect(result).toEqual({
45+
rules: [
46+
{
47+
ruleArguments: [
48+
{
49+
forbid: "someProp",
50+
},
51+
{
52+
forbid: {
53+
message: "Optional explanation",
54+
propName: "anotherProp",
55+
},
56+
},
57+
],
58+
ruleName: "react/forbid-component-props",
59+
},
60+
],
61+
plugins: ["eslint-plugin-react"],
62+
});
63+
});
64+
});

0 commit comments

Comments
 (0)