Skip to content

Commit

Permalink
fix(analyzer): suppression comment fails with inner comments in funct…
Browse files Browse the repository at this point in the history
…ions
  • Loading branch information
fireairforce committed Nov 26, 2024
1 parent bf0774f commit c50e0de
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 45 deletions.
50 changes: 6 additions & 44 deletions crates/biome_js_analyze/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ where
let mut result = Vec::new();

for comment in parse_suppression_comment(text) {
println!("comment111: {:?}", comment);
let categories = match comment {
Ok(comment) => {
if comment.is_legacy {
Expand Down Expand Up @@ -239,50 +240,11 @@ mod tests {
#[test]
fn suppression() {
const SOURCE: &str = "
function checkSuppressions1(a, b) {
a == b;
// biome-ignore lint/suspicious:whole group
a == b;
// biome-ignore lint/suspicious/noDoubleEquals: single rule
a == b;
/* biome-ignore lint/style/useWhile: multiple block comments */ /* biome-ignore lint/suspicious/noDoubleEquals: multiple block comments */
a == b;
// biome-ignore lint/style/useWhile: multiple line comments
// biome-ignore lint/suspicious/noDoubleEquals: multiple line comments
a == b;
a == b;
}
// biome-ignore lint/suspicious/noDoubleEquals: do not suppress warning for the whole function
function checkSuppressions2(a, b) {
a == b;
}
function checkSuppressions3(a, b) {
a == b;
// rome-ignore lint/suspicious: whole group
a == b;
// rome-ignore lint/suspicious/noDoubleEquals: single rule
a == b;
/* rome-ignore lint/style/useWhile: multiple block comments */ /* rome-ignore lint(suspicious/noDoubleEquals): multiple block comments */
a == b;
// rome-ignore lint/style/useWhile: multiple line comments
// rome-ignore lint/suspicious/noDoubleEquals: multiple line comments
a == b;
a == b;
}
// biome-ignore lint(suspicious/noDoubleEquals): do not suppress warning for the whole function
function checkSuppressions4(a, b) {
a == b;
}
function checkSuppressions5() {
// biome-ignore format explanation
// biome-ignore format(:
// biome-ignore (value): explanation
// biome-ignore unknown: explanation
}
// biome-ignore lint/complexity/useArrowFunction: This comment does not work with an inner comment in the function
const foo0 = function (bar: string) {
// biome-ignore lint/style/noParameterAssign: This comment works
bar = "baz";
};
";
let parsed = parse(
Expand Down
2 changes: 1 addition & 1 deletion crates/biome_js_analyze/tests/quick_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use std::{ffi::OsStr, fs::read_to_string, path::Path, slice};
#[ignore]
#[test]
fn quick_test() {
let input_file = Path::new("tests/specs/a11y/noAutofocus/invalid.jsx");
let input_file = Path::new("tests/specs/complexity/useArrowFunction/suppressionComments.ts");
let file_name = input_file.file_name().and_then(OsStr::to_str).unwrap();

let (group, rule) = parse_test_path(input_file);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// biome-ignore lint/complexity/useArrowFunction: work
const foo0 = function (bar: string) {
// biome-ignore lint/style/noParameterAssign: allow
bar = "baz";
};

// biome-ignore lint/complexity/useArrowFunction: work
const foo1 = function () {
// biome-ignore lint/suspicious/noExplicitAny: work
let bar: any;
};

0 comments on commit c50e0de

Please sign in to comment.