Add some recent lint rules to analyzer

Change-Id: I962812880b660dd17c821fb4264da28783fa14ac
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/269441
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
This commit is contained in:
Sam Rawlins 2022-11-14 04:14:40 +00:00 committed by Commit Queue
parent 29c3fea3bf
commit f811d53450
7 changed files with 28 additions and 33 deletions

View file

@ -38,6 +38,12 @@ linter:
- always_use_package_imports
- avoid_dynamic_calls
- avoid_unused_constructor_parameters
# Enable after linter 1.31 is released.
#- collection_methods_unrelated_type
- enable_null_safety
- implicit_call_tearoffs
- library_annotations
- unawaited_futures
- unnecessary_library_directive
- unnecessary_parenthesis
- use_super_parameters

View file

@ -2,8 +2,6 @@
// 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.
library analyzer.parser;
import 'package:_fe_analyzer_shared/src/parser/parser.dart' as fasta;
import 'package:_fe_analyzer_shared/src/parser/type_info.dart' as fasta;
import 'package:analyzer/dart/analysis/features.dart';

View file

@ -10,8 +10,6 @@
// The generator sometimes generates unnecessary 'this' references.
// ignore_for_file: unnecessary_this
library analyzer.src.summary.format;
import 'dart:convert' as convert;
import 'dart:typed_data' as typed_data;

View file

@ -58,7 +58,7 @@ class LibraryMacroApplier {
libraryBuilder.element.accept(collector);
for (final targetElement in collector.targets) {
final targetNode = _linker.elementNodes[targetElement];
final targetNode = _linker.elementNodes[targetElement as ElementImpl];
// TODO(scheglov) support other declarations
if (targetNode is ClassDeclaration) {
await performance.runAsync(

View file

@ -114,13 +114,14 @@ abstract class PartialCodeTest extends AbstractRecoveryTest {
descriptor, suffixes[i], i + 1, head, tail,
featureSet: featureSet);
}
if (descriptor.failing != null) {
var descriptorFailing = descriptor.failing;
if (descriptorFailing != null) {
test('${descriptor.name}_failingList', () {
Set<String> failing = Set.from(descriptor.failing!);
var failing = Set.of(descriptorFailing);
if (includeEof) {
failing.remove('eof');
}
failing.removeAll(suffixes.map((TestSuffix suffix) => suffix.name));
failing.removeAll(suffixes.map((suffix) => suffix.name));
expect(failing, isEmpty,
reason:
'There are tests marked as failing that are not being run');

View file

@ -654,8 +654,6 @@ class _CodeGenerator {
out("// The generator sometimes generates unnecessary 'this' references.");
out('// ignore_for_file: unnecessary_this');
out();
out('library analyzer.src.summary.format;');
out();
out("import 'dart:convert' as convert;");
out("import 'dart:typed_data' as typed_data;");
out();

View file

@ -1,4 +1,3 @@
// @dart = 2.9
// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
// 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.
@ -19,10 +18,10 @@ main(List<String> args) async {
int index = 0;
final int expectedPrefixLength = 'Expected: '.length;
final int actualPrefixLength = 'Actual: '.length;
TestResult currentResult;
TestResult? currentResult;
Map<String, List<TestResult>> testsByExpectedAndActual =
<String, List<TestResult>>{};
Map<String, List<TestResult>> testsByStackTrace =
Map<String?, List<TestResult>> testsByStackTrace =
<String, List<TestResult>>{};
while (index < output.length) {
String currentLine = output[index];
@ -53,7 +52,7 @@ main(List<String> args) async {
}
if (hasStackTrace) {
currentResult.stackTrace = output.sublist(index + 1, endIndex - 2);
String traceLine = currentResult.traceLine;
var traceLine = currentResult.traceLine;
testsByStackTrace
.putIfAbsent(traceLine, () => <TestResult>[])
.add(currentResult);
@ -68,11 +67,9 @@ main(List<String> args) async {
List<String> missingCodes = <String>[];
for (List<TestResult> results in testsByExpectedAndActual.values) {
for (TestResult result in results) {
String message = result.message;
if (message != null) {
if (message.startsWith('Bad state: Unable to convert (')) {
missingCodes.add(message);
}
var message = result.message;
if (message.startsWith('Bad state: Unable to convert (')) {
missingCodes.add(message);
}
}
}
@ -82,15 +79,11 @@ main(List<String> args) async {
List<String> keys = testsByExpectedAndActual.keys.toList();
keys.sort();
for (String key in keys) {
List<TestResult> results = testsByExpectedAndActual[key];
var results = testsByExpectedAndActual[key]!;
results.sort((first, second) => first.testName.compareTo(second.testName));
print('$key (${results.length})');
for (TestResult result in results) {
if (result.message == null) {
print(' ${result.testName}');
} else {
print(' ${result.testName} (${result.message})');
}
print(' ${result.testName} (${result.message})');
}
}
if (missingCodes.isNotEmpty) {
@ -104,12 +97,13 @@ main(List<String> args) async {
if (testsByStackTrace.isNotEmpty) {
print('');
print('Unique stack traces (${testsByStackTrace.length}):');
List<String> keys = testsByStackTrace.keys.toList();
var keys = testsByStackTrace.keys.toList();
keys.sort((first, second) {
return testsByStackTrace[second].length - testsByStackTrace[first].length;
return testsByStackTrace[second]!.length -
testsByStackTrace[first]!.length;
});
for (String traceLine in keys) {
print(' (${testsByStackTrace[traceLine].length}) $traceLine');
for (var traceLine in keys) {
print(' (${testsByStackTrace[traceLine]!.length}) $traceLine');
}
}
}
@ -121,14 +115,14 @@ class TestResult {
String testName;
String expected;
String actual;
String message;
List<String> stackTrace;
late String message;
late List<String> stackTrace;
TestResult(this.testName, this.expected, this.actual);
String get traceLine {
String? get traceLine {
for (int i = 0; i < stackTrace.length; i++) {
String traceLine = stackTrace[i];
var traceLine = stackTrace[i];
if (traceLine.startsWith(framePattern) &&
traceLine.contains('(package:')) {
if (traceLine.contains('ResolutionApplier._get') ||