Sdk: dartanalyzer not generating diagnostics for pubspec.yaml files

Created on 22 Sep 2020  路  12Comments  路  Source: dart-lang/sdk

To reproduce,

  1. enable sort_pub_dependencies
  2. unsort pub dependecies
  3. run analyzer
[~/src/repos/linter] (master) $ dartanalyzer .
Analyzing linter...
No issues found!

(No issues are reported in IntelliJ either.)

The linter binary does pick these up (and explains why our tests haven't noticed the regression):

[~/src/repos/linter] (master) $ dart bin/linter.dart .
/Users/pq/src/repos/linter/pubspec.yaml 16:3 [lint] Sort pub dependencies.
  analyzer: ^0.40.0
  ^^^^^^^^

/fyi @jonasfj

area-analyzer type-bug

Most helpful comment

hi! I'm still pretty new to this codebase so my conclusions may be incorrect, but I had taken a look at this issue a while back, and I think for the command-line analyzer, the reason why it's not analyzing pubspec.yaml properly is because of these lines, which causes the pubspec.yaml file to only be analyzed based on the PubspecValidator in analyzer.

All 12 comments

That's working as expected (though not necessarily as intended :-) ). The command-line analyzer only analyzes .dart files unless you explicitly specify a non-.dart file on the command line. I believe that the analysis server (and hence the future dart analyze command) analyzes all of the files in the directory that we know how to analyze.

Aha. That's helpful and yeah, a little surprising. I'm not sure it's entirely work there either though?

[~/src/repos/linter] (master) $ dartanalyzer pubspec.yaml 
Analyzing pubspec.yaml...
No issues found!

More importantly, IntelliJ isn't reporting the diagnostic either. I'm not sure if that's an IntelliJ issue or server yet.

hi! I'm still pretty new to this codebase so my conclusions may be incorrect, but I had taken a look at this issue a while back, and I think for the command-line analyzer, the reason why it's not analyzing pubspec.yaml properly is because of these lines, which causes the pubspec.yaml file to only be analyzed based on the PubspecValidator in analyzer.

Thanks for taking a look @walnutdust!

My attention has been on server, with a proof of concept up for discussion here: https://dart-review.googlesource.com/c/sdk/+/164249

image

The CLI would need some updating as well.

Is this currently just an issue with dartanalyzer (from the command line, but not from IDEs)?

It's an issue in IDEs as well.

The command-line dartanalyzer tool doesn't report any diagnostics for YAML files unless they are explicitly listed on the command-line. It might not even do so when they are listed.

The analysis server reports some diagnostics, but wasn't reporting lints for them, even though we have implemented a couple of lints. Phil's CL will fix server so that lints are produced by server.

The rub is that _analyzePubspecFile in the context manager is not running lints. I've got this hacked locally and it seems straight-forward -- needs some testing and review though.

Ah, ok. I'll rename this to reflect that this is (or will soon be) dartanalyzer specific.

As for Brian's comment, even if you specify a pubspec on the CLI lints won't be run.

UPDATE: the Flutter Engine roll was blocked on a false positive in the newly reporting sort_pub_dependencies (https://github.com/dart-lang/linter/issues/2271) so I'm rolling this back pending a fix to the lint: https://dart-review.googlesource.com/c/sdk/+/166703.

UPDATE: false alarm. Lint was fine after all. Staging change for re-landing. 馃憤

Was this page helpful?
0 / 5 - 0 ratings