[pkg/vm] analyze using package:lints

Tested: via static analysis on the CI
Change-Id: Icffb8d52001d5099cca3ab1f153d3f6e5300177d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/250770
Commit-Queue: Devon Carew <devoncarew@google.com>
Reviewed-by: Siva Annamalai <asiva@google.com>
This commit is contained in:
Devon Carew 2022-07-07 23:22:49 +00:00 committed by Commit Bot
parent e02bc1fd4d
commit 77c79d678e
17 changed files with 48 additions and 37 deletions

View file

@ -2,6 +2,4 @@
# for details. All rights reserved. Use of this source code is governed by a
# BSD-style license that can be found in the LICENSE file.
analyzer:
exclude:
- tool/**
include: package:lints/core.yaml

View file

@ -511,7 +511,7 @@ void invalidateSources(IncrementalCompilerWrapper compiler, List sourceFiles) {
Future _processExpressionCompilationRequest(request) async {
final SendPort port = request[1];
final int isolateGroupId = request[2];
final dynamic dart_platform_kernel = request[3];
final dynamic dartPlatformKernel = request[3];
final String expression = request[4];
final List<String> definitions = request[5].cast<String>();
final List<String> definitionTypes = request[6].cast<String>();
@ -576,8 +576,8 @@ Future _processExpressionCompilationRequest(request) async {
}
if (!foundDartCore) {
List<int> platformKernel;
if (dart_platform_kernel is List<int>) {
platformKernel = dart_platform_kernel;
if (dartPlatformKernel is List<int>) {
platformKernel = dartPlatformKernel;
} else {
final Uri platformUri = computePlatformBinariesLocation()
.resolve('vm_platform_strong.dill');
@ -983,7 +983,7 @@ FileSystem _buildFileSystem(List sourceFiles, List<int>? platformKernel,
String? multirootFilepaths, String? multirootScheme) {
FileSystem fileSystem = new HttpAwareFileSystem(StandardFileSystem.instance);
if (!sourceFiles.isEmpty || platformKernel != null) {
if (sourceFiles.isNotEmpty || platformKernel != null) {
MemoryFileSystem memoryFileSystem =
new MemoryFileSystem(Uri.parse('file:///'));
for (int i = 0; i < sourceFiles.length ~/ 2; i++) {
@ -1143,17 +1143,17 @@ class _CompilationOk extends CompilationResult {
}
class _CompilationNullSafety extends CompilationResult {
final bool _null_safety;
final bool _nullSafety;
_CompilationNullSafety(this._null_safety) : super._() {}
_CompilationNullSafety(this._nullSafety) : super._() {}
@override
Status get status => Status.ok;
@override
get payload => _null_safety;
get payload => _nullSafety;
String toString() => "_CompilationNullSafety($_null_safety)";
String toString() => "_CompilationNullSafety($_nullSafety)";
}
abstract class _CompilationFail extends CompilationResult {
@ -1198,9 +1198,13 @@ class _CompilationCrash extends _CompilationFail {
}
Future<T> runWithPrintToStderr<T>(Future<T> f()) {
return runZoned(() => new Future<T>(f),
zoneSpecification: new ZoneSpecification(
print: (_1, _2, _3, String line) => stderr.writeln(line)));
return runZoned(
() => new Future<T>(f),
zoneSpecification: new ZoneSpecification(
// ignore: non_constant_identifier_names
print: (_1, _2, _3, String line) => stderr.writeln(line),
),
);
}
int _debugDumpCounter = 0;

View file

@ -248,7 +248,7 @@ class VmTarget extends Target {
arg.value)
..fileOffset = arg.fileOffset;
})), keyType: coreTypes.symbolLegacyRawType)
..isConst = (arguments.named.length == 0)
..isConst = (arguments.named.isEmpty)
..fileOffset = arguments.fileOffset
], types: [
coreTypes.symbolLegacyRawType,
@ -392,7 +392,7 @@ class VmTarget extends Target {
// handling, the current approach seems sufficient.
// The 0-element list must be exactly 'const[]'.
if (elements.length == 0) {
if (elements.isEmpty) {
return new ListLiteral([], typeArgument: typeArgument)..isConst = true;
}

View file

@ -394,11 +394,13 @@ class Matchers {
final _AnyMatcher any = const _AnyMatcher();
// ignore: non_constant_identifier_names
InstructionMatcher Goto(String dest) =>
InstructionMatcher._(op: 'Goto', matchers: {
's': _ListMatcher([_blockRef(dest)])
});
// ignore: non_constant_identifier_names
InstructionMatcher Branch(InstructionMatcher compare,
{String? ifTrue, String? ifFalse}) =>
InstructionMatcher._(op: 'Branch', matchers: {

View file

@ -433,7 +433,8 @@ class ExpressionLifter extends Transformer {
new EqualsCall(expr.right, new BoolLiteral(true),
interfaceTarget: objectEquals,
functionType: objectEquals.getterType as FunctionType))));
var then, otherwise;
Statement then;
Statement? otherwise;
if (expr.operatorEnum == LogicalExpressionOperator.AND) {
then = rightBody;
otherwise = null;

View file

@ -399,7 +399,7 @@ abstract class ContinuationRewriterBase extends RecursiveContinuationRewriter {
static DartType elementTypeFrom(Class containerClass, DartType type) {
if (type is InterfaceType) {
if (type.classNode == containerClass) {
if (type.typeArguments.length == 0) {
if (type.typeArguments.isEmpty) {
return const DynamicType();
} else if (type.typeArguments.length == 1) {
return type.typeArguments[0];

View file

@ -585,7 +585,7 @@ class FfiTransformer extends Transformer {
if (fun.positionalParameters.length != fun.requiredParameterCount) {
return null;
}
if (fun.typeParameters.length != 0) return null;
if (fun.typeParameters.isNotEmpty) return null;
final DartType? returnType = convertNativeTypeToDartType(fun.returnType,
allowCompounds: true, allowHandle: true);

View file

@ -260,15 +260,15 @@ class _FfiDefinitionTransformer extends FfiTransformer {
final nativeTypeCfe = NativeTypeCfe(
this, node.getThisType(coreTypes, Nullability.nonNullable))
as AbiSpecificNativeTypeCfe;
if (nativeTypeCfe.abiSpecificTypes.length == 0) {
if (nativeTypeCfe.abiSpecificTypes.isEmpty) {
// Annotation missing, multiple annotations, or invalid mapping.
diagnosticReporter.report(messageFfiAbiSpecificIntegerMappingInvalid,
node.fileOffset, node.name.length, node.location!.file);
}
if (node.typeParameters.length != 0 ||
node.procedures.where((Procedure e) => !e.isSynthetic).length != 0 ||
node.fields.length != 0 ||
node.redirectingFactories.length != 0 ||
if (node.typeParameters.isNotEmpty ||
node.procedures.where((Procedure e) => !e.isSynthetic).isNotEmpty ||
node.fields.isNotEmpty ||
node.redirectingFactories.isNotEmpty ||
node.constructors.length != 1 ||
!node.constructors.single.isConst) {
// We want exactly one constructor, no other members and no type arguments.
@ -306,7 +306,7 @@ class _FfiDefinitionTransformer extends FfiTransformer {
/// Returns packing if any.
int? _checkCompoundClass(Class node) {
if (node.typeParameters.length > 0) {
if (node.typeParameters.isNotEmpty) {
diagnosticReporter.report(
templateFfiStructGeneric.withArguments(
node.superclass!.name, node.name),
@ -430,7 +430,7 @@ class _FfiDefinitionTransformer extends FfiTransformer {
} else if (isPointerType(type) ||
isCompoundSubtype(type) ||
isArrayType(type)) {
if (nativeTypeAnnos.length != 0) {
if (nativeTypeAnnos.isNotEmpty) {
diagnosticReporter.report(
templateFfiFieldNoAnnotation.withArguments(f.name.text),
f.fileOffset,
@ -632,7 +632,7 @@ class _FfiDefinitionTransformer extends FfiTransformer {
final packingAnnotations = _getPackedAnnotations(node);
final packing =
(!packingAnnotations.isEmpty) ? packingAnnotations.first : null;
(packingAnnotations.isNotEmpty) ? packingAnnotations.first : null;
final compoundType = () {
if (types.whereType<InvalidNativeTypeCfe>().isNotEmpty) {

View file

@ -346,7 +346,7 @@ class FfiNativeTransformer extends FfiTransformer {
// annotation matches.
bool _verifySignatures(Procedure node, FunctionType dartFunctionType,
FunctionType ffiFunctionType, int annotationOffset) {
if (ffiFunctionType.namedParameters.length > 0) {
if (ffiFunctionType.namedParameters.isNotEmpty) {
diagnosticReporter.report(
templateCantHaveNamedParameters.withArguments('FfiNative'),
annotationOffset,

View file

@ -38,7 +38,7 @@ abstract class NativeTypeCfe {
if (arrayDimensions == null) {
throw "Must have array dimensions for ArrayType.";
}
if (arrayDimensions.length == 0) {
if (arrayDimensions.isEmpty) {
throw "Must have a size for this array dimension.";
}
final elementType = transformer.arraySingleElementType(dartType);

View file

@ -94,7 +94,7 @@ class ListFactorySpecializer extends BaseSpecializer {
TreeNode transformListEmptyFactory(StaticInvocation node) {
final args = node.arguments;
assert(args.positional.length == 0);
assert(args.positional.isEmpty);
final bool? growable =
_getConstantOptionalArgument(args, 'growable', false);
if (growable == null) {

View file

@ -1865,7 +1865,7 @@ class _TreeShakerPass2 extends RemovingTransformer {
node.members.length = writeIndex;
// We only retain the extension if at least one member is retained.
assert(node.members.length > 0);
assert(node.members.isNotEmpty);
return node;
}
return removalSentinel!;

View file

@ -319,7 +319,7 @@ class SubtypePair {
// Returns the smallest index 'i' such that 'list.skip(i)' is a prefix of
// 'sublist'.
int findOverlap(List list, List sublist) {
for (int i = 0; i < list.length; ++i)
for (int i = 0; i < list.length; ++i) {
outer:
{
for (int j = 0; j < sublist.length && i + j < list.length; ++j) {
@ -327,6 +327,7 @@ int findOverlap(List list, List sublist) {
}
return i;
}
}
return list.length;
}

View file

@ -20,6 +20,7 @@ dependencies:
dev_dependencies:
expect: any
json_rpc_2: any
lints: any
path: any
test: any
web_socket_channel: any

View file

@ -250,9 +250,13 @@ main() {
hits.add(pos);
}
}
for (int pos in coverage["misses"]) positions.add(pos);
for (int pos in coverage["misses"]) {
positions.add(pos);
}
if (range["possibleBreakpoints"] != null) {
for (int pos in range["possibleBreakpoints"]) positions.add(pos);
for (int pos in range["possibleBreakpoints"]) {
positions.add(pos);
}
}
Map script = scriptIndexToScript[range["scriptIndex"]]!;
Set<int> knownPositions = new Set<int>();

View file

@ -49,9 +49,9 @@ runTestCase(Uri source) async {
}
void main(List<String> args) {
assert(args.length == 0 || args.length == 1);
assert(args.isEmpty || args.length == 1);
String? filter;
if (args.length > 0) {
if (args.isNotEmpty) {
filter = args.first;
}

View file

@ -68,7 +68,7 @@ runTestCase(
}
String? argsTestName(List<String> args) {
if (args.length > 0) {
if (args.isNotEmpty) {
return args.last;
}
return null;