Skip to content

Commit

Permalink
refcator(migrate/eslint): improve naing-convention migration
Browse files Browse the repository at this point in the history
  • Loading branch information
Conaclos committed May 24, 2024
1 parent a51ef9d commit cc8cb2f
Show file tree
Hide file tree
Showing 10 changed files with 828 additions and 279 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_eslint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ pub(crate) struct OverrideConfigData {
pub(crate) rules: Rules,
}

#[derive(Debug, Default)]
#[derive(Debug, Default, Eq, PartialEq)]
pub(crate) struct ShorthandVec<T>(Vec<T>);
impl<T> Merge for ShorthandVec<T> {
fn merge_with(&mut self, mut other: Self) {
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
593 changes: 485 additions & 108 deletions crates/biome_cli/src/execute/migrate/eslint_typescript.rs

Large diffs are not rendered by default.

20 changes: 19 additions & 1 deletion 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 @@ -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 @@ -72,101 +91,144 @@ expression: content

# Emitted Messages

```block
.eslintrc.json:30:21 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
× Property key must be double quoted
28 │ {
29 │ "selector": "variable",
> 30 │ types: ['boolean'],
│ ^^^^^
31 │ "format": ["UPPER_CASE"]
32 │ }
```

```block
.eslintrc.json:30:29 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
× JSON standard does not allow single quoted strings
28 │ {
29 │ "selector": "variable",
> 30 │ types: ['boolean'],
│ ^^^^^^^^^
31 │ "format": ["UPPER_CASE"]
32 │ }
i Use double quotes to escape the string.
```

```block
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 │ + → → → → → → ]
38 │ + → → → → → }
39 │ + → → → → }
40 │ + → → → }
41 │ + → → }
42 │ + → },
43 │ + → "overrides":·[
44 │ + → → {
45 │ + → → → "include":·["default.js"],
46 │ + → → → "linter":·{
47 │ + → → → → "rules":·{
48 │ + → → → → → "a11y":·{·"useValidAriaRole":·"error"·},
49 │ + → → → → → "style":·{
50 │ + → → → → → → "noRestrictedGlobals":·{·"level":·"error",·"options":·{}·},
51 │ + → → → → → → "useConsistentArrayType":·"error",
52 │ + → → → → → → "useFilenamingConvention":·{
53 │ + → → → → → → → "level":·"error",
54 │ + → → → → → → → "options":·{
55 │ + → → → → → → → → "requireAscii":·true,
56 │ + → → → → → → → → "filenameCases":·["kebab-case"]
57 │ + → → → → → → → }
58 │ + → → → → → → },
59 │ + → → → → → → "useNamingConvention":·{
60 │ + → → → → → → → "level":·"error",
61 │ + → → → → → → → "options":·{·"strictCase":·false·}
62 │ + → → → → → → }
63 │ + → → → → → }
64 │ + → → → → }
65 │ + → → → }
66 │ + → → },
67 │ + → → {
68 │ + → → → "include":·["alternative.js"],
69 │ + → → → "linter":·{
70 │ + → → → → "rules":·{
71 │ + → → → → → "style":·{
72 │ + → → → → → → "noRestrictedGlobals":·{
73 │ + → → → → → → → "level":·"error",
74 │ + → → → → → → → "options":·{·"deniedGlobals":·["event",·"fdescribe"]·}
75 │ + → → → → → → },
76 │ + → → → → → → "useConsistentArrayType":·{
77 │ + → → → → → → → "level":·"error",
78 │ + → → → → → → → "options":·{·"syntax":·"shorthand"·}
79 │ + → → → → → → },
80 │ + → → → → → → "useFilenamingConvention":·{
81 │ + → → → → → → → "level":·"error",
82 │ + → → → → → → → "options":·{
83 │ + → → → → → → → → "requireAscii":·true,
84 │ + → → → → → → → → "filenameCases":·["kebab-case"]
85 │ + → → → → → → → }
86 │ + → → → → → → },
87 │ + → → → → → → "useNamingConvention":·{
88 │ + → → → → → → → "level":·"error",
89 │ + → → → → → → → "options":·{
90 │ + → → → → → → → → "strictCase":·false,
91 │ + → → → → → → → → "conventions":·[{·"formats":·["CONSTANT_CASE"]·}]
92 │ + → → → → → → → }
93 │ + → → → → → → }
94 │ + → → → → → }
95 │ + → → → → }
96 │ + → → → }
97 │ + → → }
98 │ + → ]
99 │ + }
100 │ +
```
Expand Down
Loading

0 comments on commit cc8cb2f

Please sign in to comment.