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

Custom lint breaks when analysis_options.yaml is not at package root #148

Closed
Clavum opened this issue May 5, 2023 · 11 comments · Fixed by #212
Closed

Custom lint breaks when analysis_options.yaml is not at package root #148

Clavum opened this issue May 5, 2023 · 11 comments · Fixed by #212
Assignees
Labels
bug Something isn't working

Comments

@Clavum
Copy link

Clavum commented May 5, 2023

If a package has additional analysis_options.yaml files that are not at the root of the package, then custom lint will attempt to read a pubspec.yaml at the same location as the analysis options. The pubspec doesn't exist, and custom lint fails to start.

Example:

my_package
  lib
    ...
  test
    analysis_options.yaml
    ...
  analysis_options.yaml
  pubspec.yaml

Custom lint expects there to be a pubspec.yaml with every options file, and will throw the error:
PathNotFoundException: Cannot open file, path = 'project/path/my_package/test/pubspec.yaml' (OS Error: No such file or directory, errno = 2)

A PR was made to fix this several months ago, but was eventually abandoned.
#19

@Clavum Clavum added the bug Something isn't working label May 5, 2023
@rrousselGit
Copy link
Collaborator

That's not the behavior I've seen.
Do you mind making a quick github repository showcasing the problem, just so that we're on the same page?

I have multiple projects with a root analysis_options but no associated pubspec, and custom_lint works just fine on them.

@rrousselGit rrousselGit added the question Further information is requested label May 5, 2023
@Clavum
Copy link
Author

Clavum commented May 5, 2023

So I tried to make a minimal reproducible example, and yet for some reason it was not having the issue either. I kept trying to make it more similar to my package that isn't working (same Dart lints, structure, everything) but to no avail. I think the only difference between them at this point is the number of files/lines of code, and length of time they've existed...

Have any ideas what could cause it? I suppose when I get another chance to look into it I can clone and debug custom_lint myself.

@Clavum
Copy link
Author

Clavum commented May 8, 2023

Looking into this a little bit right now.

For the package having issues, allContextRoots on line 178 of custom_lint/src/workspace.dart has two context roots, including the test folder.

For the package not having issues, allContextRoots has only a single context.

Seems pretty relevant to the issue. I'll continue to debug.

@Clavum
Copy link
Author

Clavum commented May 8, 2023

Kinda embarrassing, but when trying to make the minimal reproducible example, I mistyped analysis_options.yaml in the test folder so I effectively only had one real options file in the project. After fixing it, I do get the error I initially reported. So, here's the example you asked for.

https://github.com/Clavum/lint_bug_example

@rrousselGit rrousselGit self-assigned this May 10, 2023
@TimWhiting
Copy link
Contributor

I can confirm this breaks it.

@rrousselGit
Copy link
Collaborator

TIL that we can put analysis_options.yamls inside the project instead of above it.Pretty sure I tried that before and it didn't work.

Fair enough then, this does need testing indeed

@Clavum
Copy link
Author

Clavum commented Sep 4, 2023

@rrousselGit @TimWhiting Thanks for the progress made on the PR so far! It looks like it hasn't been touched for a few months now though. Is there any more progress being made? This seems like a significant issue because it entirely prevents the use of custom lint in some projects, which includes mine.

@TimWhiting
Copy link
Contributor

Sorry, I've been out of the loop as far as this project goes. I'm unaware of what has changed as far as how custom_lint resolves packages since I last worked on the PR, but it looks like a lot has changed. Feel free to rebase the PR on the main branch and take over it if it is blocking you. I'm no longer actively working on it.

@bartekpacia
Copy link

I also experienced this problem when setting up custom_lint in Patrol repository. Here's the repro:

leancodepl/patrol#1947

bartekpacia added a commit to leancodepl/patrol that referenced this issue Nov 23, 2023
bartekpacia added a commit to leancodepl/patrol that referenced this issue Nov 23, 2023
* set up `custom_lint` in all packages

* gitignore all custom_lint.log files

* fix new lint warnings

* update prepare-* workflows to run custom_lint

* delete analysis_options in directories that do not have pubspec.yaml

This is needed because of bug in custom_lint: invertase/dart_custom_lint#148

* fix tests
@mrgnhnt96
Copy link
Contributor

@rrousselGit I think that this may have regressed lately, my nested analysis options files are not being respected anymore, I jumped from version 0.5.11 to 0.6.4. Any idea what might have caused this?

@mrgnhnt96
Copy link
Contributor

Actually, this is also happening with the 0.5.11 version as well. I did change flutter versions from 3.19.6 to 3.22.2. Perhaps there was a change in analyzer to make this act this way?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
5 participants