Skip to content

Commit

Permalink
refactor(migrate/eslint): improve naming-convention migration (biomej…
Browse files Browse the repository at this point in the history
  • Loading branch information
Conaclos authored May 25, 2024
1 parent 08b2013 commit b3da3ae
Show file tree
Hide file tree
Showing 10 changed files with 827 additions and 326 deletions.
1 change: 1 addition & 0 deletions crates/biome_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ hdrhistogram = { version = "7.5.4", default-features = false }
indexmap = { workspace = true }
lazy_static = { workspace = true }
rayon = { workspace = true }
regex = { workspace = true }
rustc-hash = { workspace = true }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion crates/biome_cli/src/execute/migrate/eslint_to_biome.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ fn migrate_eslint_rule(
eslint_eslint::Rule::TypeScriptNamingConvention(conf) => {
if migrate_eslint_any_rule(rules, &name, conf.severity(), opts, results) {
let severity = conf.severity();
let options = eslint_typescript::NamingConventionOptions::override_default(
let options = eslint_typescript::NamingConventionOptions::new(
conf.into_vec().into_iter().map(|v| *v),
);
let group = rules.style.get_or_insert_with(Default::default);
Expand Down
571 changes: 461 additions & 110 deletions crates/biome_cli/src/execute/migrate/eslint_typescript.rs

Large diffs are not rendered by default.

22 changes: 20 additions & 2 deletions crates/biome_cli/tests/commands/migrate_eslint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,28 @@ fn migrate_eslintrcjson_rule_options() {
}],
"@typescript-eslint/array-type": ["error", { "default": "generic" }],
"@typescript-eslint/naming-convention": ["error",
{
"selector": "property",
"leadingUnderscore": "forbid"
},
{
"selector": "property",
"modifiers": ["private"],
"format": ["strictCamelCase"],
"leadingUnderscore": "require"
},
{
"selector": "interface",
"prefix": ["I", "IO"]
},
{
"selector": "enumMember",
"format": ["UPPER_CASE"]
},
{
"selector": "variable",
"types": ["boolean"],
"format": ["UPPER_CASE"]
}
],
"unicorn/filename-case": ["error", {
Expand Down Expand Up @@ -301,7 +320,7 @@ fn migrate_eslintrcjson_rule_options() {
"multipleFileExtensions": true
}]
}
}],
}]
}"#;

let mut fs = MemoryFileSystem::default();
Expand All @@ -315,7 +334,6 @@ fn migrate_eslintrcjson_rule_options() {
Args::from(["migrate", "eslint", "--include-inspired"].as_slice()),
);

assert!(result.is_ok(), "run_cli returned {result:?}");
assert_cli_snapshot(SnapshotPayload::new(
module_path!(),
"migrate_eslintrcjson_rule_options",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,28 @@ expression: content
}],
"@typescript-eslint/array-type": ["error", { "default": "generic" }],
"@typescript-eslint/naming-convention": ["error",
{
"selector": "property",
"leadingUnderscore": "forbid"
},
{
"selector": "property",
"modifiers": ["private"],
"format": ["strictCamelCase"],
"leadingUnderscore": "require"
},
{
"selector": "interface",
"prefix": ["I", "IO"]
},
{
"selector": "enumMember",
"format": ["UPPER_CASE"]
},
{
"selector": "variable",
"types": ["boolean"],
"format": ["UPPER_CASE"]
}
],
"unicorn/filename-case": ["error", {
Expand Down Expand Up @@ -66,7 +85,7 @@ expression: content
"multipleFileExtensions": true
}]
}
}],
}]
}
```

Expand All @@ -77,96 +96,122 @@ biome.json migrate ━━━━━━━━━━━━━━━━━━━━
i Configuration file can be updated.
1 │ - {·"linter":·{·"enabled":·true·}·}
1 │ + {
2 │ + → "linter":·{
3 │ + → → "enabled":·true,
4 │ + → → "rules":·{
5 │ + → → → "recommended":·false,
6 │ + → → → "a11y":·{
7 │ + → → → → "useValidAriaRole":·{
8 │ + → → → → → "level":·"error",
9 │ + → → → → → "options":·{·"allowInvalidRoles":·["text"],·"ignoreNonDom":·true·}
10 │ + → → → → }
11 │ + → → → },
12 │ + → → → "style":·{
13 │ + → → → → "noRestrictedGlobals":·{
14 │ + → → → → → "level":·"error",
15 │ + → → → → → "options":·{·"deniedGlobals":·["event",·"fdescribe"]·}
16 │ + → → → → },
17 │ + → → → → "useConsistentArrayType":·{
18 │ + → → → → → "level":·"error",
19 │ + → → → → → "options":·{·"syntax":·"generic"·}
20 │ + → → → → },
21 │ + → → → → "useFilenamingConvention":·{
22 │ + → → → → → "level":·"error",
23 │ + → → → → → "options":·{
24 │ + → → → → → → "requireAscii":·true,
25 │ + → → → → → → "filenameCases":·["camelCase",·"PascalCase"]
26 │ + → → → → → }
27 │ + → → → → },
28 │ + → → → → "useNamingConvention":·{
29 │ + → → → → → "level":·"error",
30 │ + → → → → → "options":·{·"strictCase":·false,·"enumMemberCase":·"CONSTANT_CASE"·}
31 │ + → → → → }
32 │ + → → → }
33 │ + → → }
34 │ + → },
35 │ + → "overrides":·[
36 │ + → → {
37 │ + → → → "include":·["default.js"],
38 │ + → → → "linter":·{
39 │ + → → → → "rules":·{
40 │ + → → → → → "a11y":·{·"useValidAriaRole":·"error"·},
41 │ + → → → → → "style":·{
42 │ + → → → → → → "noRestrictedGlobals":·{·"level":·"error",·"options":·{}·},
43 │ + → → → → → → "useConsistentArrayType":·"error",
44 │ + → → → → → → "useFilenamingConvention":·{
45 │ + → → → → → → → "level":·"error",
46 │ + → → → → → → → "options":·{
47 │ + → → → → → → → → "requireAscii":·true,
48 │ + → → → → → → → → "filenameCases":·["kebab-case"]
49 │ + → → → → → → → }
50 │ + → → → → → → },
51 │ + → → → → → → "useNamingConvention":·{
52 │ + → → → → → → → "level":·"error",
53 │ + → → → → → → → "options":·{·"strictCase":·false·}
54 │ + → → → → → → }
55 │ + → → → → → }
56 │ + → → → → }
57 │ + → → → }
58 │ + → → },
59 │ + → → {
60 │ + → → → "include":·["alternative.js"],
61 │ + → → → "linter":·{
62 │ + → → → → "rules":·{
63 │ + → → → → → "style":·{
64 │ + → → → → → → "noRestrictedGlobals":·{
65 │ + → → → → → → → "level":·"error",
66 │ + → → → → → → → "options":·{·"deniedGlobals":·["event",·"fdescribe"]·}
67 │ + → → → → → → },
68 │ + → → → → → → "useConsistentArrayType":·{
69 │ + → → → → → → → "level":·"error",
70 │ + → → → → → → → "options":·{·"syntax":·"shorthand"·}
71 │ + → → → → → → },
72 │ + → → → → → → "useFilenamingConvention":·{
73 │ + → → → → → → → "level":·"error",
74 │ + → → → → → → → "options":·{
75 │ + → → → → → → → → "requireAscii":·true,
76 │ + → → → → → → → → "filenameCases":·["kebab-case"]
77 │ + → → → → → → → }
78 │ + → → → → → → },
79 │ + → → → → → → "useNamingConvention":·{
80 │ + → → → → → → → "level":·"error",
81 │ + → → → → → → → "options":·{·"strictCase":·false·}
82 │ + → → → → → → }
83 │ + → → → → → }
84 │ + → → → → }
85 │ + → → → }
86 │ + → → }
87 │ + → ]
88 │ + }
89 │ +
1 │ - {·"linter":·{·"enabled":·true·}·}
1 │ + {
2 │ + → "linter":·{
3 │ + → → "enabled":·true,
4 │ + → → "rules":·{
5 │ + → → → "recommended":·false,
6 │ + → → → "a11y":·{
7 │ + → → → → "useValidAriaRole":·{
8 │ + → → → → → "level":·"error",
9 │ + → → → → → "options":·{·"allowInvalidRoles":·["text"],·"ignoreNonDom":·true·}
10 │ + → → → → }
11 │ + → → → },
12 │ + → → → "style":·{
13 │ + → → → → "noRestrictedGlobals":·{
14 │ + → → → → → "level":·"error",
15 │ + → → → → → "options":·{·"deniedGlobals":·["event",·"fdescribe"]·}
16 │ + → → → → },
17 │ + → → → → "useConsistentArrayType":·{
18 │ + → → → → → "level":·"error",
19 │ + → → → → → "options":·{·"syntax":·"generic"·}
20 │ + → → → → },
21 │ + → → → → "useFilenamingConvention":·{
22 │ + → → → → → "level":·"error",
23 │ + → → → → → "options":·{
24 │ + → → → → → → "requireAscii":·true,
25 │ + → → → → → → "filenameCases":·["camelCase",·"PascalCase"]
26 │ + → → → → → }
27 │ + → → → → },
28 │ + → → → → "useNamingConvention":·{
29 │ + → → → → → "level":·"error",
30 │ + → → → → → "options":·{
31 │ + → → → → → → "strictCase":·false,
32 │ + → → → → → → "conventions":·[
33 │ + → → → → → → → {
34 │ + → → → → → → → → "selector":·{·"kind":·"enumMember"·},
35 │ + → → → → → → → → "formats":·["CONSTANT_CASE"]
36 │ + → → → → → → → },
37 │ + → → → → → → → {·"selector":·{·"kind":·"interface"·},·"match":·"(?:I|IO)(.*)"·},
38 │ + → → → → → → → {
39 │ + → → → → → → → → "selector":·{
40 │ + → → → → → → → → → "kind":·"classProperty",
41 │ + → → → → → → → → → "modifiers":·["private"]
42 │ + → → → → → → → → },
43 │ + → → → → → → → → "match":·"_([^_]*)",
44 │ + → → → → → → → → "formats":·["camelCase"]
45 │ + → → → → → → → },
46 │ + → → → → → → → {·"selector":·{·"kind":·"classProperty"·},·"match":·"([^_]*)"·},
47 │ + → → → → → → → {·"selector":·{·"kind":·"typeProperty"·},·"match":·"([^_]*)"·},
48 │ + → → → → → → → {
49 │ + → → → → → → → → "selector":·{·"kind":·"objectLiteralProperty"·},
50 │ + → → → → → → → → "match":·"([^_]*)"
51 │ + → → → → → → → }
52 │ + → → → → → → ]
53 │ + → → → → → }
54 │ + → → → → }
55 │ + → → → }
56 │ + → → }
57 │ + → },
58 │ + → "overrides":·[
59 │ + → → {
60 │ + → → → "include":·["default.js"],
61 │ + → → → "linter":·{
62 │ + → → → → "rules":·{
63 │ + → → → → → "a11y":·{·"useValidAriaRole":·"error"·},
64 │ + → → → → → "style":·{
65 │ + → → → → → → "noRestrictedGlobals":·{·"level":·"error",·"options":·{}·},
66 │ + → → → → → → "useConsistentArrayType":·"error",
67 │ + → → → → → → "useFilenamingConvention":·{
68 │ + → → → → → → → "level":·"error",
69 │ + → → → → → → → "options":·{
70 │ + → → → → → → → → "requireAscii":·true,
71 │ + → → → → → → → → "filenameCases":·["kebab-case"]
72 │ + → → → → → → → }
73 │ + → → → → → → },
74 │ + → → → → → → "useNamingConvention":·{
75 │ + → → → → → → → "level":·"error",
76 │ + → → → → → → → "options":·{·"strictCase":·false·}
77 │ + → → → → → → }
78 │ + → → → → → }
79 │ + → → → → }
80 │ + → → → }
81 │ + → → },
82 │ + → → {
83 │ + → → → "include":·["alternative.js"],
84 │ + → → → "linter":·{
85 │ + → → → → "rules":·{
86 │ + → → → → → "style":·{
87 │ + → → → → → → "noRestrictedGlobals":·{
88 │ + → → → → → → → "level":·"error",
89 │ + → → → → → → → "options":·{·"deniedGlobals":·["event",·"fdescribe"]·}
90 │ + → → → → → → },
91 │ + → → → → → → "useConsistentArrayType":·{
92 │ + → → → → → → → "level":·"error",
93 │ + → → → → → → → "options":·{·"syntax":·"shorthand"·}
94 │ + → → → → → → },
95 │ + → → → → → → "useFilenamingConvention":·{
96 │ + → → → → → → → "level":·"error",
97 │ + → → → → → → → "options":·{
98 │ + → → → → → → → → "requireAscii":·true,
99 │ + → → → → → → → → "filenameCases":·["kebab-case"]
100 │ + → → → → → → → }
101 │ + → → → → → → },
102 │ + → → → → → → "useNamingConvention":·{
103 │ + → → → → → → → "level":·"error",
104 │ + → → → → → → → "options":·{
105 │ + → → → → → → → → "strictCase":·false,
106 │ + → → → → → → → → "conventions":·[{·"formats":·["CONSTANT_CASE"]·}]
107 │ + → → → → → → → }
108 │ + → → → → → → }
109 │ + → → → → → }
110 │ + → → → → }
111 │ + → → → }
112 │ + → → }
113 │ + → ]
114 │ + }
115 │ +
```
Expand Down
Loading

0 comments on commit b3da3ae

Please sign in to comment.