dart-lang / linter

Linter for Dart.
https://dart.dev/tools/linter-rules
BSD 3-Clause "New" or "Revised" License
628 stars 170 forks source link

proposal: `unused_ignore` #4830

Open rrousselGit opened 9 months ago

rrousselGit commented 9 months ago

unused_ignore

Description

An // ignore: code line was defined, but it isn't actually ignoring anything

Details

When dealing with // ignore, it is possible that the issue disappears but the // ignore stays.

Kind

warning

Bad Examples

If the ignored code is a known lint code, warn if the next line doesn't have this warning:

// ignore: unused_import
import 'dart:math';

void main() {
  min(0 ,1); // math is used
}

Good Examples

// ignore: unused_import
import 'dart:math'; // The import is correctly unused

We also shouldn't warn if the code is not recognised by the SDK:

// ignore: unknown_code

This avoids false positives if:

Discussion

Add any other motivation or useful context here.

Discussion checklist

bwilkerson commented 9 months ago

We have already implemented this as a warning, but have been unable to land it because it's too big a breaking change.

We have discussed implementing this as a lint, and have agreed (I think) that this is the right approach, but I haven't yet been able to make the time to convert the warning-based implementation to produce a lint. (We won't be able to implement it as a traditional lint because the check has to occur after all the other lints have been run, not as part of running the lints. But that's just an implementation detail.)

srawlins commented 9 months ago

I think duplicate of https://github.com/dart-lang/sdk/issues/35234 and https://github.com/dart-lang/sdk/issues/25917