Skip to content

Commit

Permalink
fix(migrate-eslint): corretcly handle scoped package with paths (#4435)
Browse files Browse the repository at this point in the history
  • Loading branch information
Conaclos authored Oct 30, 2024
1 parent d2b3b7f commit 4713c52
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b

### CLI

#### Bug fixes

- `biome migrate eslint` now correctly resolves scoped package named `eslint-config` with a path.
Contributed by @Conaclos

### Configuration

### Editors
Expand Down
52 changes: 48 additions & 4 deletions crates/biome_cli/src/execute/migrate/eslint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,12 +377,13 @@ impl EslintPackage {
EslintPackage::Plugin => "eslint-plugin-",
};
if name.starts_with('@') {
// handle scoped module
if let Some((scope, scoped)) = name.split_once('/') {
if scoped.starts_with(artifact) || scoped == artifact.trim_end_matches('-') {
// handle scoped package
if let Some((scope, rest)) = name.split_once('/') {
let package = rest.split('/').next().unwrap_or(rest);
if rest.starts_with(artifact) || package == artifact.trim_end_matches('-') {
Cow::Borrowed(name)
} else {
Cow::Owned(format!("{scope}/{artifact}{scoped}"))
Cow::Owned(format!("{scope}/{artifact}{rest}"))
}
} else {
let artifact = artifact.trim_end_matches('-');
Expand All @@ -395,3 +396,46 @@ impl EslintPackage {
}
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn eslint_package_resolve_name() {
assert_eq!(
EslintPackage::Config.resolve_name("@scope/package"),
"@scope/eslint-config-package"
);
assert_eq!(
EslintPackage::Config.resolve_name("@scope/eslint-config-package"),
"@scope/eslint-config-package"
);
assert_eq!(
EslintPackage::Config.resolve_name("@scope/eslint-config"),
"@scope/eslint-config"
);

assert_eq!(
EslintPackage::Config.resolve_name("@scope/package/path"),
"@scope/eslint-config-package/path"
);
assert_eq!(
EslintPackage::Config.resolve_name("@scope/eslint-config-package/path"),
"@scope/eslint-config-package/path"
);
assert_eq!(
EslintPackage::Config.resolve_name("@scope/eslint-config/path"),
"@scope/eslint-config/path"
);

assert_eq!(
EslintPackage::Config.resolve_name("package"),
"eslint-config-package"
);
assert_eq!(
EslintPackage::Config.resolve_name("eslint-config-package"),
"eslint-config-package"
);
}
}

0 comments on commit 4713c52

Please sign in to comment.