invertase / dart_custom_lint

💡 Easily write powerful Dart & Flutter lint rules for your projects or for users of your packages.
https://pub.dev/packages/custom_lint
Apache License 2.0
288 stars 65 forks source link

custom_lint is in conflict with macros (more and more) #260

Closed brilliapps closed 3 months ago

brilliapps commented 3 months ago

Edit: You better scroll over to the answer to this issue. Still, possibly this post may give you some insight to circumstances of what is going on.

Related to the #255 - will put reference there. So to summarize with improving macros there is increasing conflict between the custom_lint package and the macros.

I am sorry for copying from the official Discord Dart Server (reflects my growing "knowledge" of what is happening), so it is difficult to go through. It took me a lot of time already so this time i just want to avoid special editing version for the issue.

I test custom_lint package (macros enabled), dart project in VsCode i know i got to the point where this one is called succesfully and doesn't throw: reporter.reportErrorForElement(code, element); (tried several deprecated methods, also atElement, methods starting from at... like atElement stop executing code and errors are uncatchable) but in the place in my VsCode project there is no lint error displayed but instead cyclically like one per second in VsCode a popup with an error is displayed like every 1 second (this is how often analyzer refreshes?) "Socket error: Invalid argument (uri): URI scheme 'c' is not supported. Allowed schemes are 'file', 'dart-macro+file'.: "c:/...toproject.../lib/main.dart" : but it finds the making lint error declaration correctly. Only the popup. Dart version 3.5.0-323.1.beta I found issues that may have to do with the problem: https://github.com/flutter/flutter-intellij/issues/7450 https://github.com/flutter/flutter-intellij/pull/7466 and the first issue has entry (as i remember) mentioning macros with custom_lint Does anybody know what's going on? Do i have to wait until a newer version of Dart comes out that fixes it?

I Will be later.

It's like the plugin starts (cyclically is able to do the described above stuff) when custom_lint: ^0.3.4 (maybe 0.4.0 too), ###later i will try to figure out### what might have gone wrong. Dart project (dart create somename), Windows 11, VsCode, tested on macros turned off. Maybe i mixed some steps from two tutorials (i doubt i did).

Wanted to do a quick update on this that i've just switched flutter into stable channel and custom_lint (the newest 0.6.4) actually started to work. not going to create or add to existing custom_lint or possibly Dart SDK (exceptionally as custom_lint is probably very important) issues right away.

...

Colleting some other possibly useful data on the problem. So after downgrading the flutter to the stable (Dart 3.4.4) on a project without macro enabled (i know it should be on like at least "3.5.0-323.1.beta" available on flutter sdk beta channel) it seems to work fine finally. But when in analysis_options.yaml you have macros enabled conflicts happen. F.e. for 3.4.4 where the macros are less mature the package with new lints load correctly, its part works well:

  List<LintRule> getLintRules(CustomLintConfigs configs) => <LintRule>[
      SomeLintTest(),
    ];

But when it comes to using the SomeLintTest() it throws when macros are enabled

A piece of information from custom_lint.log - clearly this has to do with the macros Plugin some_lint_test threw while analyzing C:...toproject...\lib\main.dart: [some_lint_test] 2024-07-27T12:38:07.451808 Null check operator used on a null value [some_lint_test] 2024-07-27T12:38:07.451808 #0 LibraryBuilder._addMacroAugmentation

Btw, the log file gets gradually, pretty fast reeeeaaally big The order in which macros apear in analysis_options.yaml doesn't matter

analyzer:
  plugins:
    - custom_lint
  enable-experiment:
    - macros 

But to remind you when it comes to Dart 3.5.0-323.1.beta the package with lints event doesn't start working (the custom_lint itself does as far as i can recall) getLintRules(CustomLintConfigs configs) is not called (so the more SomeLintTest() run() neithe), no useful logs (?) as far as i remember (There is the socket error popup in VsCode, read earlier info).

So to summarize with improving macros there is increasing conflict between the custom_lint package and the macros.

The bottom line: macros are in conflict with custom_lint package.

rrousselGit commented 3 months ago

This isn't related to macros. custom_lint is currently broken with the latest analyzer

There's a separate issue for that, and it's being worked on. So closing as duplicate

brilliapps commented 3 months ago

Thanks for clarifying and btw for your and other people contribution to this plugin - discovered it recently and it inspires to do amazing things earlier seemed not within the range of what i can do. So the posting this issue reflects my limited understanding what i even i write about :) .