dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.11k stars 1.57k forks source link

Feature Request: Add `--insert-ignore-comments` flag to `dart fix` command for existing code #56098

Open ishchhabra opened 3 months ago

ishchhabra commented 3 months ago

This tracker is for issues related to:

Description

As the language grows, we often introduce new lint rules to maintain and improve code quality. However, introducing new lint rules to large existing codebases can be challenging, especially when the rules are not auto-fixable. A common approach is to simply ignore the new lint rules for existing, working code and focus on ensuring the new code adheres to these rules.

Currently, this process requires developers to manually add ignore comments to existing code or write custom scripts to automate this task.

To streamline this process, a new --insert-ignore-comments flag can be added to dart fix command. This flag will only apply to lint rules that do not have an automatic fix and will allow developers to focus on improving new code without the immediate need to refactor legacy code.

I have created a quick (functional but with errors after it adds comments) prototype to demonstrate this idea. In case this is something that the Dart team agrees could be a valid feature, I'd love to contribute. I would love to learn the thoughts and opinions of the Dart team.

dart-github-bot commented 3 months ago

Summary: The user proposes adding a --insert-ignore-comments flag to the dart fix command. This flag would automatically add ignore comments to existing code for new lint rules, allowing developers to focus on fixing new code without immediately refactoring legacy code.

lrhn commented 3 months ago

This "fix" should probably only apply for lints that don't have an automatic fix.

ishchhabra commented 3 months ago

This "fix" should probably only apply for lints that don't have an automatic fix.

Yep, agreed. That was the intention behind the proposal. I have updated the description to mention that this flag will only apply to lint rules that do not have an automatic fix.