dart-lang / linter

Linter for Dart.
https://dart.dev/tools/linter-rules
BSD 3-Clause "New" or "Revised" License
629 stars 170 forks source link

`do_not_use_environment` lint message is very confusing ("Invalid use of a declared variable") #4503

Open Hixie opened 1 year ago

Hixie commented 1 year ago

The do_not_use_environment lint tries to catch compile-time use of environment variables, that should be runtime uses. The message, though, is entirely unclear about this. It just says:

Invalid use of a declared variable

For example, here is some code that triggers this lint:

const bool usingAppEngine = bool.hasEnvironment('APPENGINE_RUNTIME');

Also while I'm at it I should observe that the documentation (https://dart-lang.github.io/linter/lints/do_not_use_environment.html) does not give a "GOOD" code snippet.

pq commented 1 year ago

/fyi @parlough @bwilkerson @MaryaBelanger

bwilkerson commented 1 year ago

I might be wrong, but my interpretation of the documentation is that the lint attempts to prevent any use of either fromEnvironment or hasEnvironment without any consideration of whether the use is at compile-time or run-time.

I suspect that the docs could be enhanced, possibly as part of the re-write, to make this more clear. The example might also want to drop the const as I don't think it's important but might be part of what led to the misunderstanding.