From d04ab5bc48b5163e5e23251ebb902b612e4e6b64 Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Mon, 7 Oct 2024 14:08:31 +0100 Subject: [PATCH] fix(linter): `useSortedClasses` false positive (#4199) Co-authored-by: Carson McManus --- CHANGELOG.md | 2 ++ .../src/lint/nursery/use_sorted_classes.rs | 3 +++ crates/biome_js_analyze/tests/quick_test.rs | 5 ++--- .../tests/specs/nursery/useSortedClasses/issue_4041.jsx | 1 + .../specs/nursery/useSortedClasses/issue_4041.jsx.snap | 9 +++++++++ 5 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 crates/biome_js_analyze/tests/specs/nursery/useSortedClasses/issue_4041.jsx create mode 100644 crates/biome_js_analyze/tests/specs/nursery/useSortedClasses/issue_4041.jsx.snap diff --git a/CHANGELOG.md b/CHANGELOG.md index e85cdc4079c8..3f133ef2602c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,6 +43,8 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b - Fix [#4190](https://github.com/biomejs/biome/issues/4190), where the rule `noMissingVarFunction` wrongly reported a variable as missing when used inside a `var()` function that was a newline. Contributed by @ematipico +- Fix [#4041](https://github.com/biomejs/biome/issues/4041). Now the rule `useSortedClasses` won't be triggered if `className` is composed only by inlined variables. Contributed by @ematipico + ### Parser #### Bug Fixes diff --git a/crates/biome_js_analyze/src/lint/nursery/use_sorted_classes.rs b/crates/biome_js_analyze/src/lint/nursery/use_sorted_classes.rs index 9d596ff2e189..f24e595c64f3 100644 --- a/crates/biome_js_analyze/src/lint/nursery/use_sorted_classes.rs +++ b/crates/biome_js_analyze/src/lint/nursery/use_sorted_classes.rs @@ -165,6 +165,9 @@ impl Rule for UseSortedClasses { let ignore_postfix = should_ignore_postfix(node); let sorted_value = sort_class_name(&value, &SORT_CONFIG, ignore_prefix, ignore_postfix); + if sorted_value.is_empty() { + return None; + } if value.text() != sorted_value { return Some(sorted_value); } diff --git a/crates/biome_js_analyze/tests/quick_test.rs b/crates/biome_js_analyze/tests/quick_test.rs index 3da9ec568628..5ff05a2ad6cb 100644 --- a/crates/biome_js_analyze/tests/quick_test.rs +++ b/crates/biome_js_analyze/tests/quick_test.rs @@ -13,9 +13,8 @@ use std::{ffi::OsStr, fs::read_to_string, path::Path, slice}; // use this test check if your snippet produces the diagnostics you wish, without using a snapshot #[ignore] #[test] -fn run_test() { - let input_file = - Path::new("tests/specs/correctness/useExhaustiveDependencies/ignoredDependencies.js"); +fn quick_test() { + let input_file = Path::new("tests/specs/nursery/useSortedClasses/issue.jsx"); let file_name = input_file.file_name().and_then(OsStr::to_str).unwrap(); let (group, rule) = parse_test_path(input_file); diff --git a/crates/biome_js_analyze/tests/specs/nursery/useSortedClasses/issue_4041.jsx b/crates/biome_js_analyze/tests/specs/nursery/useSortedClasses/issue_4041.jsx new file mode 100644 index 000000000000..2983f707b47b --- /dev/null +++ b/crates/biome_js_analyze/tests/specs/nursery/useSortedClasses/issue_4041.jsx @@ -0,0 +1 @@ +
diff --git a/crates/biome_js_analyze/tests/specs/nursery/useSortedClasses/issue_4041.jsx.snap b/crates/biome_js_analyze/tests/specs/nursery/useSortedClasses/issue_4041.jsx.snap new file mode 100644 index 000000000000..6852ac4f2f56 --- /dev/null +++ b/crates/biome_js_analyze/tests/specs/nursery/useSortedClasses/issue_4041.jsx.snap @@ -0,0 +1,9 @@ +--- +source: crates/biome_js_analyze/tests/spec_tests.rs +expression: issue_4041.jsx +--- +# Input +```jsx +
+ +```