sdk icon indicating copy to clipboard operation
sdk copied to clipboard

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

Open ishchhabra opened this issue 1 year ago • 1 comments
trafficstars

This tracker is for issues related to:

  • Dart analyzer and linter

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 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.

ishchhabra avatar Jun 27 '24 17:06 ishchhabra

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.

dart-github-bot avatar Jun 27 '24 17:06 dart-github-bot

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

lrhn avatar Jul 01 '24 07:07 lrhn

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.

ishchhabra avatar Jul 01 '24 08:07 ishchhabra