question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"Add curly braces" does not appear as a Quick-fix for always_put_control_body_on_new_line

See original GitHub issue

Describe the bug

Single quick fixes don’t always appear. In this case, for always_put_control_body_on_new_line.

✅ Inline lightbulb ✅ <kbd>cmd</kbd><kbd>.</kbd> ❌ Hovercard ⇒ click “Quick fix”

https://user-images.githubusercontent.com/6655696/169700652-c421d922-da30-47fe-a2e1-61cd0ef09cb7.mp4

❌ lightbulb in Problems panel Screen Shot 2022-05-22 at 16 32 14 1

  • VS Code version: Version: 1.67.2 (Universal)
  • Dart Code extension: 3.40.0
  • Flutter extension: 3.41.20220516 (activated)

There seems to be a separate issue for multi-fixes (“everywhere in this file”) that also applies to Android Studio, so filed https://github.com/dart-lang/sdk/issues/49079.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
DanTupcommented, May 30, 2022

With https://github.com/dart-lang/sdk/commit/20b7de7b570afd582f8c7d3a58d182acfb01bda6, the “Add Curly Braces” fix will now show up as a fix for this lint:

Screenshot 2022-05-30 at 13 51 41

It won’t be applied by dart fix (because I don’t think it’s clearly the correct fix for this lint, which is about newlines and not braces).

Although, while testing this I realised that curly_braces_in_flow_control_structures doesn’t cover things on a single line, so if your code is:

if (true) print('');

Then enabling both lints still won’t get dart fix to do what you want. I think the solution to that is probably a new fix for always_put_control_body_on_new_line that inserts a newline, then the example above could be dart fixable, without conflating the lints (eg. not assuming people with always_put_control_body_on_new_line want braces, or people with curly_braces_in_flow_control_structures want everything split across lines).

There’s already an issue covering this at https://github.com/dart-lang/sdk/issues/47956, although there’s a slight complication because of conflicts with the formatter.

1reaction
DanTupcommented, May 24, 2022

Re-reading this lint, I’m now wondering whether the “Add curly braces” fix is the obvious fix here. The lint isn’t about using curly braces, but rather about having the code on a new line.

If you’re using the formatter, then these things are quite tied together, but if you’re not using the formatter you might expect a fix for “move the body to a new line” rather than adding curly braces.

There is another lint named curly_braces_in_flow_control_structures that I believe does what you want - it generates a similar warning but it does provide “add curly braces” as a fix.

Does it make more sense for you to enable curly_braces_in_flow_control_structures is curly braces is what you really want?

(cc @bwilkerson for his thoughts on whether “Use curly braces” is a reasonable fix also for “always_put_control_body_on_new_line”)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using StandardJS, getting error for curly brace on wrong line ...
Like the error says, you need to put the closing curly brace on the same line as the subsequent block after the else...
Read more >
IDE0011: Add braces - .NET - Microsoft Learn
Use the following option to specify whether curly braces are preferred or not, and if preferred, whether only for multi-line code blocks.
Read more >
Code Syntax Style: Braces for Single Nested Statements
JetBrains Rider highlights code that do not comply with your preferences and suggests the corresponding quick-fix or fix in scope.
Read more >
curly brackets in GUID - Esri Community
Hi, When importing data from a PostgreSQL database into ArcGIS Pro, the UUID from PostgreSQL are transformed into GUIDs, and for some reason ......
Read more >
Direct Query adding curly brackets to Test GUID Field
Direct Query adding curly brackets to Test GUID Field ... When I go to Edit Query I dont see the Brackets. But in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found