From dd8cbe50c907cf7a785cb059d1fdee1bf7259cc8 Mon Sep 17 00:00:00 2001 From: Victorien Elvinger Date: Thu, 19 Oct 2023 12:06:32 +0200 Subject: [PATCH] fix(lint/noSelfAssign): don't panic --- CHANGELOG.md | 4 ++++ .../src/analyzers/correctness/no_self_assign.rs | 4 ++-- .../tests/specs/correctness/noSelfAssign/issue548.js | 2 ++ .../specs/correctness/noSelfAssign/issue548.js.snap | 11 +++++++++++ website/src/content/docs/internals/changelog.mdx | 4 ++++ 5 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 crates/biome_js_analyze/tests/specs/correctness/noSelfAssign/issue548.js create mode 100644 crates/biome_js_analyze/tests/specs/correctness/noSelfAssign/issue548.js.snap diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c3801ddc93e..718fa5f4a13b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,10 @@ Read our [guidelines for writing a good changelog entry](https://github.com/biom ### Linter +#### Bug fixes + +- Fix [#548](https://github.com/biomejs/biome/issues/548) which made [noSelfAssign](https://biomejs.dev/linter/rules/no-self-assign) panic. + ### Parser ### VSCode diff --git a/crates/biome_js_analyze/src/analyzers/correctness/no_self_assign.rs b/crates/biome_js_analyze/src/analyzers/correctness/no_self_assign.rs index 64e6c351f583..e22b562a8a76 100644 --- a/crates/biome_js_analyze/src/analyzers/correctness/no_self_assign.rs +++ b/crates/biome_js_analyze/src/analyzers/correctness/no_self_assign.rs @@ -690,7 +690,7 @@ pub(crate) enum IdentifiersLike { } impl TryFrom<(AnyNameLike, AnyNameLike)> for IdentifiersLike { - type Error = SyntaxError; + type Error = (); fn try_from((left, right): (AnyNameLike, AnyNameLike)) -> Result { match (left, right) { @@ -713,7 +713,7 @@ impl TryFrom<(AnyNameLike, AnyNameLike)> for IdentifiersLike { AnyNameLike::AnyJsLiteralExpression(right), ) => Ok(Self::Literal(left, right)), - _ => unreachable!("you should map the correct references"), + _ => Err(()), } } } diff --git a/crates/biome_js_analyze/tests/specs/correctness/noSelfAssign/issue548.js b/crates/biome_js_analyze/tests/specs/correctness/noSelfAssign/issue548.js new file mode 100644 index 000000000000..a36f5369ba9e --- /dev/null +++ b/crates/biome_js_analyze/tests/specs/correctness/noSelfAssign/issue548.js @@ -0,0 +1,2 @@ +// See https://github.com/biomejs/biome/issues/548 +a[c] = b[0]; \ No newline at end of file diff --git a/crates/biome_js_analyze/tests/specs/correctness/noSelfAssign/issue548.js.snap b/crates/biome_js_analyze/tests/specs/correctness/noSelfAssign/issue548.js.snap new file mode 100644 index 000000000000..127a972a6f34 --- /dev/null +++ b/crates/biome_js_analyze/tests/specs/correctness/noSelfAssign/issue548.js.snap @@ -0,0 +1,11 @@ +--- +source: crates/biome_js_analyze/tests/spec_tests.rs +expression: issue548.js +--- +# Input +```js +// See https://github.com/biomejs/biome/issues/548 +a[c] = b[0]; +``` + + diff --git a/website/src/content/docs/internals/changelog.mdx b/website/src/content/docs/internals/changelog.mdx index 46287aec6941..302d8bf494af 100644 --- a/website/src/content/docs/internals/changelog.mdx +++ b/website/src/content/docs/internals/changelog.mdx @@ -30,6 +30,10 @@ Read our [guidelines for writing a good changelog entry](https://github.com/biom ### Linter +#### Bug fixes + +- Fix [#548](https://github.com/biomejs/biome/issues/548) which made [noSelfAssign](https://biomejs.dev/linter/rules/no-self-assign) panic. + ### Parser ### VSCode