do-not-use-environment
Same as do_not_use_environment in Dart lints
- Group
- Style
- Path
lint/style/do-not-use-environment- Default
- Off, opt in
- Origin
- Dart lints
- Rule
- 226 of 512
Disallow reading compilation environment declarations, including type aliases.
Reports invocations of bool.fromEnvironment, int.fromEnvironment,
String.fromEnvironment, and bool.hasEnvironment. Constructor identity
is resolved through type aliases and import prefixes; dot-shorthand
invocations are checked using their expected type. User-defined constructors
with the same names and constructor tear-offs are not reported.
Invalid
import 'dart:core';
import 'dart:core' as core;
const bool debug = bool.fromEnvironment('DEBUG');
const int port = int.fromEnvironment('PORT', defaultValue: 8080);
const String flavor = String.fromEnvironment('FLAVOR');
const bool hasFlavor = bool.hasEnvironment('FLAVOR');
final bool runtimeDebug = new bool.fromEnvironment('DEBUG');
const prefixed = core.String.fromEnvironment('NAME');
const explicitConst = const int.fromEnvironment('LEVEL');
const bool shorthand = .fromEnvironment('SHORT');
class Config {
static const String apiKey = String.fromEnvironment('API_KEY');
final int retries = .fromEnvironment('RETRIES');
}
void main() {
const bool local = bool.fromEnvironment('LOCAL');
print([local, debug, port, flavor, hasFlavor, runtimeDebug, prefixed, explicitConst, shorthand]);
} const bool debug = bool.fromEnvironment('DEBUG');const bool debug = bool.fromEnvironment('DEBUG');const int port = int.fromEnvironment('PORT', defaultValue: 8080);const int port = int.fromEnvironment('PORT', defaultValue: 8080);const String flavor = String.fromEnvironment('FLAVOR');const String flavor = String.fromEnvironment('FLAVOR');const bool hasFlavor = bool.hasEnvironment('FLAVOR');const bool hasFlavor = bool.hasEnvironment('FLAVOR');final bool runtimeDebug = new bool.fromEnvironment('DEBUG');final bool runtimeDebug = new bool.fromEnvironment('DEBUG');const prefixed = core.String.fromEnvironment('NAME');const prefixed = core.String.fromEnvironment('NAME');const explicitConst = const int.fromEnvironment('LEVEL');const explicitConst = const int.fromEnvironment('LEVEL');const bool shorthand = .fromEnvironment('SHORT');class Config { static const String apiKey = String.fromEnvironment('API_KEY'); static const String apiKey = String.fromEnvironment('API_KEY'); final int retries = .fromEnvironment('RETRIES');void main() { const bool local = bool.fromEnvironment('LOCAL');Valid
import 'dart:io';
const bool debug = false;
const int port = 8080;
final String flavor = Platform.environment['FLAVOR'] ?? 'dev';
// A constructor tear-off is not an invocation.
final String Function(String, {String defaultValue}) reader = String.fromEnvironment;
// int.hasEnvironment / String.hasEnvironment do not exist; only bool's is checked.
final parsed = int.parse('42');
final text = String.fromCharCodes([72, 105]);
class Settings {
const Settings.fromEnvironment();
static const Settings settings = Settings.fromEnvironment();
}
void main() {
print([debug, port, flavor, reader, parsed, text, Settings.settings]);
}Configure do-not-use-environment
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"style": {
"do-not-use-environment": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/style/do-not-use-environment: <reason>More style rules
- double-literal-format
double-literal-formatFlags double literals written with redundant or missing digits.
- empty-constructor-bodies
empty_constructor_bodiesrecommendedFlags constructors with an empty block body
{}. - enum-constants-ordering
Flags enum constants whose declared names violate the configured order.
- eol-at-end-of-file
eol_at_end_of_filerecommendedFlags a non-empty file that does not end with exactly one line break.
- extend-equatableequatable
Require Equatable semantics for configured class/file name patterns.
- file-names
file_namesrecommendedEnforces
lowercase_with_underscoresfor source file names. - flutter-style-todos
flutter_style_todosFlags
TODOcomments that do not follow the Flutter style// TODO(username): message, https://URL-to-issue. - format-comment
format-commentFlags comments that are not formatted as complete sentences.