proper-from-environment
Same as proper_from_environment in Pyramid Lint
- Group
- Correctness
- Path
lint/correctness/proper-from-environment- Default
- On (recommended)
- Origin
- Pyramid Lint
- Rule
- 424 of 512
Require fromEnvironment to be evaluated in a const context.
Flags a String.fromEnvironment, int.fromEnvironment, or
bool.fromEnvironment invocation that is not in a const context. These
constructors read --dart-define values only when evaluated at compile time;
called at runtime they ignore the environment entirely and silently return
the default, so a missing const turns a configured value into its fallback
with no error. Prefix the call with const, or place it somewhere already
const — a const variable initializer or an annotation argument.
Invalid
final apiUrl = String.fromEnvironment('API_URL');
final debug = bool.fromEnvironment('DEBUG');
final port = int.fromEnvironment('PORT');
String read() => String.fromEnvironment('KEY');
void f() {
var mode = String.fromEnvironment('MODE');
print(mode);
}final apiUrl = String.fromEnvironment('API_URL'); final debug = bool.fromEnvironment('DEBUG'); final port = int.fromEnvironment('PORT'); String read() => String.fromEnvironment('KEY');void f() { var mode = String.fromEnvironment('MODE');Valid
const apiUrl = String.fromEnvironment('API_URL');
const debug = bool.fromEnvironment('DEBUG');
const port = int.fromEnvironment('PORT');
class C {
static const key = String.fromEnvironment('KEY');
}
const list = [
String.fromEnvironment('A'),
String.fromEnvironment('B'),
];
String get env => const String.fromEnvironment('ENV');
class EnvironmentValue {
final String value;
const EnvironmentValue(this.value);
}
@EnvironmentValue(String.fromEnvironment('ANNOTATED'))
void annotated() {}Configure proper-from-environment
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"correctness": {
"proper-from-environment": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/correctness/proper-from-environment: <reason>More correctness rules
- proper-super-init-state
proper_super_init_staterecommendedflutterRequire
super.initState()to be the first statement of a resolved FlutterStatesubclass'sinitStateoverride. - require-super-disposerecommendedflutter
Require
super.dispose()in Flutter State dispose overrides. - sort-pub-dependencies
sort_pub_dependenciescross-fileRequire
pubspec.yamldependency sections to be sorted alphabetically. - test-types-in-equals
test_types_in_equalsrecommendedFlags casting the parameter of
operator ==instead of testing its type. - throw-in-finally
throw_in_finallyrecommendedFlags
throwinside afinallyblock. - type-literal-in-constant-pattern
type_literal_in_constant_patternrecommendedDon't use constant patterns whose expressions have the core
Typetype. - undeclared-dependenciescross-file
Report package imports and exports missing from the enclosing pubspec.
- unnecessary-flutter-importsrecommendedflutter
Disallow unused Flutter framework and
dart:asyncimports.