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

Linters installed as regular `dependencies` aren't registered #275

Closed dickermoshe closed 1 month ago

dickermoshe commented 2 months ago

Describe the bug Only lint packages installed as a dev_dependencies have their linters ran

To Reproduce

  1. Install riverpod_lint in dependencies. Not in dev_dependencies
  2. All the lints will be ignored in the IDE and in the CLI

Expected behavior Lints run on all dependencies

Over in drift land we want to use this package to create an awesome linters. We already have tons of packages, and while melos does make it easier (thanks guys), we are trying to keep it down. We rather put he linter in our drift_dev package rather than make an entire new drift_lint package.

Our code generator package, drift_dev is usually installed as a dev_dependencies, however in rare instances there is some code which some users could find useful and they install it in regular dependencies.

However, much to our dismay, it seems that custom_lint only looks or linters in dev_dependencies.

PS: If we add drift_dev to dependencies AND dev_dependencies, we can import drift_dev code into the main project and the linter does work. However we don't want our users to be seeing this nasty thing:

image
rrousselGit commented 2 months ago

It is expected because lints are only used in dev.

I'm not necessarily against changing it.

dickermoshe commented 2 months ago

Thanks @rrousselGit

I'm not very familiar with this codebase. Where would the code which insects the pubspec.yaml file be?

rrousselGit commented 2 months ago

It should be within packages/custom_lint. You can search for Pubspec.parse. We're using https://pub.dev/packages/pubspec_parse for decoding pubspecs, so that should be easy to find and change

dickermoshe commented 2 months ago

You've made this way too easy. Thanks

btw, this package is blowing my mind. Takes like 15 lines of code to write linters. You're the greatest!

dickermoshe commented 2 months ago

This TODO makes it sound like you really DON"T want regular dependencies...

https://github.com/invertase/dart_custom_lint/blob/90365e2c47526587603f9132cf89eb7d352ee057/packages/custom_lint/lib/src/workspace.dart#L947-L983

Does this jog your memory for any reason why it would break something?

rrousselGit commented 2 months ago

It doesn't break anything. It was just done on purpose because the approach of splitting a package into a "dependencies" + "dev_dependency" (so making a drift_lint) can save some bandwidth for users who do not use lints.