Skip to content

Commit

Permalink
Version 3.5.0-170.0.dev
Browse files Browse the repository at this point in the history
Merge 9c20217 into dev
  • Loading branch information
Dart CI committed May 18, 2024
2 parents 3c8718d + 9c20217 commit 17b21cb
Show file tree
Hide file tree
Showing 23 changed files with 776 additions and 191 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -513,21 +513,19 @@ class BulkFixProcessor {
break;
}
if (result is ParsedLibraryResult) {
var allUnits = result.units
.map((parsedUnit) =>
LinterContextUnit(parsedUnit.content, parsedUnit.unit))
.toList();
var errorListener = RecordingErrorListener();
for (var linterUnit in allUnits) {
var allUnits = <LinterContextUnit>[];

for (var parsedUnit in result.units) {
var errorReporter = ErrorReporter(
errorListener,
StringSource(linterUnit.content, null),
);
_computeLints(
linterUnit,
allUnits,
errorReporter,
StringSource(parsedUnit.content, null),
);
allUnits.add(LinterContextUnit(
parsedUnit.content, parsedUnit.unit, errorReporter));
}
for (var linterUnit in allUnits) {
_computeLints(linterUnit, allUnits);
}
await _fixErrorsInParsedLibrary(result, errorListener.errors,
stopAfterFirst: stopAfterFirst);
Expand All @@ -540,19 +538,16 @@ class BulkFixProcessor {
return BulkFixRequestResult(builder);
}

void _computeLints(LinterContextUnit currentUnit,
List<LinterContextUnit> allUnits, ErrorReporter errorReporter) {
void _computeLints(
LinterContextUnit currentUnit, List<LinterContextUnit> allUnits) {
var unit = currentUnit.unit;
var nodeRegistry = NodeLintRegistry(false);

var context = LinterContextParsedImpl(allUnits, currentUnit);

var lintRules = syntacticLintCodes
.map((name) => Registry.ruleRegistry.getRule(name))
.nonNulls
.toList();
.nonNulls;
for (var linter in lintRules) {
linter.reporter = errorReporter;
linter.reporter = currentUnit.errorReporter;
linter.registerNodeProcessors(nodeRegistry, context);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ class ReplaceCascadeWithDot extends ResolvedCorrectionProducer {

@override
Future<void> compute(ChangeBuilder builder) async {
var cascadeExpression = node;
AstNode? cascadeExpression = node;
if (cascadeExpression is ExtensionOverride) {
cascadeExpression = cascadeExpression.parent;
}
if (cascadeExpression is! CascadeExpression) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -662,9 +662,7 @@ CompileTimeErrorCode.EXTENSION_OVERRIDE_ACCESS_TO_STATIC_MEMBER:
CompileTimeErrorCode.EXTENSION_OVERRIDE_ARGUMENT_NOT_ASSIGNABLE:
status: noFix
CompileTimeErrorCode.EXTENSION_OVERRIDE_WITH_CASCADE:
status: needsFix
notes: |-
Replace the `..` with `.`.
status: hasFix
CompileTimeErrorCode.EXTENSION_OVERRIDE_WITHOUT_ACCESS:
status: noFix
CompileTimeErrorCode.EXTENSION_TYPE_CONSTRUCTOR_WITH_SUPER_FORMAL_PARAMETER:
Expand Down Expand Up @@ -840,9 +838,7 @@ CompileTimeErrorCode.IMPLICIT_THIS_REFERENCE_IN_INITIALIZER:
CompileTimeErrorCode.IMPLICIT_SUPER_INITIALIZER_MISSING_ARGUMENTS:
status: hasFix
CompileTimeErrorCode.IMPORT_INTERNAL_LIBRARY:
status: needsFix
notes: |-
Remove the import.
status: hasFix
CompileTimeErrorCode.IMPORT_OF_NON_LIBRARY:
status: needsFix
notes: |-
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -934,6 +934,9 @@ final _builtInNonLintProducers = <ErrorCode, List<ProducerGenerator>>{
CompileTimeErrorCode.EXTENSION_OVERRIDE_ACCESS_TO_STATIC_MEMBER: [
ReplaceWithExtensionName.new,
],
CompileTimeErrorCode.EXTENSION_OVERRIDE_WITH_CASCADE: [
ReplaceCascadeWithDot.new,
],
CompileTimeErrorCode.EXTRA_POSITIONAL_ARGUMENTS: [
CreateConstructor.new,
],
Expand Down Expand Up @@ -989,6 +992,9 @@ final _builtInNonLintProducers = <ErrorCode, List<ProducerGenerator>>{
CompileTimeErrorCode.IMPLICIT_SUPER_INITIALIZER_MISSING_ARGUMENTS: [
AddSuperParameter.new,
],
CompileTimeErrorCode.IMPORT_INTERNAL_LIBRARY: [
RemoveUnusedImport.new,
],
CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_EXISTENT_FIELD: [
ChangeTo.field,
CreateField.new,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,8 @@ suggestions

Future<void> test_afterUri_beforeImport_partial_d() async {
await computeSuggestions('''
import "foo" d^ import
import "foo" d^
import
''');
assertResponse(r'''
replacement
Expand All @@ -271,7 +272,9 @@ suggestions

Future<void> test_afterUri_beforeImport_partial_sh() async {
await computeSuggestions('''
import "foo" sh^ import "bar"; import "baz";
import "foo" sh^
import "bar";
import "baz";
''');
assertResponse(r'''
replacement
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ class A1 extends A0 {
}
''');
assertResponse(r'''
location: ObjectPattern_fieldName
locationOpType: ObjectPattern_fieldName
suggestions
f01
Expand Down Expand Up @@ -262,6 +263,7 @@ class A1 extends A0 {
}
''');
assertResponse(r'''
location: ObjectPattern_fieldName
locationOpType: ObjectPattern_fieldName
replacement
left: 1
Expand Down Expand Up @@ -484,6 +486,7 @@ class A1 extends A0 {
}
''');
assertResponse(r'''
location: PatternField_pattern
locationOpType: PatternField_pattern
suggestions
f01
Expand Down Expand Up @@ -723,6 +726,7 @@ class A1 extends A0 {
}
''');
assertResponse(r'''
location: ObjectPattern_fieldName
locationOpType: ObjectPattern_fieldName
replacement
left: 1
Expand Down Expand Up @@ -764,6 +768,7 @@ class A1 extends A0 {
}
''');
assertResponse(r'''
location: ObjectPattern_fieldName
locationOpType: ObjectPattern_fieldName
replacement
right: 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,15 @@ void f() {
''');
}

test_internalLibraryImport() async {
await resolveTestCode('''
import 'dart:_internal';
''');

await assertHasFix('''
''', errorFilter: (e) => e.errorCode == WarningCode.UNUSED_IMPORT);
}

Future<void> test_severalLines() async {
await resolveTestCode('''
import
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,28 @@ class C {
''');
}

Future<void> test_extensionCascade() async {
await resolveTestCode('''
extension E on int {
int get g => 0;
}
f() {
E(3)..g;
}
''');
await assertHasFix('''
extension E on int {
int get g => 0;
}
f() {
E(3).g;
}
''',
errorFilter: (e) =>
e.errorCode.name ==
LintNames.avoid_single_cascade_in_expression_statements);
}

Future<void> test_getter_normalCascade() async {
await resolveTestCode('''
void f(String s) {
Expand Down
27 changes: 14 additions & 13 deletions pkg/analyzer/lib/src/dart/analysis/library_analyzer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -318,17 +318,18 @@ class LibraryAnalyzer {
}

if (_analysisOptions.lint) {
var allUnits = <LinterContextUnit2>[];
for (var unitAnalysis in _libraryUnits.values) {
var linterUnit = LinterContextUnit2(
unitAnalysis.file,
unitAnalysis.unit,
);
unitAnalysis.linterUnit = linterUnit;
allUnits.add(linterUnit);
}
for (var unitAnalysis in _libraryUnits.values) {
_computeLints(unitAnalysis, allUnits);
var analysesToContextUnits = {
for (var unitAnalysis in _libraryUnits.values)
unitAnalysis: LinterContextUnit(
unitAnalysis.file.content,
unitAnalysis.unit,
unitAnalysis.errorReporter,
),
};
var allUnits = analysesToContextUnits.values.toList();
for (var MapEntry(key: unitAnalysis, value: currentUnit)
in analysesToContextUnits.entries) {
_computeLints(unitAnalysis, allUnits, currentUnit);
}
}

Expand All @@ -350,14 +351,14 @@ class LibraryAnalyzer {
void _computeLints(
UnitAnalysis unitAnalysis,
List<LinterContextUnit> allUnits,
LinterContextUnit currentUnit,
) {
// Skip computing lints on macro generated augmentations.
// See: https://github.com/dart-lang/sdk/issues/54875
if (unitAnalysis.file.isMacroAugmentation) return;

var currentUnit = unitAnalysis.linterUnit;
var unit = currentUnit.unit;
var errorReporter = unitAnalysis.errorReporter;
var errorReporter = currentUnit.errorReporter;

var enableTiming = _analysisOptions.enableTiming;
var nodeRegistry = NodeLintRegistry(enableTiming);
Expand Down
2 changes: 0 additions & 2 deletions pkg/analyzer/lib/src/dart/analysis/unit_analysis.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import 'package:analyzer/src/dart/analysis/file_state.dart';
import 'package:analyzer/src/dart/ast/ast.dart';
import 'package:analyzer/src/dart/element/element.dart';
import 'package:analyzer/src/ignore_comments/ignore_info.dart';
import 'package:analyzer/src/lint/linter.dart';

/// Information about a file being analyzed.
class UnitAnalysis {
Expand All @@ -20,7 +19,6 @@ class UnitAnalysis {
final IgnoreInfo ignoreInfo;

late final CompilationUnitElementImpl element;
late final LinterContextUnit2 linterUnit;

UnitAnalysis({
required this.file,
Expand Down
34 changes: 16 additions & 18 deletions pkg/analyzer/lib/src/lint/linter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import 'package:analyzer/error/listener.dart';
import 'package:analyzer/file_system/file_system.dart' as file_system;
import 'package:analyzer/file_system/physical_file_system.dart' as file_system;
import 'package:analyzer/source/line_info.dart';
import 'package:analyzer/src/dart/analysis/file_state.dart';
import 'package:analyzer/src/dart/ast/ast.dart';
import 'package:analyzer/src/dart/ast/token.dart';
import 'package:analyzer/src/dart/constant/compute.dart';
Expand Down Expand Up @@ -269,22 +268,9 @@ class LinterContextUnit {

final CompilationUnit unit;

LinterContextUnit(this.content, this.unit);
}

// TODO(scheglov): This class exists only because there are places in the
// analyzer and analysis server that instantiate [LinterContextUnit]. This
// should not happen, and should be fixed.
class LinterContextUnit2 implements LinterContextUnit {
final FileState file;

@override
final CompilationUnit unit;
final ErrorReporter errorReporter;

LinterContextUnit2(this.file, this.unit);

@override
String get content => file.content;
LinterContextUnit(this.content, this.unit, this.errorReporter);
}

/// Thrown when an error occurs in linting.
Expand Down Expand Up @@ -321,8 +307,9 @@ abstract class LintFilter {
/// Describes a lint rule.
abstract class LintRule implements Comparable<LintRule>, NodeLintRule {
/// Used to report lint warnings.
/// NOTE: this is set by the framework before visit begins.
late ErrorReporter reporter;
/// NOTE: this is set by the framework before any node processors start
/// visiting nodes.
late ErrorReporter _reporter;

/// Description (in markdown format) suitable for display in a detailed lint
/// description.
Expand Down Expand Up @@ -377,6 +364,17 @@ abstract class LintRule implements Comparable<LintRule>, NodeLintRule {
/// The lint codes associated with this lint rule.
List<LintCode> get lintCodes => [lintCode];

@protected
// Protected so that lint rule visitors do not access this directly.
// TODO(srawlins): With the new availability of an ErrorReporter on
// LinterContextUnit, we should probably remove this reporter. But whatever
// the new API would be is not yet decided. It might also change with the
// notion of post-processing lint rules that have access to all unit
// reporters at once.
ErrorReporter get reporter => _reporter;

set reporter(ErrorReporter value) => _reporter = value;

@override
int compareTo(LintRule other) {
var g = group.compareTo(other.group);
Expand Down
Loading

0 comments on commit 17b21cb

Please sign in to comment.