Skip to content

Commit

Permalink
fix(migrate-eslint): allow null in file lists (#4749)
Browse files Browse the repository at this point in the history
  • Loading branch information
Conaclos authored Dec 16, 2024
1 parent 8cd13d6 commit 5f61826
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 17 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b

Contributed by @Conaclos

- `biome migrate eslint` now correctly handles ESLint configuration with `null` values in file lists ([#4740](https://github.com/biomejs/biome/issues/4740)).
Contributed by @Conaclos

### Configuration

### Editors
Expand Down
18 changes: 14 additions & 4 deletions crates/biome_cli/src/execute/migrate/eslint_eslint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ pub(crate) struct FlatConfigData(pub(crate) Vec<FlatConfigObject>);
#[derive(Debug, Default, Deserializable)]
#[deserializable(unknown_fields = "allow")]
pub(crate) struct FlatConfigObject {
pub(crate) files: Vec<String>,
pub(crate) files: ShorthandVec<String>,
/// The glob patterns that ignore to lint.
pub(crate) ignores: Vec<String>,
pub(crate) ignores: ShorthandVec<String>,
// using `Option` is important to distinguish a global ignores from a config objerct
pub(crate) language_options: Option<FlatLanguageOptions>,
// using `Option` is important to distinguish a global ignores from a config objerct
Expand Down Expand Up @@ -240,6 +240,11 @@ impl<T> DerefMut for ShorthandVec<T> {
&mut self.0
}
}
impl<T> FromIterator<T> for ShorthandVec<T> {
fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self {
Self(iter.into_iter().collect())
}
}
impl<T> IntoIterator for ShorthandVec<T> {
type Item = T;
type IntoIter = vec::IntoIter<T>;
Expand All @@ -255,9 +260,14 @@ impl<T: Deserializable> Deserializable for ShorthandVec<T> {
) -> Option<Self> {
Some(ShorthandVec(
if value.visitable_type()? == DeserializableType::Array {
Deserializable::deserialize(value, name, diagnostics)?
<Vec<Option<T>>>::deserialize(value, name, diagnostics)?
.into_iter()
.flatten()
.collect()
} else {
Vec::from_iter([Deserializable::deserialize(value, name, diagnostics)?])
<Option<T>>::deserialize(value, name, diagnostics)?
.into_iter()
.collect()
},
))
}
Expand Down
20 changes: 10 additions & 10 deletions crates/biome_cli/src/execute/migrate/eslint_to_biome.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,8 @@ mod tests {
#[test]
fn flat_config_single_config_object() {
let flat_config = FlatConfigData(vec![FlatConfigObject {
files: vec!["*.js".to_string()],
ignores: vec!["*.test.js".to_string()],
files: ["*.js".to_string()].into_iter().collect(),
ignores: ["*.test.js".to_string()].into_iter().collect(),
language_options: None,
rules: Some(Rules(
[Rule::Any(Cow::Borrowed("eqeqeq"), Severity::Error)]
Expand Down Expand Up @@ -354,14 +354,14 @@ mod tests {
fn flat_config_multiple_config_object() {
let flat_config = FlatConfigData(vec![
FlatConfigObject {
files: vec![],
ignores: vec!["*.test.js".to_string()],
files: ShorthandVec::default(),
ignores: ["*.test.js".to_string()].into_iter().collect(),
language_options: None,
rules: None,
},
FlatConfigObject {
files: vec![],
ignores: vec![],
files: ShorthandVec::default(),
ignores: ShorthandVec::default(),
language_options: None,
rules: Some(Rules(
[Rule::Any(Cow::Borrowed("eqeqeq"), Severity::Error)]
Expand All @@ -370,14 +370,14 @@ mod tests {
)),
},
FlatConfigObject {
files: vec![],
ignores: vec!["*.spec.js".to_string()],
files: ShorthandVec::default(),
ignores: ["*.spec.js".to_string()].into_iter().collect(),
language_options: None,
rules: None,
},
FlatConfigObject {
files: vec!["*.ts".to_string()],
ignores: vec![],
files: ["*.ts".to_string()].into_iter().collect(),
ignores: ShorthandVec::default(),
language_options: None,
rules: Some(Rules(
[Rule::Any(Cow::Borrowed("eqeqeq"), Severity::Off)]
Expand Down
2 changes: 1 addition & 1 deletion crates/biome_cli/tests/commands/migrate_eslint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ fn migrate_merge_with_overrides() {
}"#;
let eslintrc = r#"{
"overrides": [{
"files": ["bin/*.js", "lib/*.js"],
"files": ["bin/*.js", "lib/*.js", null],
"excludedFiles": "*.test.js",
"rules": {
"eqeqeq": ["off"]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
source: crates/biome_cli/tests/snap_test.rs
expression: content
snapshot_kind: text
---
## `biome.json`

Expand All @@ -20,7 +21,7 @@ expression: content
```json
{
"overrides": [{
"files": ["bin/*.js", "lib/*.js"],
"files": ["bin/*.js", "lib/*.js", null],
"excludedFiles": "*.test.js",
"rules": {
"eqeqeq": ["off"]
Expand Down
6 changes: 5 additions & 1 deletion crates/biome_deserialize/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,11 @@ impl<T: Deserializable> Deserializable for Option<T> {
name: &str,
diagnostics: &mut Vec<DeserializationDiagnostic>,
) -> Option<Self> {
T::deserialize(value, name, diagnostics).map(Option::Some)
if value.visitable_type() == Some(crate::DeserializableType::Null) {
None
} else {
T::deserialize(value, name, diagnostics).map(Option::Some)
}
}
}

Expand Down

0 comments on commit 5f61826

Please sign in to comment.