Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Suppress rule" quickfix removes indentation #1697

Closed
fmajestic opened this issue Jan 28, 2024 · 1 comment · Fixed by #1747
Closed

"Suppress rule" quickfix removes indentation #1697

fmajestic opened this issue Jan 28, 2024 · 1 comment · Fixed by #1747
Labels
A-Linter Area: linter S-Enhancement Status: Improve an existing feature S-Help-wanted Status: you're familiar with the code base and want to help the project

Comments

@fmajestic
Copy link

Biome version 1.5.3
VSCode version 1.85.2
Extension version 2.1.2

Steps:

  1. Enable lint/suspicious/noAssignInExpressions and lint/suspicious/noConsoleLog.

  2. Code

    // file.ts
    export function foo() {
      let x: number;
      while ((x = Math.random()) > 0.1) {
        console.log(x);
      }
    }
  3. Apply quickfix

    • To assignment (notice the two spaces after while too):

      export function foo() {
        let x: number;
        // biome-ignore lint/suspicious/noAssignInExpressions: <explanation>
      while  ((x = Math.random()) > 0.1) {
          console.log(x);
        }
        return numbers;
      }
    • To console.log:

      export function foo() {
        let x: number;
        while ((x = Math.random()) > 0.1) {
          // biome-ignore lint/suspicious/noConsoleLog: <explanation>
      console.log(x);
        }
      }
@nhedger nhedger transferred this issue from biomejs/biome-vscode Jan 29, 2024
@ematipico ematipico added S-Help-wanted Status: you're familiar with the code base and want to help the project A-Linter Area: linter S-Enhancement Status: Improve an existing feature labels Jan 29, 2024
@ematipico
Copy link
Member

For anyone who wants to help with this issue, the code to fix the issue should be here:

let mut new_token = token_to_apply_suppression.clone();
if !should_insert_leading_newline {
if token_has_trailing_comments {
new_token = new_token.with_trailing_trivia([
(TriviaPieceKind::Newline, "\n"),
(
TriviaPieceKind::SingleLineComment,
format!("// {}: <explanation>", suppression_text).as_str(),
),
(TriviaPieceKind::Newline, "\n"),
])
} else {
new_token = new_token.with_leading_trivia([
(TriviaPieceKind::Newline, "\n"),
(
TriviaPieceKind::SingleLineComment,
format!("// {}: <explanation>", suppression_text).as_str(),
),
(TriviaPieceKind::Newline, "\n"),
])
}
} else if token_has_trailing_comments {
new_token = new_token.with_trailing_trivia([
(
TriviaPieceKind::SingleLineComment,
format!("// {}: <explanation>", suppression_text).as_str(),
),
(TriviaPieceKind::Newline, "\n"),
])
} else {
new_token = new_token.with_leading_trivia([
(
TriviaPieceKind::SingleLineComment,
format!("// {}: <explanation>", suppression_text).as_str(),
),
(TriviaPieceKind::Newline, "\n"),
])
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Linter Area: linter S-Enhancement Status: Improve an existing feature S-Help-wanted Status: you're familiar with the code base and want to help the project
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants