-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[linter] Improve do_not_use_environment lint error message and documentation #60970
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
base: main
Are you sure you want to change the base?
[linter] Improve do_not_use_environment lint error message and documentation #60970
Conversation
Thank you for your contribution! This project uses Gerrit for code reviews. Your pull request has automatically been converted into a code review at: https://dart-review.googlesource.com/c/sdk/+/435744 Please wait for a developer to review your code review at the above link; you can speed up the review if you sign into Gerrit and manually add a reviewer that has recently worked on the relevant code. See CONTRIBUTING.md to learn how to upload changes to Gerrit directly. Additional commits pushed to this PR will update both the PR and the corresponding Gerrit CL. After the review is complete on the CL, your reviewer will merge the CL (automatically closing this PR). |
71af238
to
8fbffe0
Compare
…ntation Replaces confusing "Invalid use of an environment declaration" message with clear, actionable guidance that explains WHY environment constructors should be avoided and WHAT to use instead. Changes: - Problem message: Now includes specific method name and explains it creates "hidden global state" - Correction message: Suggests Platform.environment for runtime access - Documentation: Added comprehensive examples showing both bad and good patterns - Implementation: Pass method name to error message for better specificity - Tests: Fixed test to properly validate message contains specific method name Before: "Invalid use of an environment declaration." After: "Avoid using environment values like 'bool.fromEnvironment' which create hidden global state." The new message clearly explains: 1. WHAT is wrong (creates hidden global state) 2. WHY it's problematic (unpredictable across environments) 3. WHAT to do instead (use Platform.environment) Fixes dart-lang#59203
f5c0df9
to
bf3933c
Compare
https://dart-review.googlesource.com/c/sdk/+/435744 has been updated with the latest commits from this pull request. |
1 similar comment
https://dart-review.googlesource.com/c/sdk/+/435744 has been updated with the latest commits from this pull request. |
Per code review feedback, using a throw statement makes it clear to readers that this case cannot be reached under normal circumstances.
https://dart-review.googlesource.com/c/sdk/+/435744 has been updated with the latest commits from this pull request. |
1 similar comment
https://dart-review.googlesource.com/c/sdk/+/435744 has been updated with the latest commits from this pull request. |
looks like you still have many failing tests. |
i need to relook at my local development environment |
Summary
Improves the
do_not_use_environment
lint rule error message and documentation to be more helpful and actionable.Problem
The current error message is confusing and unhelpful:
Solution
After: "Avoid using environment values like 'bool.hasEnvironment' which create hidden global state."
Key Improvements:
Specific Method Names: Error message now includes the exact method being used (e.g., "bool.hasEnvironment", "String.fromEnvironment")
Clear Explanation: Explains that environment constructors create "hidden global state" which makes code hard to understand and maintain
Actionable Guidance: Suggests using
Platform.environment
for runtime access insteadComprehensive Documentation:
Better Test Coverage: Added tests for all variants and edge cases
Examples
Before
After
Documentation Improvements
Added clear examples in the lint documentation:
BAD:
GOOD:
Files Changed
pkg/linter/messages.yaml
- Updated message and documentationpkg/linter/lib/src/rules/do_not_use_environment.dart
- Pass method name to errorpkg/linter/lib/src/lint_codes.g.dart
- Generated code updatepkg/linter/test/rules/do_not_use_environment_test.dart
- Enhanced test coverageTest Plan
bool.hasEnvironment('APPENGINE_RUNTIME')
)Fixes #59203