diff --git a/crates/biome_js_analyze/tests/quick_test.rs b/crates/biome_js_analyze/tests/quick_test.rs index 901aa8a2885c..6c752d520c5f 100644 --- a/crates/biome_js_analyze/tests/quick_test.rs +++ b/crates/biome_js_analyze/tests/quick_test.rs @@ -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); diff --git a/crates/biome_js_analyze/tests/specs/complexity/useArrowFunction/suppressionComments.ts b/crates/biome_js_analyze/tests/specs/complexity/useArrowFunction/suppressionComments.ts new file mode 100644 index 000000000000..1c9dbf2bde9b --- /dev/null +++ b/crates/biome_js_analyze/tests/specs/complexity/useArrowFunction/suppressionComments.ts @@ -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; +}; \ No newline at end of file diff --git a/crates/biome_js_analyze/tests/specs/complexity/useArrowFunction/suppressionComments.ts.snap b/crates/biome_js_analyze/tests/specs/complexity/useArrowFunction/suppressionComments.ts.snap new file mode 100644 index 000000000000..43742d4cac5d --- /dev/null +++ b/crates/biome_js_analyze/tests/specs/complexity/useArrowFunction/suppressionComments.ts.snap @@ -0,0 +1,133 @@ +--- +source: crates/biome_js_analyze/tests/spec_tests.rs +expression: suppressionComments.ts +snapshot_kind: text +--- +# Input +```ts +// 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; +}; +``` + +# Diagnostics +``` +suppressionComments.ts:2:14 lint/complexity/useArrowFunction FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + ! This function expression can be turned into an arrow function. + + 1 │ // biome-ignore lint/complexity/useArrowFunction: work + > 2 │ const foo0 = function (bar: string) { + │ ^^^^^^^^^^^^^^^^^^^^^^^^ + > 3 │ // biome-ignore lint/style/noParameterAssign: allow + > 4 │ bar = "baz"; + > 5 │ }; + │ ^ + 6 │ + 7 │ // biome-ignore lint/complexity/useArrowFunction: work + + i Function expressions that don't use this can be turned into arrow functions. + + i Safe fix: Use an arrow function instead. + + 1 1 │ // biome-ignore lint/complexity/useArrowFunction: work + 2 │ - const·foo0·=·function·(bar:·string)·{ + 2 │ + const·foo0·=·(bar:·string)·=>·{ + 3 3 │ // biome-ignore lint/style/noParameterAssign: allow + 4 4 │ bar = "baz"; + + +``` + +``` +suppressionComments.ts:8:14 lint/complexity/useArrowFunction FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + ! This function expression can be turned into an arrow function. + + 7 │ // biome-ignore lint/complexity/useArrowFunction: work + > 8 │ const foo1 = function () { + │ ^^^^^^^^^^^^^ + > 9 │ // biome-ignore lint/suspicious/noExplicitAny: work + > 10 │ let bar: any; + > 11 │ }; + │ ^ + + i Function expressions that don't use this can be turned into arrow functions. + + i Safe fix: Use an arrow function instead. + + 6 6 │ + 7 7 │ // biome-ignore lint/complexity/useArrowFunction: work + 8 │ - const·foo1·=·function·()·{ + 8 │ + const·foo1·=·()·=>·{ + 9 9 │ // biome-ignore lint/suspicious/noExplicitAny: work + 10 10 │ let bar: any; + + +``` + +``` +suppressionComments.ts:1:1 suppressions/unused ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + ! Suppression comment has no effect. Remove the suppression or make sure you are suppressing the correct rule. + + > 1 │ // biome-ignore lint/complexity/useArrowFunction: work + │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 2 │ const foo0 = function (bar: string) { + 3 │ // biome-ignore lint/style/noParameterAssign: allow + + +``` + +``` +suppressionComments.ts:3:2 suppressions/unused ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + ! Suppression comment has no effect. Remove the suppression or make sure you are suppressing the correct rule. + + 1 │ // biome-ignore lint/complexity/useArrowFunction: work + 2 │ const foo0 = function (bar: string) { + > 3 │ // biome-ignore lint/style/noParameterAssign: allow + │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 4 │ bar = "baz"; + 5 │ }; + + +``` + +``` +suppressionComments.ts:7:1 suppressions/unused ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + ! Suppression comment has no effect. Remove the suppression or make sure you are suppressing the correct rule. + + 5 │ }; + 6 │ + > 7 │ // biome-ignore lint/complexity/useArrowFunction: work + │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 8 │ const foo1 = function () { + 9 │ // biome-ignore lint/suspicious/noExplicitAny: work + + +``` + +``` +suppressionComments.ts:9:5 suppressions/unused ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + ! Suppression comment has no effect. Remove the suppression or make sure you are suppressing the correct rule. + + 7 │ // biome-ignore lint/complexity/useArrowFunction: work + 8 │ const foo1 = function () { + > 9 │ // biome-ignore lint/suspicious/noExplicitAny: work + │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 10 │ let bar: any; + 11 │ }; + + +```