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

In Dart 3.5.0 analysis_options.yaml don't seem to be used under certain conditions #56416

Closed
jellynoone opened this issue Aug 9, 2024 · 22 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

@jellynoone
Copy link

jellynoone commented Aug 9, 2024

I'm attaching a zip file containing the source code for a reproducer. source.zip

Summary:
When editing a project in a specific way, analysis_options.yaml file doesn't get picked up and the project lacks the enabled lints.

The project structure is as follows:

app/                                    <- this is where the app implementation lives
app/main_app/                           <- this is the dart package root for the main app
app/main_app/lib/main.dart
app/main_app/lib/src/a.dart
app/main_app/analysis_options.yaml
app/main_app/pubspec.yaml
extra/                                  <- custom lints live here
extra/lib/analysis_options.yaml         <- our custom lints
extra/pubspec.yaml
# extra/lib/analysis_options.yaml
include: package:lints/recommended.yaml

linter:
  rules:
    prefer_relative_imports: true
// app/main_app/lib/main.dart

import 'package:main_app/src/a.dart';

void main(List<String> args) {
  print(A());
}
// app/main_app/lib/src/a.dart

class A {}
# app/main_app/analysis_options.yaml
include: package:extra/analysis_options.yaml

Steps to reproduce:

  1. Open app/ in an editor
  2. Open main_app/lib/main.dart
  3. There should be a lint for the import, but there is none.
    Running dart analyze on app/ produces the same behavior.

On the other hand, if we open app/main_app directly or run dart analyze on it. We observe all the expected lints.

In addition if we copy over the lints from extra/lib/analysis_options.yaml to app/main_app/analysis_options.yaml, we are correctly notified of all lints even when editing the project from app.

So it seems when a project is opened from a directory above it, lints from included files are not picked up.

dart --version
Dart SDK version: 3.5.0 (stable) (Tue Jul 30 02:17:59 2024 -0700) on "macos_arm64"

Perhaps this is related to #55975.

@dart-github-bot
Copy link
Collaborator

Summary: The analysis_options.yaml file in a nested package is not being used when the project is opened from a directory above it. This results in missing lints from included files, even though the lints are correctly applied when the package is opened directly or when running dart analyze on the package.

@dart-github-bot dart-github-bot added area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. triage-automation See https://github.com/dart-lang/ecosystem/tree/main/pkgs/sdk_triage_bot. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels Aug 9, 2024
@pq
Copy link
Member

pq commented Aug 9, 2024

@keertip: do we think this is handled by your recent fixes?

@pq pq added the P2 A bug or feature request we're likely to work on label Aug 9, 2024
@keertip
Copy link
Contributor

keertip commented Aug 9, 2024

Yes, this should be handled with the recent fixes.

@jellynoone, which channel of dart are you on? The latest dev channel has the fix, the other channels (stable, beta) probably not.

@jellynoone
Copy link
Author

Originally tested this on stable, 3.5.0. Since then tested this on dev, and everything works as expected.

Will this be cherry-picked?

@bwilkerson
Copy link
Member

@itsjustkevin

@lucasjinreal
Copy link

The functionality is impaired. It is kindly requested to upgrade to at least a minimally operational Dart release before pushing to Flutter....!!

@lishaduck
Copy link

To clarify what @lucasjinreal said, this is also broken in Flutter. It drove me crazy last night, and I was about to file a Dart-Code issue 🤣
I can check if it's in the flutter dev channel, though I would assume it is?

@lucasjinreal
Copy link

lucasjinreal commented Aug 11, 2024

@lishaduck Thank you for your expression! I uninstalled Flutter and reinstalled the beta channel, but the same issue occurred. Now this is truly troublesome! @jellynoone Beta channel actually not work at all!!

@lishaduck
Copy link

lishaduck commented Aug 11, 2024

I uninstalled Flutter and reinstalled the beta channel, but the same issue occurred. Now this is truly troublesome! [...] Beta channel actually not work at all!!

As @keertip said,

The latest dev channel has the fix, the other channels (stable, beta) probably not.

dev == main1

Try flutter channel main, that should fix it. If not, we just need to wait for a new version of Dart to make it to Flutter. Notifying everyone subscribed doesn't get it fixed any faster.

Footnotes

  1. That's my assumption, at least.

@lucasjinreal
Copy link

No, it's master.

@lucasjinreal
Copy link

Originally tested this on stable, 3.5.0. Since then tested this on dev, and everything works as expected.

main master dev stable beta ....

We are just getting extremly confused.

@jellynoone
Copy link
Author

jellynoone commented Aug 11, 2024

Originally tested this on stable, 3.5.0. Since then tested this on dev, and everything works as expected.

main master dev stable beta ....

We are just getting extremly confused.

I was talking about the Dart channel here, not the Flutter branch.
I'm unaware what Flutter branch actually has the fix, beta probably won't since even Dart beta channel is on version 3.5.0 which is the current version i.e. due to a new release stable and beta are the same.

I was able to solve the issues I was having with analysis by editing the project at its root (where the analysis_options.yaml and pubspec.yaml files live).

@lucasjinreal
Copy link

@jellynoone Hi, what is the meaning of by editing the project at its root? Could you elaborate a little on how to modify the YAML files? Which part needs to be changed?

@lrhn lrhn removed the triage-automation See https://github.com/dart-lang/ecosystem/tree/main/pkgs/sdk_triage_bot. label Aug 12, 2024
@jellynoone
Copy link
Author

jellynoone commented Aug 12, 2024

@lucasjinreal What I'm referring to as the project root is where the pubspec.yaml and analysis_options.yaml files are defined.

If you look at my initial report, you see I mention a project structure similar to the following:

app/
  main_app/                 <- this is what I refer to as the root of the project
    lib/
      main.dart
    analysis_options.yaml
    pubspec.yaml
  server_app/
extra/
package1/
package2/

The bug only occurs if you edit the project by opening app/ in the editor.
If you open app/main_app/, then everything works as expected.

Without knowing your project structure, I can't tell you anything more specific. But my guess is you have a mono-repo? Where there are multiple smaller packages / apps and you are editing them at the same time from a parent folder?
If this is the case, try opening the individual packages and edit just one at the time.

@lucasjinreal
Copy link

In my case, I think I am actually opened the main_app, my is just a bare flutter project, looks like:

main_app/                
    lib/
      main.dart
    analysis_options.yaml
    pubspec.yaml

typically I will code ./main_app which opens the root as you suggested, but is where the error comes.

@lishaduck
Copy link

lishaduck commented Aug 13, 2024

In that case, it's a different issue. This issue is about includes in monorepos.

@lucasjinreal
Copy link

To me, it's the same issue, but don't know why your solution works in your situation.

@lishaduck
Copy link

To me, it's the same issue, but don't know why your solution works in your situation.

I think they're different bugs, with similar symptoms.
@jellynoone & I both use monorepos, and for both of us, the include directive doesn't work.

If analysis_options also doesn't work under other conditions now, that is also a bug, but not what this thread is about.

@lucasjinreal
Copy link

lucasjinreal commented Aug 14, 2024

Yes, the symptoms are identical (as indicated by the error messages), nonetheless, it does not necessarily imply that the root cause is not the same, unless we determine the reason.

Currently, I can only wait for the next Flutter release. It is blocked.

@lishaduck
Copy link

lishaduck commented Aug 14, 2024

Duplicate of #56047; possible duplicate of #55975.
Fixed by b513402.
Cherry picked in 3.5.1: #56464 / 14ff0ca.
Awaiting Flutter engine reroll.

As @lucasjinreal said, all we can do is wait.

EDIT: Flutter 3.24.1 cherrypicked this!

@jellynoone
Copy link
Author

Tried to reproduce the issue with Dart 3.5.1 and I couldn't.

@lishaduck
Copy link

Flutter 3.24.1 cherrypicked this, file a new issue if upgrading doesn't resolve it, @lucasjinreal

lishaduck added a commit to PHS-TSA/our_democracy that referenced this issue Aug 26, 2024
Yahoo! dart-lang/sdk#56416 finally landed in Flutter stable!
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

8 participants