Enable lint prefer asserts in initializer lists (#12903)
* enable lint prefer_asserts_in_initializer_lists * enable --assert-initializer
This commit is contained in:
parent
a75f003b9c
commit
15601fe55c
@ -109,7 +109,7 @@ linter:
|
|||||||
- package_prefixed_library_names
|
- package_prefixed_library_names
|
||||||
# - parameter_assignments # we do this commonly
|
# - parameter_assignments # we do this commonly
|
||||||
- prefer_adjacent_string_concatenation
|
- prefer_adjacent_string_concatenation
|
||||||
# - prefer_asserts_in_initializer_lists # not yet tested
|
- prefer_asserts_in_initializer_lists
|
||||||
- prefer_collection_literals
|
- prefer_collection_literals
|
||||||
- prefer_conditional_assignment
|
- prefer_conditional_assignment
|
||||||
- prefer_const_constructors
|
- prefer_const_constructors
|
||||||
|
@ -103,7 +103,7 @@ linter:
|
|||||||
- package_prefixed_library_names
|
- package_prefixed_library_names
|
||||||
# - parameter_assignments # we do this commonly
|
# - parameter_assignments # we do this commonly
|
||||||
- prefer_adjacent_string_concatenation
|
- prefer_adjacent_string_concatenation
|
||||||
# - prefer_asserts_in_initializer_lists # not yet tested
|
- prefer_asserts_in_initializer_lists
|
||||||
- prefer_collection_literals
|
- prefer_collection_literals
|
||||||
- prefer_conditional_assignment
|
- prefer_conditional_assignment
|
||||||
- prefer_const_constructors
|
- prefer_const_constructors
|
||||||
|
@ -39,6 +39,7 @@ IF NOT EXIST "%flutter_root%\.git" (
|
|||||||
REM Ensure that bin/cache exists.
|
REM Ensure that bin/cache exists.
|
||||||
IF NOT EXIST "%cache_dir%" MKDIR "%cache_dir%"
|
IF NOT EXIST "%cache_dir%" MKDIR "%cache_dir%"
|
||||||
|
|
||||||
|
SET FLUTTER_TOOL_ARGS=--assert-initializer %FLUTTER_TOOL_ARGS%
|
||||||
REM To debug the tool, you can uncomment the following lines to enable checked mode and set an observatory port:
|
REM To debug the tool, you can uncomment the following lines to enable checked mode and set an observatory port:
|
||||||
REM SET FLUTTER_TOOL_ARGS="--checked %FLUTTER_TOOL_ARGS%"
|
REM SET FLUTTER_TOOL_ARGS="--checked %FLUTTER_TOOL_ARGS%"
|
||||||
REM SET FLUTTER_TOOL_ARGS="%FLUTTER_TOOL_ARGS% --observe=65432"
|
REM SET FLUTTER_TOOL_ARGS="%FLUTTER_TOOL_ARGS% --observe=65432"
|
||||||
|
@ -206,7 +206,8 @@ Future<Null> _pubRunTest(
|
|||||||
final List<String> args = <String>['run', 'test', '-j1', '-rexpanded'];
|
final List<String> args = <String>['run', 'test', '-j1', '-rexpanded'];
|
||||||
if (testPath != null)
|
if (testPath != null)
|
||||||
args.add(testPath);
|
args.add(testPath);
|
||||||
return _runCommand(pub, args, workingDirectory: workingDirectory);
|
return _runCommand(pub, args, workingDirectory: workingDirectory,
|
||||||
|
environment: <String, String>{'DART_VM_OPTIONS': '--assert-initializer'});
|
||||||
}
|
}
|
||||||
|
|
||||||
class EvalResult {
|
class EvalResult {
|
||||||
|
@ -89,6 +89,7 @@ class CupertinoPageRoute<T> extends PageRoute<T> {
|
|||||||
assert(maintainState != null),
|
assert(maintainState != null),
|
||||||
assert(fullscreenDialog != null),
|
assert(fullscreenDialog != null),
|
||||||
super(settings: settings, fullscreenDialog: fullscreenDialog) {
|
super(settings: settings, fullscreenDialog: fullscreenDialog) {
|
||||||
|
// ignore: prefer_asserts_in_initializer_lists , https://github.com/dart-lang/sdk/issues/31223
|
||||||
assert(opaque); // PageRoute makes it return true.
|
assert(opaque); // PageRoute makes it return true.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -642,12 +642,11 @@ abstract class DiagnosticsNode {
|
|||||||
this.showName: true,
|
this.showName: true,
|
||||||
this.showSeparator: true,
|
this.showSeparator: true,
|
||||||
}) : assert(showName != null),
|
}) : assert(showName != null),
|
||||||
assert(showSeparator != null) {
|
assert(showSeparator != null),
|
||||||
// A name ending with ':' indicates that the user forgot that the ':' will
|
// A name ending with ':' indicates that the user forgot that the ':' will
|
||||||
// be automatically added for them when generating descriptions of the
|
// be automatically added for them when generating descriptions of the
|
||||||
// property.
|
// property.
|
||||||
assert(name == null || !name.endsWith(':'), 'Names of diagnostic nodes must not end with colons.');
|
assert(name == null || !name.endsWith(':'), 'Names of diagnostic nodes must not end with colons.');
|
||||||
}
|
|
||||||
|
|
||||||
/// Diagnostics containing just a string `message` and not a concrete name or
|
/// Diagnostics containing just a string `message` and not a concrete name or
|
||||||
/// value.
|
/// value.
|
||||||
@ -1318,15 +1317,14 @@ class FlagProperty extends DiagnosticsProperty<bool> {
|
|||||||
DiagnosticLevel level: DiagnosticLevel.info,
|
DiagnosticLevel level: DiagnosticLevel.info,
|
||||||
}) : assert(showName != null),
|
}) : assert(showName != null),
|
||||||
assert(level != null),
|
assert(level != null),
|
||||||
|
assert(ifTrue != null || ifFalse != null),
|
||||||
super(
|
super(
|
||||||
name,
|
name,
|
||||||
value,
|
value,
|
||||||
showName: showName,
|
showName: showName,
|
||||||
defaultValue: defaultValue,
|
defaultValue: defaultValue,
|
||||||
level: level,
|
level: level,
|
||||||
) {
|
);
|
||||||
assert(ifTrue != null || ifFalse != null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Description to use if the property [value] is true.
|
/// Description to use if the property [value] is true.
|
||||||
///
|
///
|
||||||
|
@ -71,6 +71,7 @@ class MaterialPageRoute<T> extends PageRoute<T> {
|
|||||||
bool fullscreenDialog: false,
|
bool fullscreenDialog: false,
|
||||||
}) : assert(builder != null),
|
}) : assert(builder != null),
|
||||||
super(settings: settings, fullscreenDialog: fullscreenDialog) {
|
super(settings: settings, fullscreenDialog: fullscreenDialog) {
|
||||||
|
// ignore: prefer_asserts_in_initializer_lists , https://github.com/dart-lang/sdk/issues/31223
|
||||||
assert(opaque);
|
assert(opaque);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -411,11 +411,10 @@ abstract class ShapeBorder {
|
|||||||
///
|
///
|
||||||
/// The borders are listed from the outside to the inside.
|
/// The borders are listed from the outside to the inside.
|
||||||
class _CompoundBorder extends ShapeBorder {
|
class _CompoundBorder extends ShapeBorder {
|
||||||
_CompoundBorder(this.borders) {
|
_CompoundBorder(this.borders)
|
||||||
assert(borders != null);
|
: assert(borders != null),
|
||||||
assert(borders.length >= 2);
|
assert(borders.length >= 2),
|
||||||
assert(!borders.any((ShapeBorder border) => border is _CompoundBorder));
|
assert(!borders.any((ShapeBorder border) => border is _CompoundBorder));
|
||||||
}
|
|
||||||
|
|
||||||
final List<ShapeBorder> borders;
|
final List<ShapeBorder> borders;
|
||||||
|
|
||||||
|
@ -220,16 +220,15 @@ class DefaultWidgetsLocalizations implements WidgetsLocalizations {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _LocalizationsScope extends InheritedWidget {
|
class _LocalizationsScope extends InheritedWidget {
|
||||||
_LocalizationsScope ({
|
const _LocalizationsScope ({
|
||||||
Key key,
|
Key key,
|
||||||
@required this.locale,
|
@required this.locale,
|
||||||
@required this.localizationsState,
|
@required this.localizationsState,
|
||||||
@required this.typeToResources,
|
@required this.typeToResources,
|
||||||
Widget child,
|
Widget child,
|
||||||
}) : super(key: key, child: child) {
|
}) : assert(localizationsState != null),
|
||||||
assert(localizationsState != null);
|
assert(typeToResources != null),
|
||||||
assert(typeToResources != null);
|
super(key: key, child: child);
|
||||||
}
|
|
||||||
|
|
||||||
final Locale locale;
|
final Locale locale;
|
||||||
final _LocalizationsState localizationsState;
|
final _LocalizationsState localizationsState;
|
||||||
@ -337,11 +336,10 @@ class Localizations extends StatefulWidget {
|
|||||||
@required this.locale,
|
@required this.locale,
|
||||||
@required this.delegates,
|
@required this.delegates,
|
||||||
this.child,
|
this.child,
|
||||||
}) : super(key: key) {
|
}) : assert(locale != null),
|
||||||
assert(locale != null);
|
assert(delegates != null),
|
||||||
assert(delegates != null);
|
assert(delegates.any((LocalizationsDelegate<dynamic> delegate) => delegate is LocalizationsDelegate<WidgetsLocalizations>)),
|
||||||
assert(delegates.any((LocalizationsDelegate<dynamic> delegate) => delegate is LocalizationsDelegate<WidgetsLocalizations>));
|
super(key: key);
|
||||||
}
|
|
||||||
|
|
||||||
/// Overrides the inherited [Locale] or [LocalizationsDelegate]s for `child`.
|
/// Overrides the inherited [Locale] or [LocalizationsDelegate]s for `child`.
|
||||||
///
|
///
|
||||||
|
@ -39,9 +39,8 @@ class PageStorageKey<T> extends ValueKey<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _StorageEntryIdentifier {
|
class _StorageEntryIdentifier {
|
||||||
_StorageEntryIdentifier(this.keys) {
|
_StorageEntryIdentifier(this.keys)
|
||||||
assert(keys != null);
|
: assert(keys != null);
|
||||||
}
|
|
||||||
|
|
||||||
final List<PageStorageKey<dynamic>> keys;
|
final List<PageStorageKey<dynamic>> keys;
|
||||||
|
|
||||||
|
@ -83,9 +83,8 @@ class PageRouteBuilder<T> extends PageRoute<T> {
|
|||||||
assert(transitionsBuilder != null),
|
assert(transitionsBuilder != null),
|
||||||
assert(barrierDismissible != null),
|
assert(barrierDismissible != null),
|
||||||
assert(maintainState != null),
|
assert(maintainState != null),
|
||||||
super(settings: settings) {
|
assert(opaque != null),
|
||||||
assert(opaque != null);
|
super(settings: settings);
|
||||||
}
|
|
||||||
|
|
||||||
/// Used build the route's primary contents.
|
/// Used build the route's primary contents.
|
||||||
///
|
///
|
||||||
|
@ -33,9 +33,8 @@ final EnumIndex<HealthStatus> _healthStatusIndex =
|
|||||||
/// [FlutterDriver.checkHealth] test.
|
/// [FlutterDriver.checkHealth] test.
|
||||||
class Health extends Result {
|
class Health extends Result {
|
||||||
/// Creates a [Health] object with the given [status].
|
/// Creates a [Health] object with the given [status].
|
||||||
Health(this.status) {
|
Health(this.status)
|
||||||
assert(status != null);
|
: assert(status != null);
|
||||||
}
|
|
||||||
|
|
||||||
/// The status represented by this object.
|
/// The status represented by this object.
|
||||||
///
|
///
|
||||||
|
@ -21,9 +21,8 @@ abstract class ApplicationPackage {
|
|||||||
/// Package ID from the Android Manifest or equivalent.
|
/// Package ID from the Android Manifest or equivalent.
|
||||||
final String id;
|
final String id;
|
||||||
|
|
||||||
ApplicationPackage({ @required this.id }) {
|
ApplicationPackage({ @required this.id })
|
||||||
assert(id != null);
|
: assert(id != null);
|
||||||
}
|
|
||||||
|
|
||||||
String get name;
|
String get name;
|
||||||
|
|
||||||
@ -46,10 +45,9 @@ class AndroidApk extends ApplicationPackage {
|
|||||||
String id,
|
String id,
|
||||||
@required this.apkPath,
|
@required this.apkPath,
|
||||||
@required this.launchActivity
|
@required this.launchActivity
|
||||||
}) : super(id: id) {
|
}) : assert(apkPath != null),
|
||||||
assert(apkPath != null);
|
assert(launchActivity != null),
|
||||||
assert(launchActivity != null);
|
super(id: id);
|
||||||
}
|
|
||||||
|
|
||||||
/// Creates a new AndroidApk from an existing APK.
|
/// Creates a new AndroidApk from an existing APK.
|
||||||
factory AndroidApk.fromApk(String applicationBinary) {
|
factory AndroidApk.fromApk(String applicationBinary) {
|
||||||
|
@ -21,9 +21,8 @@ GenSnapshot get genSnapshot => context.putIfAbsent(GenSnapshot, () => const GenS
|
|||||||
|
|
||||||
/// A snapshot build configuration.
|
/// A snapshot build configuration.
|
||||||
class SnapshotType {
|
class SnapshotType {
|
||||||
SnapshotType(this.platform, this.mode) {
|
SnapshotType(this.platform, this.mode)
|
||||||
assert(mode != null);
|
: assert(mode != null);
|
||||||
}
|
|
||||||
|
|
||||||
final TargetPlatform platform;
|
final TargetPlatform platform;
|
||||||
final BuildMode mode;
|
final BuildMode mode;
|
||||||
|
@ -17,9 +17,8 @@ Flags get flags => context?.getVariable(Flags) ?? const _EmptyFlags();
|
|||||||
/// the Flutter tool (immediately after the arguments have been parsed in
|
/// the Flutter tool (immediately after the arguments have been parsed in
|
||||||
/// [FlutterCommandRunner]) and is available via the [flags] global property.
|
/// [FlutterCommandRunner]) and is available via the [flags] global property.
|
||||||
class Flags {
|
class Flags {
|
||||||
Flags(this._globalResults) {
|
Flags(this._globalResults)
|
||||||
assert(_globalResults != null);
|
: assert(_globalResults != null);
|
||||||
}
|
|
||||||
|
|
||||||
final ArgResults _globalResults;
|
final ArgResults _globalResults;
|
||||||
|
|
||||||
|
@ -177,8 +177,8 @@ class BufferLogger extends Logger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class VerboseLogger extends Logger {
|
class VerboseLogger extends Logger {
|
||||||
VerboseLogger(this.parent) {
|
VerboseLogger(this.parent)
|
||||||
assert(terminal != null);
|
: assert(terminal != null) {
|
||||||
stopwatch.start();
|
stopwatch.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,9 +21,7 @@ class ApkKeystoreInfo {
|
|||||||
this.password,
|
this.password,
|
||||||
this.keyAlias,
|
this.keyAlias,
|
||||||
@required this.keyPassword,
|
@required this.keyPassword,
|
||||||
}) {
|
}) : assert(keystore != null);
|
||||||
assert(keystore != null);
|
|
||||||
}
|
|
||||||
|
|
||||||
final String keystore;
|
final String keystore;
|
||||||
final String password;
|
final String password;
|
||||||
|
@ -297,7 +297,7 @@ Future<Null> _runTests(List<String> testArgs, String observatoryUri) async {
|
|||||||
..add('-rexpanded');
|
..add('-rexpanded');
|
||||||
final String dartVmPath = fs.path.join(dartSdkPath, 'bin', 'dart');
|
final String dartVmPath = fs.path.join(dartSdkPath, 'bin', 'dart');
|
||||||
final int result = await runCommandAndStreamOutput(
|
final int result = await runCommandAndStreamOutput(
|
||||||
<String>[dartVmPath]..addAll(args),
|
<String>[dartVmPath]..addAll(dartVmFlags)..addAll(args),
|
||||||
environment: <String, String>{ 'VM_SERVICE_URL': observatoryUri }
|
environment: <String, String>{ 'VM_SERVICE_URL': observatoryUri }
|
||||||
);
|
);
|
||||||
if (result != 0)
|
if (result != 0)
|
||||||
|
@ -104,8 +104,8 @@ Future<String> compile(
|
|||||||
/// The wrapper is intended to stay resident in memory as user changes, reloads,
|
/// The wrapper is intended to stay resident in memory as user changes, reloads,
|
||||||
/// restarts the Flutter app.
|
/// restarts the Flutter app.
|
||||||
class ResidentCompiler {
|
class ResidentCompiler {
|
||||||
ResidentCompiler(this._sdkRoot) {
|
ResidentCompiler(this._sdkRoot)
|
||||||
assert(_sdkRoot != null);
|
: assert(_sdkRoot != null) {
|
||||||
// This is a URI, not a file path, so the forward slash is correct even on Windows.
|
// This is a URI, not a file path, so the forward slash is correct even on Windows.
|
||||||
if (!_sdkRoot.endsWith('/'))
|
if (!_sdkRoot.endsWith('/'))
|
||||||
_sdkRoot = '$_sdkRoot/';
|
_sdkRoot = '$_sdkRoot/';
|
||||||
|
@ -11,6 +11,9 @@ String get dartSdkPath {
|
|||||||
return fs.path.join(Cache.flutterRoot, 'bin', 'cache', 'dart-sdk');
|
return fs.path.join(Cache.flutterRoot, 'bin', 'cache', 'dart-sdk');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The required Dart language flags
|
||||||
|
const List<String> dartVmFlags = const <String>['--assert-initializer'];
|
||||||
|
|
||||||
/// Return the platform specific name for the given Dart SDK binary. So, `pub`
|
/// Return the platform specific name for the given Dart SDK binary. So, `pub`
|
||||||
/// ==> `pub.bat`. The default SDK location can be overridden with a specified
|
/// ==> `pub.bat`. The default SDK location can be overridden with a specified
|
||||||
/// [sdkLocation].
|
/// [sdkLocation].
|
||||||
|
@ -102,11 +102,10 @@ class FlutterManifest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class Font {
|
class Font {
|
||||||
Font(this.familyName, this.fontAssets) {
|
Font(this.familyName, this.fontAssets)
|
||||||
assert(familyName != null);
|
: assert(familyName != null),
|
||||||
assert(fontAssets != null);
|
assert(fontAssets != null),
|
||||||
assert(fontAssets.isNotEmpty);
|
assert(fontAssets.isNotEmpty);
|
||||||
}
|
|
||||||
|
|
||||||
final String familyName;
|
final String familyName;
|
||||||
final List<FontAsset> fontAssets;
|
final List<FontAsset> fontAssets;
|
||||||
@ -123,9 +122,8 @@ class Font {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class FontAsset {
|
class FontAsset {
|
||||||
FontAsset(this.asset, {this.weight, this.style}) {
|
FontAsset(this.asset, {this.weight, this.style})
|
||||||
assert(asset != null);
|
: assert(asset != null);
|
||||||
}
|
|
||||||
|
|
||||||
final String asset;
|
final String asset;
|
||||||
final int weight;
|
final int weight;
|
||||||
|
@ -18,9 +18,9 @@ class ProtocolDiscovery {
|
|||||||
this.portForwarder,
|
this.portForwarder,
|
||||||
this.hostPort,
|
this.hostPort,
|
||||||
this.defaultHostPort,
|
this.defaultHostPort,
|
||||||
}) : _prefix = '$serviceName listening on ' {
|
}) : assert(logReader != null),
|
||||||
assert(logReader != null);
|
assert(portForwarder == null || defaultHostPort != null),
|
||||||
assert(portForwarder == null || defaultHostPort != null);
|
_prefix = '$serviceName listening on ' {
|
||||||
_deviceLogSubscription = logReader.logLines.listen(_handleLine);
|
_deviceLogSubscription = logReader.logLines.listen(_handleLine);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,9 +88,7 @@ class _FlutterPlatform extends PlatformPlugin {
|
|||||||
this.startPaused,
|
this.startPaused,
|
||||||
this.explicitObservatoryPort,
|
this.explicitObservatoryPort,
|
||||||
this.host,
|
this.host,
|
||||||
}) {
|
}) : assert(shellPath != null);
|
||||||
assert(shellPath != null);
|
|
||||||
}
|
|
||||||
|
|
||||||
final String shellPath;
|
final String shellPath;
|
||||||
final TestWatcher watcher;
|
final TestWatcher watcher;
|
||||||
|
@ -209,12 +209,12 @@ void main() {
|
|||||||
// TODO(pq): enable when sky_shell is available
|
// TODO(pq): enable when sky_shell is available
|
||||||
if (!io.Platform.isWindows) {
|
if (!io.Platform.isWindows) {
|
||||||
// Verify that the sample widget test runs cleanly.
|
// Verify that the sample widget test runs cleanly.
|
||||||
final List<String> args = <String>[
|
final List<String> args = <String>[]
|
||||||
fs.path.absolute(fs.path.join('bin', 'flutter_tools.dart')),
|
..addAll(dartVmFlags)
|
||||||
'test',
|
..add(fs.path.absolute(fs.path.join('bin', 'flutter_tools.dart')))
|
||||||
'--no-color',
|
..add('test')
|
||||||
fs.path.join(projectDir.path, 'test', 'widget_test.dart'),
|
..add('--no-color')
|
||||||
];
|
..add(fs.path.join(projectDir.path, 'test', 'widget_test.dart'));
|
||||||
|
|
||||||
final ProcessResult result = await Process.run(
|
final ProcessResult result = await Process.run(
|
||||||
fs.path.join(dartSdkPath, 'bin', 'dart'),
|
fs.path.join(dartSdkPath, 'bin', 'dart'),
|
||||||
@ -338,7 +338,10 @@ Future<Null> _analyzeProject(String workingDir, {String target}) async {
|
|||||||
'flutter_tools.dart',
|
'flutter_tools.dart',
|
||||||
));
|
));
|
||||||
|
|
||||||
final List<String> args = <String>[flutterToolsPath, 'analyze'];
|
final List<String> args = <String>[]
|
||||||
|
..addAll(dartVmFlags)
|
||||||
|
..add(flutterToolsPath)
|
||||||
|
..add('analyze');
|
||||||
if (target != null)
|
if (target != null)
|
||||||
args.add(target);
|
args.add(target);
|
||||||
|
|
||||||
|
@ -143,11 +143,13 @@ Future<ProcessResult> _runFlutterTest(
|
|||||||
if (!testFile.existsSync())
|
if (!testFile.existsSync())
|
||||||
fail('missing test file: $testFile');
|
fail('missing test file: $testFile');
|
||||||
|
|
||||||
final List<String> args = <String>[
|
final List<String> args = <String>[]
|
||||||
fs.path.absolute(fs.path.join('bin', 'flutter_tools.dart')),
|
..addAll(dartVmFlags)
|
||||||
'test',
|
..add(fs.path.absolute(fs.path.join('bin', 'flutter_tools.dart')))
|
||||||
'--no-color'
|
..add('test')
|
||||||
]..addAll(extraArgs)..add(testFilePath);
|
..add('--no-color')
|
||||||
|
..addAll(extraArgs)
|
||||||
|
..add(testFilePath);
|
||||||
|
|
||||||
while (_testExclusionLock != null)
|
while (_testExclusionLock != null)
|
||||||
await _testExclusionLock;
|
await _testExclusionLock;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user