do_not_use_environment
Do not use environment declared variables.
Details
#Using values derived from the environment at compile-time, creates hidden global state and makes applications hard to understand and maintain.
DON'T use fromEnvironment
or hasEnvironment
factory constructors.
BAD:
dart
const loggingLevel =
bool.hasEnvironment('logging') ? String.fromEnvironment('logging') : null;
Enable
#To enable the do_not_use_environment
rule,
add do_not_use_environment
under linter > rules in your
analysis_options.yaml
file:
analysis_options.yaml
yaml
linter:
rules:
- do_not_use_environment
If you're instead using the YAML map syntax to configure linter rules,
add do_not_use_environment: true
under linter > rules:
analysis_options.yaml
yaml
linter:
rules:
do_not_use_environment: true
除非另有说明,文档之所提及适用于 Dart 3.7.1 版本,本页面最后更新时间: 2025-01-27。 查看文档源码 或者 报告页面问题。