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 81fdedb commit cfe66c3
Show file tree
Hide file tree
Showing 3 changed files with 145 additions and 1 deletion.
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;
};
Original file line number Diff line number Diff line change
@@ -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 │ };
```

0 comments on commit cfe66c3

Please sign in to comment.