Skip to content

"Use curly braces" quick fix removes comment before the expression guearded by if statement #4440

@kpsroka

Description

@kpsroka

Describe the bug
If a comment precedes expression guarded by if statement without curly braces, the "Use curly braces" quick fix removes the comment.

To Reproduce

  1. Make sure curly_braces_in_flow_control_structures lint rule is enforced
  2. Insert the following code:
if (identical(true, false))
  // This is a nice comment.
  throw Exception();
  1. Open quick fixes suggestions in VSCode at the if statement line.
  2. Apply "Use curly braces" fix.

The resulting code is

if (identical(true, false)) {
  throw Exception();
}

Expected behavior
The resulting code should be:

if (identical(true, false)) {
  // This is a nice comment.
  throw Exception();
}

Please complete the following information:

  • Operating System and version: MacOS 13.1 (Ventura)
  • VS Code version: 1.76.1 (Universal)
  • Dart extension version: v3.60.1
  • Dart/Flutter SDK version: 2.19.2 / 3.7.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    in editorRelates to code editing or language featuresin lsp/analysis serverSomething to be fixed in the Dart analysis serveris bugrelies on sdk changesSomething that requires changes in the Dart/Flutter SDK to ship before it will become available

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions