Skip to content

Commit

Permalink
Version 3.5.0-89.0.dev
Browse files Browse the repository at this point in the history
Merge c78ad94 into dev
  • Loading branch information
Dart CI committed Apr 23, 2024
2 parents 9f64eec + c78ad94 commit b340d0f
Show file tree
Hide file tree
Showing 7 changed files with 165 additions and 9 deletions.
1 change: 1 addition & 0 deletions pkg/linter/lib/src/extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ extension AstNodeExtension on AstNode {
return switch (self) {
ClassDeclaration() => self.augmentKeyword != null,
ConstructorDeclaration() => self.augmentKeyword != null,
EnumConstantDeclaration() => self.augmentKeyword != null,
EnumDeclaration() => self.augmentKeyword != null,
ExtensionTypeDeclaration() => self.augmentKeyword != null,
FieldDeclaration() => self.augmentKeyword != null,
Expand Down
6 changes: 4 additions & 2 deletions pkg/linter/lib/src/rules/always_declare_return_types.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:analyzer/dart/ast/token.dart';
import 'package:analyzer/dart/ast/visitor.dart';

import '../analyzer.dart';
import '../extensions.dart';

const _desc = r'Declare method return types.';

Expand Down Expand Up @@ -88,7 +89,7 @@ class _Visitor extends SimpleAstVisitor<void> {

@override
void visitFunctionDeclaration(FunctionDeclaration node) {
if (!node.isSetter && node.returnType == null) {
if (!node.isSetter && node.returnType == null && !node.isAugmentation) {
rule.reportLintForToken(node.name,
arguments: [node.name.lexeme], errorCode: functionCode);
}
Expand All @@ -106,7 +107,8 @@ class _Visitor extends SimpleAstVisitor<void> {
void visitMethodDeclaration(MethodDeclaration node) {
if (!node.isSetter &&
node.returnType == null &&
node.name.type != TokenType.INDEX_EQ) {
node.name.type != TokenType.INDEX_EQ &&
!node.isAugmentation) {
rule.reportLintForToken(node.name,
arguments: [node.name.lexeme], errorCode: methodCode);
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/linter/lib/src/rules/constant_identifier_names.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ class _Visitor extends SimpleAstVisitor<void> {

@override
void visitEnumConstantDeclaration(EnumConstantDeclaration node) {
if (node.isAugmentation) return;

checkIdentifier(node.name);
}

Expand Down
2 changes: 2 additions & 0 deletions pkg/linter/test/rules/all.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

// ignore_for_file: library_prefixes

import 'always_declare_return_types_test.dart' as always_declare_return_types;
import 'always_specify_types_test.dart' as always_specify_types;
import 'always_use_package_imports_test.dart' as always_use_package_imports;
import 'annotate_overrides_test.dart' as annotate_overrides;
Expand Down Expand Up @@ -267,6 +268,7 @@ import 'valid_regexps_test.dart' as valid_regexps;
import 'void_checks_test.dart' as void_checks;

void main() {
always_declare_return_types.main();
always_specify_types.main();
always_use_package_imports.main();
annotate_overrides.main();
Expand Down
135 changes: 135 additions & 0 deletions pkg/linter/test/rules/always_declare_return_types_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
// Copyright (c) 2024, 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.

import 'package:test_reflective_loader/test_reflective_loader.dart';

import '../rule_test_support.dart';

main() {
defineReflectiveSuite(() {
defineReflectiveTests(AlwaysDeclareReturnTypesTest);
});
}

@reflectiveTest
class AlwaysDeclareReturnTypesTest extends LintRuleTest {
@override
String get lintRule => 'always_declare_return_types';

test_augmentationClass() async {
var a = newFile('$testPackageLibPath/a.dart', r'''
import augment 'b.dart';
class A { }
''');

var b = newFile('$testPackageLibPath/b.dart', r'''
augment library 'a.dart';
augment class A {
f() { }
}
''');

result = await resolveFile(a.path);
await assertNoDiagnosticsIn(errors);

result = await resolveFile(b.path);
await assertDiagnosticsIn(errors, [
lint(47, 1),
]);
}

test_augmentationTopLevelFunction() async {
var a = newFile('$testPackageLibPath/a.dart', r'''
import augment 'b.dart';
''');

var b = newFile('$testPackageLibPath/b.dart', r'''
augment library 'a.dart';
f() { }
''');

result = await resolveFile(a.path);
await assertNoDiagnosticsIn(errors);

result = await resolveFile(b.path);
await assertDiagnosticsIn(errors, [
lint(27, 1),
]);
}

/// Augmentation target chain variations tested in `augmentedTopLevelFunction{*}`.
test_augmentedMethod() async {
var a = newFile('$testPackageLibPath/a.dart', r'''
import augment 'b.dart';
class A {
f() { }
}
''');

var b = newFile('$testPackageLibPath/b.dart', r'''
augment library 'a.dart';
augment class A {
augment f() { }
}
''');

result = await resolveFile(a.path);
await assertDiagnosticsIn(errors, [
lint(38, 1),
]);

result = await resolveFile(b.path);
await assertNoDiagnosticsIn(errors);
}

test_augmentedTopLevelFunction() async {
var a = newFile('$testPackageLibPath/a.dart', r'''
import augment 'b.dart';
f() { }
''');

var b = newFile('$testPackageLibPath/b.dart', r'''
augment library 'a.dart';
augment f() { }
''');

result = await resolveFile(a.path);
await assertDiagnosticsIn(errors, [
lint(26, 1),
]);

result = await resolveFile(b.path);
await assertNoDiagnosticsIn(errors);
}

test_augmentedTopLevelFunction_chain() async {
var a = newFile('$testPackageLibPath/a.dart', r'''
import augment 'b.dart';
f() { }
''');

var b = newFile('$testPackageLibPath/b.dart', r'''
augment library 'a.dart';
augment dynamic f() { }
augment f() { }
''');

result = await resolveFile(a.path);
await assertDiagnosticsIn(errors, [
lint(26, 1),
]);

result = await resolveFile(b.path);
await assertNoDiagnosticsIn(errors);
}
}
26 changes: 20 additions & 6 deletions pkg/linter/test/rules/constant_identifier_names_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ class ConstantIdentifierNamesTest extends LintRuleTest {
@override
String get lintRule => 'constant_identifier_names';

@FailingTest(
reason: 'error(CompileTimeErrorCode.DUPLICATE_DEFINITION, 40, 1),',
issue: 'https://github.com/dart-lang/linter/issues/4933',
)
test_augmentationEnum() async {
newFile('$testPackageLibPath/a.dart', r'''
import augment 'test.dart';
Expand All @@ -34,10 +30,10 @@ enum E {
augment library 'a.dart';
augment enum E {
X;
Xy;
}
''', [
lint(34, 1),
lint(46, 2),
]);
}

Expand All @@ -55,6 +51,24 @@ const PI = 3.14;
]);
}

test_augmentedEnumValue() async {
newFile('$testPackageLibPath/a.dart', r'''
import augment 'test.dart';
enum E {
Xy;
}
''');

await assertNoDiagnostics(r'''
augment library 'a.dart';
augment enum E {
augment Xy;
}
''');
}

test_augmentedTopLevelVariable() async {
newFile('$testPackageLibPath/a.dart', r'''
import augment 'test.dart';
Expand Down
2 changes: 1 addition & 1 deletion tools/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ CHANNEL dev
MAJOR 3
MINOR 5
PATCH 0
PRERELEASE 88
PRERELEASE 89
PRERELEASE_PATCH 0

0 comments on commit b340d0f

Please sign in to comment.