Turn on the "isEmpty" and "isNotEmpty" lints and fix violations.

Change-Id: Ia6d957ebcc2b19f8043fa58f0c6e2202b2c1104f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/160982
Commit-Queue: Bob Nystrom <rnystrom@google.com>
Auto-Submit: Bob Nystrom <rnystrom@google.com>
Reviewed-by: Karl Klose <karlklose@google.com>
This commit is contained in:
Robert Nystrom 2020-08-31 18:33:48 +00:00 committed by commit-bot@chromium.org
parent 4e7848d17a
commit 8b21a49f61
14 changed files with 21 additions and 21 deletions

View file

@ -8,8 +8,6 @@ linter:
# - non_constant_identifier_names # - non_constant_identifier_names
# - only_throw_errors # - only_throw_errors
# - prefer_interpolation_to_compose_strings # - prefer_interpolation_to_compose_strings
# - prefer_is_empty
# - prefer_is_not_empty
# - prefer_single_quotes # - prefer_single_quotes
- avoid_bool_literals_in_conditional_expressions - avoid_bool_literals_in_conditional_expressions
- avoid_empty_else - avoid_empty_else
@ -60,6 +58,8 @@ linter:
- prefer_final_fields - prefer_final_fields
- prefer_generic_function_type_aliases - prefer_generic_function_type_aliases
- prefer_initializing_formals - prefer_initializing_formals
- prefer_is_empty
- prefer_is_not_empty
- prefer_null_aware_operators - prefer_null_aware_operators
- prefer_typing_uninitialized_variables - prefer_typing_uninitialized_variables
- recursive_getters - recursive_getters

View file

@ -382,7 +382,7 @@ class AdbDevicePool {
static Future<AdbDevicePool> create() async { static Future<AdbDevicePool> create() async {
var names = await AdbHelper.listDevices(); var names = await AdbHelper.listDevices();
var devices = names.map((id) => AdbDevice(id)).toList(); var devices = names.map((id) => AdbDevice(id)).toList();
if (devices.length == 0) { if (devices.isEmpty) {
throw Exception('No android devices found. ' throw Exception('No android devices found. '
'Please make sure "adb devices" shows your device!'); 'Please make sure "adb devices" shows your device!');
} }

View file

@ -54,7 +54,7 @@ String pathToJSIdentifier(String path) {
/// Escape [name] to make it into a valid identifier. /// Escape [name] to make it into a valid identifier.
String _toJSIdentifier(String name) { String _toJSIdentifier(String name) {
if (name.length == 0) return r'$'; if (name.isEmpty) return r'$';
// Escape any invalid characters // Escape any invalid characters
StringBuffer buffer; StringBuffer buffer;

View file

@ -1105,7 +1105,7 @@ class BrowserTestRunner {
} }
void printDoubleReportingTests() { void printDoubleReportingTests() {
if (doubleReportingOutputs.length == 0) return; if (doubleReportingOutputs.isEmpty) return;
// TODO(ricow): die on double reporting. // TODO(ricow): die on double reporting.
// Currently we just report this here, we could have a callback to the // Currently we just report this here, we could have a callback to the
// encapsulating environment. // encapsulating environment.

View file

@ -504,7 +504,7 @@ compiler.''',
case _OptionValueType.string: case _OptionValueType.string:
// Validate against the allowed values. // Validate against the allowed values.
if (!option.values.isEmpty) { if (option.values.isNotEmpty) {
validate(String value) { validate(String value) {
if (!option.values.contains(value)) { if (!option.values.contains(value)) {
_fail('Unknown value "$value" for option "$command".'); _fail('Unknown value "$value" for option "$command".');

View file

@ -200,7 +200,7 @@ class Path {
var isAbs = isAbsolute; var isAbs = isAbsolute;
var segs = segments(); var segs = segments();
String drive; String drive;
if (isAbs && !segs.isEmpty && segs[0].length == 2 && segs[0][1] == ':') { if (isAbs && segs.isNotEmpty && segs[0].length == 2 && segs[0][1] == ':') {
drive = segs[0]; drive = segs[0];
segs.removeRange(0, 1); segs.removeRange(0, 1);
} }

View file

@ -405,7 +405,7 @@ class CommandQueue {
void _tryRunNextCommand() { void _tryRunNextCommand() {
_checkDone(); _checkDone();
if (_numProcesses < _maxProcesses && !_runQueue.isEmpty) { if (_numProcesses < _maxProcesses && _runQueue.isNotEmpty) {
var command = _runQueue.removeFirst(); var command = _runQueue.removeFirst();
var isBrowserCommand = command is BrowserTestCommand; var isBrowserCommand = command is BrowserTestCommand;

View file

@ -143,7 +143,7 @@ Future<Null> killSafari({Uri bundle}) async {
if (result.exitCode == 0) { if (result.exitCode == 0) {
var stdout = result.stdout as String; var stdout = result.stdout as String;
var pids = var pids =
stdout.split("\n").where((String line) => !line.isEmpty).toList(); stdout.split("\n").where((String line) => line.isNotEmpty).toList();
var timer = Timer(const Duration(seconds: 10), () { var timer = Timer(const Duration(seconds: 10), () {
print("Kill -9 Safari $pids"); print("Kill -9 Safari $pids");
kill(pids, force: true); kill(pids, force: true);

View file

@ -113,7 +113,7 @@ class TestCase {
} }
CommandOutput get lastCommandOutput { CommandOutput get lastCommandOutput {
if (commandOutputs.length == 0) { if (commandOutputs.isEmpty) {
throw Exception("CommandOutputs is empty, maybe no command was run? (" throw Exception("CommandOutputs is empty, maybe no command was run? ("
"displayName: '$displayName', " "displayName: '$displayName', "
"configurationString: '$configurationString')"); "configurationString: '$configurationString')");
@ -122,7 +122,7 @@ class TestCase {
} }
Command get lastCommandExecuted { Command get lastCommandExecuted {
if (commandOutputs.length == 0) { if (commandOutputs.isEmpty) {
throw Exception("CommandOutputs is empty, maybe no command was run? (" throw Exception("CommandOutputs is empty, maybe no command was run? ("
"displayName: '$displayName', " "displayName: '$displayName', "
"configurationString: '$configurationString')"); "configurationString: '$configurationString')");

View file

@ -254,7 +254,7 @@ Future testConfigurations(List<TestConfiguration> configurations) async {
} }
// Start all the HTTP servers required before starting the process queue. // Start all the HTTP servers required before starting the process queue.
if (!serverFutures.isEmpty) { if (serverFutures.isNotEmpty) {
await Future.wait(serverFutures); await Future.wait(serverFutures);
} }

View file

@ -595,14 +595,14 @@ class StandardTestSuite extends TestSuite {
var commonArguments = _commonArgumentsFromFile(testFile); var commonArguments = _commonArgumentsFromFile(testFile);
var vmOptionsList = getVmOptions(testFile); var vmOptionsList = getVmOptions(testFile);
assert(!vmOptionsList.isEmpty); assert(vmOptionsList.isNotEmpty);
for (var vmOptionsVariant = 0; for (var vmOptionsVariant = 0;
vmOptionsVariant < vmOptionsList.length; vmOptionsVariant < vmOptionsList.length;
vmOptionsVariant++) { vmOptionsVariant++) {
var vmOptions = vmOptionsList[vmOptionsVariant]; var vmOptions = vmOptionsList[vmOptionsVariant];
var allVmOptions = vmOptions; var allVmOptions = vmOptions;
if (!extraVmOptions.isEmpty) { if (extraVmOptions.isNotEmpty) {
allVmOptions = vmOptions.toList()..addAll(extraVmOptions); allVmOptions = vmOptions.toList()..addAll(extraVmOptions);
} }
@ -623,7 +623,7 @@ class StandardTestSuite extends TestSuite {
var commonArguments = _commonArgumentsFromFile(testFile); var commonArguments = _commonArgumentsFromFile(testFile);
var vmOptionsList = getVmOptions(testFile); var vmOptionsList = getVmOptions(testFile);
assert(!vmOptionsList.isEmpty); assert(vmOptionsList.isNotEmpty);
var emitDdsTest = false; var emitDdsTest = false;
for (var i = 0; i < 2; ++i) { for (var i = 0; i < 2; ++i) {
@ -632,7 +632,7 @@ class StandardTestSuite extends TestSuite {
vmOptionsVariant++) { vmOptionsVariant++) {
var vmOptions = vmOptionsList[vmOptionsVariant]; var vmOptions = vmOptionsList[vmOptionsVariant];
var allVmOptions = vmOptions; var allVmOptions = vmOptions;
if (!extraVmOptions.isEmpty) { if (extraVmOptions.isNotEmpty) {
allVmOptions = vmOptions.toList()..addAll(extraVmOptions); allVmOptions = vmOptions.toList()..addAll(extraVmOptions);
} }
if (emitDdsTest) { if (emitDdsTest) {

View file

@ -241,7 +241,7 @@ class TestingServers {
Uri _getFileUriFromRequestUri(Uri request) { Uri _getFileUriFromRequestUri(Uri request) {
// Go to the top of the file to see an explanation of the URL path scheme. // Go to the top of the file to see an explanation of the URL path scheme.
var pathSegments = request.normalizePath().pathSegments; var pathSegments = request.normalizePath().pathSegments;
if (pathSegments.length == 0) return null; if (pathSegments.isEmpty) return null;
var packagesIndex = pathSegments.indexOf('packages'); var packagesIndex = pathSegments.indexOf('packages');
if (packagesIndex != -1) { if (packagesIndex != -1) {
var packageUri = Uri( var packageUri = Uri(

View file

@ -50,7 +50,7 @@ class Parser {
}); });
// Parse the args. // Parse the args.
while (args.length > 0) { while (args.isNotEmpty) {
if (current == '--') { if (current == '--') {
// Reached the argument terminator, so stop here. // Reached the argument terminator, so stop here.
args.removeAt(0); args.removeAt(0);
@ -98,7 +98,7 @@ class Parser {
/// that there is a valid value there. /// that there is a valid value there.
void readNextArgAsValue(Option option) { void readNextArgAsValue(Option option) {
// Take the option argument from the next command line arg. // Take the option argument from the next command line arg.
validate(args.length > 0, 'Missing argument for "${option.name}".'); validate(args.isNotEmpty, 'Missing argument for "${option.name}".');
// Make sure it isn't an option itself. // Make sure it isn't an option itself.
validate(!_ABBR_OPT.hasMatch(current) && !_LONG_OPT.hasMatch(current), validate(!_ABBR_OPT.hasMatch(current) && !_LONG_OPT.hasMatch(current),

View file

@ -144,11 +144,11 @@ class Usage {
var lines = text.split('\n'); var lines = text.split('\n');
// Strip leading and trailing empty lines. // Strip leading and trailing empty lines.
while (lines.length > 0 && lines[0].trim() == '') { while (lines.isNotEmpty && lines[0].trim() == '') {
lines.removeRange(0, 1); lines.removeRange(0, 1);
} }
while (lines.length > 0 && lines[lines.length - 1].trim() == '') { while (lines.isNotEmpty && lines[lines.length - 1].trim() == '') {
lines.removeLast(); lines.removeLast();
} }