When I define excludes in my .analysis_options
file like this:
analyzer:
strong-mode: true
exclude:
- test/**
- lib/generated_library/**
files in lib/generated_library
are still analyzed, when they are imported by other libraries in my project.
I would expect _not_ to get strong-mode warnings or lint errors in any files excluded in the exclude:
list
Analyzer has to analyze every file that is imported in order to know which names are and are not defined in the importing library, but you're right that errors and warnings should not be reported for explicitly excluded files.
Exactly. The rules defined in my .analysis_options
should not apply to excluded files, event though they need analysing.
All my tests are red!!! I've excluded test because generic functions are not available and expectAsync produces all those "Unsound..." errors
Is there an update for this? I know that there are more exciting things to do than fixing the exclude flag, but it is really annoying and there is no real solution to work around it.
This issue is now more than 2 years old, it would be great to see some work done on this.
@enyo, can you attach a small project that repros this issue? We use exclude
s ourselves in our own work, and don't see issues, but it's likely that you're hitting some problem in the implementation that we're not aware of.
@devoncarew yes! Glad to help, I'll do it ASAP.
@devoncarew https://github.com/exitlive/exclude_demo
This is actually a issue that I have hit in my own angular_analyzer_plugin. It's surprisingly nontrivial to fix, but it's only an issue in analyzer_cli. So if we make the switch to use server as the backend for that, this will go away.
That would be great :)
I'd like to give additional feedback on this, but it is probably a completely separate issue.
Although normally excluded files are properly excluded in IDEs (which, if I understood correctly use the server โ tested on both IntelliJ and VSCode), sometimes excluded files reappear.
I think it's related to which file is currently open. So if you open an excluded file in your IDE, suddenly the excludes for this file are ignored.
When you open a file, it gets analyzed, and Analysis Server sends errors, semantic highlighting, etc to the IDE. When you close the file (so, it stops being a priority file), you should stop getting more data about this file. What is missing now is sending the empty list of errors so that IDE removed red squiggles.
@scheglov Ah! That makes sense. Thanks
Leaving a note that this affects part files as well.
Is there any news on this ? 3 years it's a bit long ^^ :(
For example if you want to force single quote with prefer_single_quotes: error
and you're using intl
for localization, it will generate everything with double quote and your CI will fail because it take excluded files into consideration where IDE is not :/
@MichaelRFairhurst didn't quite understand your message, did you have a hack around this issue ?
The title can be more generic as it's not just imports but all rules The "exclude" list in .analysis_options is ignored in cli
Any progress on that? That is actually a huge issue that cuts out half of the cases where you can use the tool. I would like to add it to CI flow, however, I can't because there are some warnings in generated files.
It's surprisingly nontrivial to fix, but it's only an issue in analyzer_cli. So if we make the switch to use server as the backend for that, this will go away.
Could you elaborate on what the obstacles are?
For me is exactly this problem https://github.com/dart-lang/sdk/issues/28754, I just can't exclude file.
I managed to solve this issue by creating a small tool to edit each ignored file and add the directive "// ignore_this_file: ...".
Then I run this after building the generated content making sure lint will not fail because of these files.
I used my analysis_options file to get the list of ignored files and the list of rules - so I create this ignore directive by the same way I would expect dartanalyzer to do.
Based on tips from https://github.com/dart-lang/sdk/issues/34098, I found pub global activate tuneup
, which doesn't suffer from this (tuneup check
).
Seems like this would be fixed by fixing the same underlying issue of #34098 (using the analysis server in whatever way the CLI isn't currently), and probably should just be clsoed as a duplicate.
I tune in to those, who cannot exclude files - I have the same problem...
In my case, the exclude
list is not ignored in dartanalyzer .
but in Android Studio.
@scheglov Closing the files does not work for me. As soon as I open any file in the project, the errors and warnings appear again. In my case the problem is that it is generated code that I am referencing in my own code.
(exactly what @rrousselGit reported in https://github.com/Dart-Code/Dart-Code/issues/601#issue-298742063)
Here's another small project to reproduce: https://github.com/johnpryan/analyzer_exclude_bug
Same for Android Studio. I have analysis_options.yaml
with
analyzer:
exclude:
- lib/net.dart
- lib/network_error.dart
- lib/search_net.dart
- lib/orders_net.dart
strong-mode:
implicit-casts: false
but analyzer randomly stops excluding some files
I fixed this by adding a analysis_options.yaml and relaunched the android studio.
I fixed this by adding a analysis_options.yaml and relaunched the android studio.
That actually helped me too... I got strict errors reported from json_serializable generated files and after AS restart those reports are gone.
This should have more attention. I can't work around the rules just to not have them reporting errors on generated files. Adding linter suppressors on the file don't seem to help as well.
Is there any update on this issue? When using code generation the analyzer often gets unusable :/
One workaround is having two packages, and two analysis_options.yaml, one for generated code, one for manual.
It looks like the issue is when you add exclude path that is not in quotation marks. I have config below and it works just right. Feel free to try it.
include: package:pedantic/analysis_options.yaml
analyzer:
strong-mode:
implicit-casts: false
implicit-dynamic: false
exclude:
- "**/*.g.dart"
errors:
missing_return: error
missing_required_param: error
It looks like the issue is when you add exclude path that is not in quotation marks. I have config below and it works just right. Feel free to try it.
include: package:pedantic/analysis_options.yaml analyzer: strong-mode: implicit-casts: false implicit-dynamic: false exclude: - "**/*.g.dart" errors: missing_return: error missing_required_param: error
~Are you sure that it works? I've just tried and it completely ignores it and shows hundreds of errors e.g.:~
~EDIT: I had to reset the VS Code and it works now!~
EDIT2: Well, it stopped working yesterday again...
analyzer:
exclude:
- "build/**"
- "lib/generated/*"
- "lib/icons/*"
- "**/*.freezed.dart"
- "**/*g.dart"
- "*.g.dart"
- "test/**"
- "**/*_test.dart"
Doctor summary (to see all details, run flutter doctor -v):
[โ] Flutter (Channel dev, v1.16.2, on Mac OS X 10.15.3 19D76, locale pl-PL)
[โ] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
[โ] Xcode - develop for iOS and macOS (Xcode 11.3.1)
[โ] Chrome - develop for the web
[โ] Android Studio (version 3.6)
[โ] VS Code (version 1.43.2)
[โ] Connected device (3 available)
โข No issues found!
@bwilkerson @devoncarew
Do we have any news on this? Is there any specific blocking point that was not communicated?
This put unnecessary stress on code-generators maintainers. Because of such an issue, we receive many requests for generating // ignore_for_file
.
cc @stereotype441 for visibility into this dartanalyzer cli issue
@rrousselGit - in an upcoming release of the Dart sdk (likely the first Dart 2.9-dev release), we'll have a new dart analyze
command. The implementation of that is currently based on the analysis server, so won't have this issue.
dart analyze
is working nicely ๐ Thanks guys!
analyzer:
exclude:
- lib/**/*.g.dart
Flutter (Channel master, 1.20.0-1.0.pre.29)
Dart version 2.9.0 (build 2.9.0-15.0.dev f043f9e5f6)
(AS 3.6.3, Flutter plugin 46.0.1 is still complaining about **/*.g.dart
though)
@arctouch-matheusromao This was also the case before, i.e. analyze
did consider the exclude
list but the IDE did not.
@creativecreatorormaybenot Well, it wasn't working for me with the wildcards after lib
when I was on stable... I mean, flutter analyze
and dartanalyzer
were running and pointing the infos and warnings in the generated files, even though I was excluding everything. Then I tried with dart analyze
and worked, even faster than before.
It was working perfectly for me, until the latest beta. It seems to be completely removed now.
Yes, sorry. The combined dart
UI was pulled from the upcoming dart 2.9 stable (and beta) release. It's still in master and dev, and will be in the next beta, and the following stable.
There were a few issues running dart apps in some corner case use cases. These were deemed blocking in terms of shipping it in upcoming current stable release given how widespread use of the dart
CLI tool is.
In my case, restarting my IDE solved the issue.
2.8.4
2020.1.4
(Ultimate Edition)201.8538.45
@arctouch-matheusromao what version of dart are you using. dart analyze
doesn't work for me.
long1eu@Razvans-Mac-Pro mobile % dart --version
Dart SDK version: 2.9.0 (stable) (Fri Jul 31 10:59:48 2020 +0200) on "macos_x64"
long1eu@Razvans-Mac-Pro mobile % dart analyze
Error: Error when reading 'analyze': No such file or directory
Vs-code doesn't show the excluded files but when I run the dartanalyzer
in powershell it shows me the excluded files.
analyzer:
exclude:
- "**/*.chopper.dart"
- "**/injection.config.dart"
- "**/*.freezed.dart"
- "**/*.g.dart"
I run it with this command dartanalyzer.bat --options .\analysis_options.yaml .
So:
dart analyze
doesn't exist (yet)Am I supposed to give up on running lints in a CI? I don't see dartanalyzer
being marked as deprecated and this is a pretty serious 4.5 year old bug :/
I still get avoid_equals_and_hash_code_on_mutable_classes
violations from built_value
generated files with
analyzer:
exclude:
- "**/*.g.dart"
and dartanalyzer.bat --options .\analysis_options.yaml .
Update
dart analyze
works fine though
dart analyze
was officially released with dart 2.10. I can finally run lints in my CI ๐๐๐
Can this be closed now that dart analyze
is a thing?
I guess I have permission to close this, so I will. If someone is still having this issue, please comment to re-open, or file a more up to date bug for the current tooling.
Most helpful comment
@bwilkerson @devoncarew
Do we have any news on this? Is there any specific blocking point that was not communicated?
This put unnecessary stress on code-generators maintainers. Because of such an issue, we receive many requests for generating
// ignore_for_file
.