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.

Refactoring to extract final variable

See original GitHub issue

In our code base we prefer to have all variables with final modifier. It would be super helpful if Extract local variable would add final with every refactoring.

  • Add vscode preference for Extract local variable or
  • Add separate refactoring Extract final variable

Thought I am not sure how to achieve this in most elegant way without overfilling refactoring menu with similar options or adding very rarely used preference. 😃

In Intellij it is possible to add options for refactoring 😃 image

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
DanTupcommented, Sep 2, 2019

The SDK was updated to use final when the prefer_final_locals lint is enabled so this should just start working for you in an upcoming release 👍

1reaction
pqcommented, Aug 28, 2019

there’s this lint which I think is only fields, but having a similar one for local variable

That’s actually already implemented! (see: prefer_final_locals.)

As for the initial ask, we could accomplish this if we considered project lint settings when doing refactorings. I’m not sure there’s a precedent but definitely worth discussing.

Opened https://github.com/dart-lang/sdk/issues/38081 to track. 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

Extract Variable - Refactoring.Guru
How to Refactor · Insert a new line before the relevant expression and declare a new variable there. Assign part of the complex...
Read more >
Refactoring: Extract Variable in IntelliJ IDEA - The JetBrains Blog
The Extract Variable refactoring lets you simplify an expression and remove its redundant parts. If an expression is hard to understand or it...
Read more >
Refactoring: Extract a local variable Be careful!
Choose menu item Refactor -> Extract local variable. This causes this window to pop up: We already typed in a name for the...
Read more >
Extract Variable - Refactoring
const basePrice = order.quantity * order.itemPrice; const quantityDiscount = Math.max(0, order.quantity - 500) * order.itemPrice * 0.05; const shipping ...
Read more >
Refactoring source code in Visual Studio Code
Source code fragments can be extracted into a new method, or into a new function at various different scopes. During the extract refactoring,...
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