Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hints like unused_local_variable missing from linter docs #48553

Closed
DetachHead opened this issue Mar 14, 2022 · 9 comments
Closed

Hints like unused_local_variable missing from linter docs #48553

DetachHead opened this issue Mar 14, 2022 · 9 comments
Labels
area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P3 A lower priority bug or feature request type-documentation A request to add or improve documentation

Comments

@DetachHead
Copy link

Describe the issue
https://dart-lang.github.io/linter/lints/index.html
https://dart-lang.github.io/linter/lints/unused_local_variable.html - 404 error

@srawlins srawlins transferred this issue from dart-lang/linter Mar 14, 2022
@srawlins
Copy link
Member

unused_local_variable is not a Lint defined in the linter, but a Hint (more like a Warning) defined in the SDK. See https://dart.dev/tools/diagnostic-messages#unused_local_variable.

@srawlins
Copy link
Member

CC @bwilkerson. I think you discussed a common diagnostics location, on another issue.

@srawlins srawlins added area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. type-documentation A request to add or improve documentation labels Mar 14, 2022
@bwilkerson
Copy link
Member

Yes, we've discussed moving the lint documentation to the same location as the other diagnostics. Not sure whether it's a good idea (especially given the evidence that some users are very familiar with the current location), but even if it would be a good idea, it's probably not a high priority.

@DetachHead
Copy link
Author

Maybe if there is was some indication in the dart analyze output that says whether a rule is a lint or a diagnostic it would be less confusing

@bwilkerson
Copy link
Member

Confusion abounds. :-(

A diagnostic is an indication of a problem in the code. A lint is a diagnostic that is disabled by default.

The fact that lints are implemented in the linter package while every other kind of diagnostic is implemented in the analyzer package is an implementation detail that shouldn't be visible to users. Unfortunately, because of where we've put the documentation for lints, it becomes somewhat visible.

Maybe if there is was some indication in the dart analyze output that says whether a rule is a lint ...

I'm not sure whether that would be a good thing or not. Ideally the user shouldn't need to know which are from lints. Of course, the current state is not ideal, so ... :-/

But I will point out that dart analyze includes, as part of its output, the URL of the documentation for every diagnostic that has documentation. You should be able to use that URL to navigate to the documentation without needing to think about whether the diagnostic was generated by a lint or not.

@DetachHead
Copy link
Author

Yes, we've discussed moving the lint documentation to the same location as the other diagnostics. Not sure whether it's a good idea (especially given the evidence that some users are very familiar with the current location)

The fact that lints are implemented in the linter package while every other kind of diagnostic is implemented in the analyzer package is an implementation detail that shouldn't be visible to users. Unfortunately, because of where we've put the documentation for lints, it becomes somewhat visible.

imo if this is an implementation detail that users aren't meant to see, i think it would be better if the documentation was moved even if there are some users used to the current state

But I will point out that dart analyze includes, as part of its output, the URL of the documentation for every diagnostic that has documentation. You should be able to use that URL to navigate to the documentation without needing to think about whether the diagnostic was generated by a lint or not.

is there an argument i need to pass to enable for this? i'm not seeing any urls in the output:

>dart analyze
Analyzing project...

  error • lib\screens\foo.dart:13:11 • The value of the local variable 'foo' isn't used. Try removing the variable or using it. • unused_local_variable
  error • test\widget_test.dart:10:8 • Target of URI doesn't exist: 'package:project/main.dart'. Try creating the file referenced by the URI, or Try using a URI for a file that does exist. • uri_does_not_exist
  error • test\widget_test.dart:15:35 • The name 'HomeRoute' isn't a class. Try correcting the name to match an existing class. • creation_with_non_type
   info • lib\screens\foo.dart:5:7 • This class (or a class that this class inherits from) is marked as '@immutable', but one or more of its instance fields aren't final: ReportRoute.report, ReportRoute.onSave • must_be_immutable

4 issues found.

i know there are documentation links when you hover over the warnings in the IDE, but i think they should also be present in the dart analyze output like you said, especially if it's not obvious where to look for said docs
image

@bwilkerson
Copy link
Member

I thought it was the default behavior, but it appears that you need to include the --verbose flag in order to get that information. FWIW, I consider that to be a bug.

dart analyze

   info • lib/test.dart:2:7 • The value of the local variable 'x' isn't used. Try removing the variable or using it. •
          unused_local_variable

dart analyze --verbose

   info • lib/test.dart:2:7 • The value of the local variable 'x' isn't used. Try removing the variable or using it. •
          https://dart.dev/diagnostics/unused_local_variable

@srawlins srawlins changed the title unused_local_variable missing from docs Hints like unused_local_variable missing from linter docs Mar 21, 2022
@srawlins srawlins added the P3 A lower priority bug or feature request label Mar 21, 2022
@srawlins
Copy link
Member

CC @parlough and @pq was this resolved recently?

@parlough
Copy link
Member

parlough commented Jul 21, 2023

I think the core issue raised here is that linter rules are treated differently by the analyzer from other diagnostics. To solve this, we're currently working on adding consistent diagnostic documentation for linter rules to the same location and in the same format as other diagnostics.

We're tracking that work in dart-lang/site-www#4498 among other issues, so perhaps this issue can be closed in favor of those.

@DetachHead DetachHead closed this as not planned Won't fix, can't repro, duplicate, stale Jul 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P3 A lower priority bug or feature request type-documentation A request to add or improve documentation
Projects
None yet
Development

No branches or pull requests

4 participants