Skip to content

Commit

Permalink
Version 3.5.0-223.0.dev
Browse files Browse the repository at this point in the history
Merge a451edf into dev
  • Loading branch information
Dart CI committed Jun 4, 2024
2 parents 343c206 + a451edf commit dac7c04
Show file tree
Hide file tree
Showing 28 changed files with 355 additions and 245 deletions.
7 changes: 0 additions & 7 deletions docs/External-Package-Maintenance.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
> [!IMPORTANT]
> This page was copied from https://github.com/dart-lang/sdk/wiki and needs review.
> Please [contribute](../CONTRIBUTING.md) changes to bring it up-to-date -
> removing this header - or send a CL to delete the file.
---

# Versioning Packages

## Bumping versions
Expand Down
2 changes: 1 addition & 1 deletion pkg/analyzer/lib/error/listener.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import 'package:analyzer/src/diagnostic/diagnostic.dart';
import 'package:meta/meta.dart';
import 'package:source_span/source_span.dart';

/// An object that listen for [AnalysisError]s being produced by the analysis
/// An object that listens for [AnalysisError]s being produced by the analysis
/// engine.
abstract class AnalysisErrorListener {
/// An error listener that ignores errors that are reported to it.
Expand Down
4 changes: 3 additions & 1 deletion pkg/analyzer/lib/src/dart/resolver/resolution_visitor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1561,7 +1561,9 @@ class ResolutionVisitor extends RecursiveAstVisitor<void> {
}

void _define(Element element) {
(_nameScope as LocalScope).add(element);
if (_nameScope case LocalScope nameScope) {
nameScope.add(element);
}
}

/// Define given [elements] in the [_nameScope].
Expand Down
19 changes: 0 additions & 19 deletions pkg/analyzer/lib/src/error/annotation_verifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ class AnnotationVerifier {
_checkInternal(node);
} else if (element.isLiteral) {
_checkLiteral(node);
} else if (element.isMustBeOverridden) {
_checkMustBeOverridden(node);
} else if (element.isNonVirtual) {
_checkNonVirtual(node);
} else if (element.isReopen) {
Expand Down Expand Up @@ -204,23 +202,6 @@ class AnnotationVerifier {
}
}

/// Reports a warning [node] if its parent is not a valid target for a
/// `@mustBeOverridden` annotation.
void _checkMustBeOverridden(Annotation node) {
var parent = node.parent;
if ((parent is MethodDeclaration && parent.isStatic) ||
(parent is FieldDeclaration && parent.isStatic) ||
parent.parent is ExtensionDeclaration ||
parent.parent is ExtensionTypeDeclaration ||
parent.parent is EnumDeclaration) {
_errorReporter.atNode(
node.name,
WarningCode.INVALID_ANNOTATION_TARGET,
arguments: [node.name.name, 'instance members of classes and mixins'],
);
}
}

/// Reports a warning at [node] if its parent is not a valid target for a
/// `@nonVirtual` annotation.
void _checkNonVirtual(Annotation node) {
Expand Down
108 changes: 9 additions & 99 deletions pkg/analyzer/lib/src/lint/linter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.

import 'dart:io';

import 'package:analyzer/dart/ast/token.dart';
import 'package:analyzer/dart/constant/value.dart';
import 'package:analyzer/dart/element/element.dart';
Expand All @@ -12,9 +10,6 @@ import 'package:analyzer/dart/element/type_system.dart';
import 'package:analyzer/diagnostic/diagnostic.dart';
import 'package:analyzer/error/error.dart';
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/ast/ast.dart';
import 'package:analyzer/src/dart/ast/token.dart';
import 'package:analyzer/src/dart/constant/compute.dart';
Expand All @@ -27,10 +22,7 @@ import 'package:analyzer/src/dart/element/element.dart';
import 'package:analyzer/src/dart/element/inheritance_manager3.dart';
import 'package:analyzer/src/dart/element/type_system.dart';
import 'package:analyzer/src/error/codes.dart';
import 'package:analyzer/src/generated/engine.dart'
show AnalysisErrorInfo, AnalysisErrorInfoImpl;
import 'package:analyzer/src/lint/analysis.dart';
import 'package:analyzer/src/lint/io.dart';
import 'package:analyzer/src/lint/linter_visitor.dart' show NodeLintRegistry;
import 'package:analyzer/src/lint/pub.dart';
import 'package:analyzer/src/lint/registry.dart';
Expand All @@ -43,82 +35,6 @@ export 'package:analyzer/src/lint/linter_visitor.dart' show NodeLintRegistry;
export 'package:analyzer/src/lint/state.dart'
show dart2_12, dart3, dart3_3, State;

typedef Printer = void Function(String msg);

/// Dart source linter, only for package:linter's tools and tests.
class DartLinter implements AnalysisErrorListener {
final errors = <AnalysisError>[];

final LinterOptions options;
final file_system.ResourceProvider _resourceProvider;
final Reporter reporter;

/// The total number of sources that were analyzed. Only valid after
/// [lintFiles] has been called.
late int numSourcesAnalyzed;

DartLinter(
this.options, {
file_system.ResourceProvider? resourceProvider,
this.reporter = const PrintingReporter(),
}) : _resourceProvider =
resourceProvider ?? file_system.PhysicalResourceProvider.INSTANCE;

Future<Iterable<AnalysisErrorInfo>> lintFiles(List<File> files) async {
List<AnalysisErrorInfo> errors = [];
var lintDriver = LintDriver(options, _resourceProvider);
errors.addAll(await lintDriver.analyze(files.where((f) => isDartFile(f))));
numSourcesAnalyzed = lintDriver.numSourcesAnalyzed;
files.where((f) => isPubspecFile(f)).forEach((path) {
numSourcesAnalyzed++;
var errorsForFile = lintPubspecSource(
contents: path.readAsStringSync(),
sourcePath: _resourceProvider.pathContext.normalize(path.absolute.path),
);
errors.addAll(errorsForFile);
});
return errors;
}

@visibleForTesting
Iterable<AnalysisErrorInfo> lintPubspecSource(
{required String contents, String? sourcePath}) {
var results = <AnalysisErrorInfo>[];

var sourceUrl = sourcePath == null ? null : p.toUri(sourcePath);

var spec = Pubspec.parse(contents, sourceUrl: sourceUrl);

for (var lint in options.enabledRules) {
var rule = lint;
var visitor = rule.getPubspecVisitor();
if (visitor != null) {
// Analyzer sets reporters; if this file is not being analyzed,
// we need to set one ourselves. (Needless to say, when pubspec
// processing gets pushed down, this hack can go away.)
if (sourceUrl != null) {
var source = createSource(sourceUrl);
rule.reporter = ErrorReporter(this, source);
}
try {
spec.accept(visitor);
} on Exception catch (e) {
reporter.exception(LinterException(e.toString()));
}
if (rule._locationInfo.isNotEmpty) {
results.addAll(rule._locationInfo);
rule._locationInfo.clear();
}
}
}

return results;
}

@override
void onError(AnalysisError error) => errors.add(error);
}

class Group implements Comparable<Group> {
/// Defined rule groups.
static const Group errors =
Expand All @@ -134,11 +50,16 @@ class Group implements Comparable<Group> {
'https://dart.dev/guides/language/effective-dart/style'));

/// List of builtin groups in presentation order.
@visibleForTesting
static const Iterable<Group> builtin = [errors, style, pub];

final String name;

@visibleForTesting
final bool custom;

final String description;

final Hyperlink? link;

factory Group(String name, {String description = '', Hyperlink? link}) {
Expand Down Expand Up @@ -349,11 +270,6 @@ abstract class LintRule implements Comparable<LintRule>, NodeLintRule {
/// messages page.
final bool hasDocumentation;

/// Until pubspec analysis is pushed into the analyzer proper, we need to
/// do some extra book-keeping to keep track of details that will help us
/// constitute AnalysisErrorInfos.
final List<AnalysisErrorInfo> _locationInfo = <AnalysisErrorInfo>[];

/// The state of a lint, and optionally since when the state began.
final State state;

Expand Down Expand Up @@ -456,21 +372,15 @@ abstract class LintRule implements Comparable<LintRule>, NodeLintRule {
{List<Object> arguments = const [],
List<DiagnosticMessage> contextMessages = const [],
ErrorCode? errorCode}) {
var source = node.source;
// Cache error and location info for creating AnalysisErrorInfos
AnalysisError error = AnalysisError.tmp(
source: source,
// Cache error and location info for creating `AnalysisErrorInfo`s.
var error = AnalysisError.tmp(
source: node.source,
offset: node.span.start.offset,
length: node.span.length,
errorCode: errorCode ?? lintCode,
arguments: arguments,
contextMessages: contextMessages,
);
LineInfo lineInfo = LineInfo.fromContent(source.contents.data);

_locationInfo.add(AnalysisErrorInfoImpl([error], lineInfo));

// Then do the reporting
reporter.reportError(error);
}
}
Expand All @@ -487,7 +397,7 @@ abstract class NodeLintRule {
}

class PrintingReporter implements Reporter {
final Printer _print;
final void Function(String msg) _print;

const PrintingReporter([this._print = print]);

Expand Down
5 changes: 1 addition & 4 deletions pkg/analyzer/lib/src/test_utilities/mock_packages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,7 @@ class _MustBeConst {
}
@Target({
TargetKind.field,
TargetKind.getter,
TargetKind.method,
TargetKind.setter,
TargetKind.overridableMember,
})
class _MustBeOverridden {
const _MustBeOverridden();
Expand Down
8 changes: 8 additions & 0 deletions pkg/analyzer/test/generated/invalid_code_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,14 @@ extension on int {}
''');
}

test_issue_52363() async {
await _assertCanBeAnalyzed(r'''
class A {
const a = (var b,) = (0,);
}
''');
}

test_issue_52432() async {
await _assertCanBeAnalyzed(r'''
void f() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ class PubPackageResolutionTest extends ContextResolutionTest
List<String> get experiments {
return [
Feature.macros.enableString,
Feature.wildcard_variables.enableString,
];
}

Expand Down Expand Up @@ -633,10 +634,3 @@ mixin WithStrictCastsMixin on PubPackageResolutionTest {
Future<void> assertNoErrorsWithStrictCasts(String code) async =>
assertErrorsWithStrictCasts(code, []);
}

// TODO(pq): revisit, https://dart-review.googlesource.com/c/sdk/+/368880
mixin WithWildCardVariablesMixin on PubPackageResolutionTest {
@override
List<String> get experiments =>
[...super.experiments, Feature.wildcard_variables.enableString];
}
32 changes: 14 additions & 18 deletions pkg/analyzer/test/src/diagnostics/dead_code_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import '../dart/resolution/context_collection_resolution.dart';
main() {
defineReflectiveSuite(() {
defineReflectiveTests(DeadCodeTest);
defineReflectiveTests(DeadCodeWildcardVariablesTest);
defineReflectiveTests(DeadCodeTest_Language219);
});
}
Expand Down Expand Up @@ -140,12 +139,25 @@ void f(int a) {

test_localFunction_wildcard() async {
await assertErrorsInCode(r'''
void f() {
_(){}
}
''', [
error(WarningCode.DEAD_CODE, 13, 5),
]);
}

test_localFunction_wildcard_preWildcards() async {
await assertErrorsInCode(r'''
// @dart = 3.4
// (pre wildcard-variables)
void f() {
_(){}
}
''', [
// No dead code.
error(WarningCode.UNUSED_ELEMENT, 13, 1),
error(WarningCode.UNUSED_ELEMENT, 57, 1),
]);
}

Expand Down Expand Up @@ -1756,19 +1768,3 @@ Iterable<int> f() sync* {
]);
}
}

// TODO(pq): inline this test once we've sorted out how we want to use language overrides for experiment testing
@reflectiveTest
class DeadCodeWildcardVariablesTest extends DeadCodeTest
with WithWildCardVariablesMixin {
@override
test_localFunction_wildcard() async {
await assertErrorsInCode(r'''
void f() {
_(){}
}
''', [
error(WarningCode.DEAD_CODE, 13, 5),
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -157,19 +157,6 @@ extension E on String {
]);
}

test_extensionType_instance_method() async {
await assertErrorsInCode(r'''
import 'package:meta/meta.dart';
extension type E(int i) {
@mustBeOverridden
void m() { }
}
''', [
error(WarningCode.INVALID_ANNOTATION_TARGET, 63, 16),
]);
}

test_mixin_instance_method() async {
await assertNoErrorsInCode(r'''
import 'package:meta/meta.dart';
Expand Down
Loading

0 comments on commit dac7c04

Please sign in to comment.