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

The "exclude" list in .analysis_options is ignored by the dartanalyzer cli #25551

Closed
enyo opened this issue Jan 21, 2016 · 76 comments
Closed

The "exclude" list in .analysis_options is ignored by the dartanalyzer cli #25551

enyo opened this issue Jan 21, 2016 · 76 comments
Labels
area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@enyo
Copy link

enyo commented Jan 21, 2016

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

@floitschG floitschG added the area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. label Jan 21, 2016
@bwilkerson
Copy link
Member

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.

@enyo
Copy link
Author

enyo commented Jan 21, 2016

Exactly. The rules defined in my .analysis_options should not apply to excluded files, event though they need analysing.

@kevmoo kevmoo added P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) and removed Priority-Medium labels Mar 1, 2016
@MikeMitterer
Copy link

All my tests are red!!! I've excluded test because generic functions are not available and expectAsync produces all those "Unsound..." errors

capturfiles-20161207_121922

capturfiles-20161207_121643

@enyo
Copy link
Author

enyo commented Aug 23, 2018

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.

@devoncarew
Copy link
Member

@enyo, can you attach a small project that repros this issue? We use excludes 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.

@enyo
Copy link
Author

enyo commented Aug 23, 2018

@devoncarew yes! Glad to help, I'll do it ASAP.

@enyo
Copy link
Author

enyo commented Aug 27, 2018

@MichaelRFairhurst
Copy link
Contributor

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.

@enyo
Copy link
Author

enyo commented Aug 28, 2018

That would be great :)

@enyo
Copy link
Author

enyo commented Sep 4, 2018

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.

@scheglov
Copy link
Contributor

scheglov commented Sep 4, 2018

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.

@enyo
Copy link
Author

enyo commented Sep 5, 2018

@scheglov Ah! That makes sense. Thanks

@MichaelRFairhurst
Copy link
Contributor

Leaving a note that this affects part files as well.

@jaumard
Copy link

jaumard commented Feb 21, 2019

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 ?

@jaumard
Copy link

jaumard commented Feb 22, 2019

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

@lejard-h
Copy link

Same issue after upgrading to 2.13

@spkersten
Copy link
Contributor

We're also seeing this issue after upgrading to Dart 2.13. We have three/four layers of analysis_options.yaml which each include the next one. I could work around this issue by add

exclude:
    - "**/*.g.dart"

in a different layer.

@enyo
Copy link
Author

enyo commented Jun 25, 2021

We're also seeing this issue after upgrading to Dart 2.13. We have three/four layers of analysis_options.yaml which each include the next one. I could work around this issue by add


exclude:

    - "**/*.g.dart"

in a different layer.

Could you be a bit more specific? Where did you add the exclude for it to work?

@enyo
Copy link
Author

enyo commented Jun 26, 2021

Ok, so I was able to find a solution to, thanks to @spkersten .

I too was using multiple analysis_options.yaml files, and I was excluding a specific directory as well (instead of only **/*.g.dart). To make sure that the directory was properly excluded I needed to also adapt the path to the excluded directory, relative to the different analysis_options.yaml files.

@pruthvi145
Copy link

@enyo can you explain the solution? I am using the lint package (Thus, I am also using the layers of analysis_options.yaml). I have excluded the file from my project but it is not working!

@spkersten
Copy link
Contributor

@pruthvi145 I think the issue @enyo and I encountered is that excludes that start with path (e.g., lib/*.g.dart) are only matched against paths in the same directory as the analysis_options.yaml that declares them. So if you include such an analysis_options.yaml from another directory, those excludes don't do anything. A workaround for that is to not use that kind of exclude but instead something like "**/*.g.dart"; or to move the excludes to the top-level analysis_options.yaml.

I don't see any excludes in the lint packages, so I'm not sure you're experiencing the same problem.

@pruthvi145
Copy link

pruthvi145 commented Jul 3, 2021

@spkersten Right! can you help me to figure out my issue?

Here is my analysis_options.yaml rules:

image

According to the rules, the file lib/common/pulse_icons.dart should be excluded but the dart analyzer is not ignoring that file.
Here is my VSCode's output:

image

Here is the output of the dart analyze:

image

At both places, it seems like exclude is not affecting the analyzer. Can anyone explain the behavior? why it is happening? Am I missing something?

@2shrestha22
Copy link

2shrestha22 commented Aug 7, 2021

flutter analyze and dart analyze makes no sense if we can't control which files we needed to include or exclude. There are dozens of issues about this and all closed without proper solution.

@lejard-h
Copy link

lejard-h commented Aug 26, 2021

Any news about this ?

I am still having the issue on 2.14.0-377.7.beta

@dnfield could we reopen the issue ?

@scheglov
Copy link
Contributor

scheglov commented Aug 27, 2021

Please upload an example, which causes unexpected diagnostics reported.
For example, see the attached ZIP file.
test2.zip

scheglov@scheglov-macbookpro2:~/dart$
scheglov@scheglov-macbookpro2:~/dart/test2$ dart analyze
Analyzing test2...                     0.9s
No issues found!

I use never Dart SDK, but AFAIK nothing was changed there recently.

scheglov@scheglov-macbookpro2:~/dart/test2$ dart --version
Dart SDK version: 2.15.0-edge.888e41b5a259f13aa66dd700ae92a757fa4a2123 (be) (Thu Aug 26 17:39:38 2021 +0000) on "macos_x64"

@scheglov scheglov reopened this Aug 27, 2021
@lejard-h
Copy link

Here's what i found after investigation.

I have a core package containing the analysis_options.yaml use by my other packages and also use by itself.

core/lib/generated
core/lib/src
core/lib/analysis_options.yaml
core/analysis_options.yaml (include the one in lib)

package_a/lib/generated
package_a/analysis_options.yaml (include core/lib/analysis_options.yaml)

I do the exclude in core/lib/analysis_options.yaml and this is were it does not work.
It want a relative path

# This does not work on core, but works on package_a
# Working on sdk 2.12 but not after
analyzer:
  exclude:
    - lib/generated/*.dart
    
# This work on core, but not package_a
analyzer:
  exclude:
    - generated/*.dart

Other issue on core/analysis_options.yaml, the analyzer seems to completely ignore this file since there is one already define in core/lib

exclude_anlayzer_test.zip

@scheglov
Copy link
Contributor

OK, I see why it happens.
When you have a file named analysis_options.yaml in a directory, it replaces any options file in a parent directory.
But you want to reuse core/lib/analysis_options.yaml for analysis in core and package_a by including it.

So, name it something differently than analysis_options.yaml, for example analysis_options_to_include.yaml, and update includes to use include: package:core/analysis_options_to_include.yaml.

@lejard-h
Copy link

Thanks @scheglov It fix my issue !

Don't know if it the same for everyone

@RyosukeOK
Copy link

In my case, it was due to brackets ( )in parent folder name.
When I removed it, exclude worked.

llucax added a commit to lunofono/lunofono_player that referenced this issue Sep 21, 2021
The dartanalyzer has a bug when excluding files that have been around
for a long time now, and since it is now deprecated in flavour of `dart
analyze` it is very unlikely to be fixed any time soon.

Since this action uses dartanalyzer and we need to exclude mocks, we
can't use it anymore.

dart-lang/sdk#25551
llucax added a commit to lunofono/lunofono_player that referenced this issue Sep 21, 2021
The dartanalyzer has a bug when excluding files that have been around
for a long time now, and since it is now deprecated in flavour of `dart
analyze` it is very unlikely to be fixed any time soon.

Since this action uses dartanalyzer and we need to exclude mocks, we
can't use it anymore.

dart-lang/sdk#25551
llucax added a commit to lunofono/lunofono_player that referenced this issue Sep 21, 2021
The dartanalyzer has a bug when excluding files that have been around
for a long time now, and since it is now deprecated in flavour of `dart
analyze` it is very unlikely to be fixed any time soon.

Since this action uses dartanalyzer and we need to exclude mocks, we
can't use it anymore.

dart-lang/sdk#25551
llucax added a commit to lunofono/lunofono_player that referenced this issue Sep 21, 2021
The dartanalyzer has a bug when excluding files that have been around
for a long time now, and since it is now deprecated in flavour of `dart
analyze` it is very unlikely to be fixed any time soon.

Since this action uses dartanalyzer and we need to exclude mocks, we
can't use it anymore.

dart-lang/sdk#25551
@mit-mit
Copy link
Member

mit-mit commented Oct 11, 2021

dart analyze is not always an option either, because it doesn't provide the --format=machine option for example.

Please note that dart analyze does support this option, even though it's not in the (abbreviated) help:

$ dart analyze --format=machine .
ERROR|COMPILE_TIME_ERROR|UNDEFINED_FUNCTION|/Users/mit/tmp/d1/bin/d1.dart|5|5|4|The function 'prnt' isn't defined.

@mit-mit
Copy link
Member

mit-mit commented Oct 11, 2021

dart analyze is the current workaround for this issue. If anyone has any things they are missing in dart analyze which is causing them to still use dartanalyzer and hit the present issue, please let us know as dartanalyzer is scheduled for eventual deprecation.

@srawlins
Copy link
Member

Closing this for now, as dartanalyzer is now scheduled for removal soon.

@ptheofan
Copy link

Would be great to fix the excluded option as my README.md gets errors on every commit when it's touched.

@mit-mit
Copy link
Member

mit-mit commented Mar 20, 2023

@ptheofan this issue is now closed. If you are still seeing issues with recent builds, please file a new issue with details and repro steps.

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. P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests