dart-lang / sdk

The Dart SDK, including the VM, dart2js, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
9.94k stars 1.53k forks source link

Analysis options bugged after upgrading from Flutter 3.22.0-0.2.pre to 3.23.0-0.1.pre #55975

Open cabaucom376 opened 3 weeks ago

cabaucom376 commented 3 weeks ago

For the last 6 moths I have been using this guide to essentially include all linter rules and then override the conflicts and tune the rules to my taste. I have made this simple little setup into a package that I host on a private GitHub repo and just update the all_linter_rules.yaml file whenever new rules are added, as well as make sure all conflicts are resolved. With the 3.23 beta I am encountering a new error even though my overall methods have remained consistent.

I am now getting warnings about conflicting linter rules in my all_linter_rules.yaml file even though conflicts are properly overridden and the included_file_warning: ignore analyzer error is properly set. The weird part is that when I reference my custom analysis packages' analysis_options.yaml locally the errors are not present. Only when referencing the analysis_options.yaml using a package import, from git hosted or local path, do these warnings appear.

  1. nv_analysis package files

  2. Project files

pubspec.yaml:

dev_dependencies:
  flutter_test:
    sdk: flutter
  nv_analysis:
    git:
      url: git@github.com:Novoid-LLC/nv_flutter_analysis.git
      ref: master

analysis_options.yaml:

include: package:nv_analysis/analysis_options.yaml # local barrel import of file removes warnings
analyzer:
  plugins:
    - custom_lint
  1. Warnings:
    Warning in the included options file /Users/$User/.pub-cache/git/nv_flutter_analysis-b80a6a1f77bd738d967c1ff52af94e50788bb94f/lib/all_lint_rules.yaml(1497..1529): The rule 'avoid_types_on_closure_parameters' is incompatible with the rule 'always_specify_types'.dart(included_file_warning)
    Warning in the included options file /Users/$User/.pub-cache/git/nv_flutter_analysis-b80a6a1f77bd738d967c1ff52af94e50788bb94f/lib/all_lint_rules.yaml(3522..3546): The rule 'omit_local_variable_types' is incompatible with the rule 'always_specify_types'.dart(included_file_warning)
    Warning in the included options file /Users/$User/.pub-cache/git/nv_flutter_analysis-b80a6a1f77bd738d967c1ff52af94e50788bb94f/lib/all_lint_rules.yaml(4302..4324): The rule 'prefer_final_parameters' is incompatible with the rule 'avoid_final_parameters'.dart(included_file_warning)
    Warning in the included options file /Users/$User/.pub-cache/git/nv_flutter_analysis-b80a6a1f77bd738d967c1ff52af94e50788bb94f/lib/all_lint_rules.yaml(4906..4928): The rule 'prefer_relative_imports' is incompatible with the rule 'always_use_package_imports'.dart(included_file_warning)
    Warning in the included options file /Users/$User/.pub-cache/git/nv_flutter_analysis-b80a6a1f77bd738d967c1ff52af94e50788bb94f/lib/all_lint_rules.yaml(4936..4955): The rule 'prefer_single_quotes' is incompatible with the rule 'prefer_double_quotes'.dart(included_file_warning)
    Warning in the included options file /Users/$User/.pub-cache/git/nv_flutter_analysis-b80a6a1f77bd738d967c1ff52af94e50788bb94f/lib/all_lint_rules.yaml(5799..5815): The rule 'unnecessary_final' is incompatible with the rule 'prefer_final_locals'.dart(included_file_warning)

Expected results

The expected results is that I should be able to include: package:nv_analysis/analysis_options.yaml and not receive conflicts from the all_lint_rules.yaml file since they have been resolved using overrides and even supposedly silenced using included_file_warning: ignore.

Actual results

My best guess of what is actually happening is for some reason the included_file_warning: ignore is not being applied to subsequent inclusions in yaml files. This is resulting in linter rules showing up as conflicts. Interestingly this is only reproducible when importing as a package.

Code sample

Attempt to import this analysis package in your projects analysis_options.yaml:

include: package:nv_analysis/analysis_options.yaml

Screenshots or Video

No response

Logs

No response

Flutter Doctor output

Doctor output ```console [✓] Flutter (Channel beta, 3.23.0-0.1.pre, on macOS 14.5 23F79 darwin-arm64, locale en-US) [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0) [✓] Xcode - develop for iOS and macOS (Xcode 15.4) [✗] Chrome - develop for the web (Cannot find Chrome executable at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome) ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable. [✓] Android Studio (version 2023.1) [✓] VS Code (version 1.90.0) [✓] Connected device (4 available) ! Error: Browsing on the local area network for iPhone. Ensure the device is unlocked and attached with a cable or associated with the same local area network as this Mac. The device must be opted into Developer Mode to connect wirelessly. (code -27) [✓] Network resources ! Doctor found issues in 1 category. ```

Originally posted by @cabaucom376 in https://github.com/flutter/flutter/issues/149981

foxanna commented 3 weeks ago

I experience similar behavior in my project. In this monorepo, there is a package www_analysis dedicated to configuring analyzer, which only contains lib/analysis_options.yaml file with the following content:

analyzer:
  exclude:
    - lib/**.g.dart
    - lib/**.freezed.dart
    - lib/**.i69n.dart
    - lib/**.config.dart

  errors:
    missing_required_param: error
    missing_return: error
    invalid_assignment: warning
    invalid_annotation_target: ignore

This package is referenced by path by every other package, and their analysis_options.yaml file contains:

include: package:www_analysis/analysis_options.yaml

With this configuration, the project used to have no analyzer warnings in generated files, and also did not have invalid_annotation_target warnings because it was instructed to ignore those.

However, after I switched from stable channel Flutter 3.22.2 and Dart 3.4.3 to beta Flutter 3.23.0-0.1.pre and Dart 3.5.0-180.3.beta, this configuration provided with include seems to be ignored as there are now invalid_annotation_target warnings everywhere.

If I copy the content of www_analysis/lib/analysis_options.yaml file to analysis_options.yaml of other packages, warnings in those packages disappear.

bwilkerson commented 3 weeks ago

There is another possible reason for the behavior being reported here: it's possible that the interpretation of relative paths changed. If the relative path is now interpreted relative to the analysis_options.yaml file in www_analysis and was previously interpreted relative to the including analysis_options.yaml file, that would account for the difference.

@pq