Skip to content

Commit 7a372bb

Browse files
bwilkersonCommit Queue
authored andcommitted
Remove support for diagnostics related to the required annotation
The annotation has been marked as deprecated for a long time now, and the annotation hasn't been useful since 2.12. Change-Id: Ia3bb019ef3fc6b1f9bb406cb268dcc6b78bf1159 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/451403 Commit-Queue: Brian Wilkerson <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]>
1 parent a3b6333 commit 7a372bb

File tree

11 files changed

+1
-407
lines changed

11 files changed

+1
-407
lines changed

pkg/analysis_server/lib/src/services/correction/error_fix_status.yaml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2496,7 +2496,7 @@ LintCode.unnecessary_to_list_in_spreads:
24962496
LintCode.unnecessary_unawaited:
24972497
status: hasFix
24982498
LintCode.unnecessary_underscores:
2499-
status: hasFix
2499+
status: hasFix
25002500
LintCode.unreachable_from_main:
25012501
status: hasFix
25022502
LintCode.unrelated_type_equality_checks_in_expression:
@@ -3673,12 +3673,6 @@ WarningCode.INVALID_OVERRIDE_OF_NON_VIRTUAL_MEMBER:
36733673
status: noFix
36743674
WarningCode.INVALID_REOPEN_ANNOTATION:
36753675
status: hasFix
3676-
WarningCode.INVALID_REQUIRED_NAMED_PARAM:
3677-
status: hasFix
3678-
WarningCode.INVALID_REQUIRED_OPTIONAL_POSITIONAL_PARAM:
3679-
status: hasFix
3680-
WarningCode.INVALID_REQUIRED_POSITIONAL_PARAM:
3681-
status: hasFix
36823676
WarningCode.INVALID_USE_OF_DO_NOT_SUBMIT_MEMBER:
36833677
status: needsEvaluation
36843678
WarningCode.INVALID_USE_OF_INTERNAL_MEMBER:

pkg/analysis_server/lib/src/services/correction/fix_internal.dart

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,9 +1156,6 @@ final _builtInNonLintGenerators = <DiagnosticCode, List<ProducerGenerator>>{
11561156
WarningCode.invalidLiteralAnnotation: [RemoveAnnotation.new],
11571157
WarningCode.invalidNonVirtualAnnotation: [RemoveAnnotation.new],
11581158
WarningCode.invalidReopenAnnotation: [RemoveAnnotation.new],
1159-
WarningCode.invalidRequiredNamedParam: [RemoveAnnotation.new],
1160-
WarningCode.invalidRequiredOptionalPositionalParam: [RemoveAnnotation.new],
1161-
WarningCode.invalidRequiredPositionalParam: [RemoveAnnotation.new],
11621159
WarningCode.invalidVisibilityAnnotation: [RemoveAnnotation.new],
11631160
WarningCode.invalidVisibleForOverridingAnnotation: [RemoveAnnotation.new],
11641161
WarningCode.missingOverrideOfMustBeOverriddenOne: [

pkg/analysis_server/test/src/services/correction/fix/remove_annotation_test.dart

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -290,45 +290,6 @@ base class B extends A {}
290290
''');
291291
}
292292

293-
Future<void> test_required_namedWithDefault() async {
294-
await resolveTestCode('''
295-
import 'package:meta/meta.dart';
296-
297-
f({@required int x = 0}) {}
298-
''');
299-
await assertHasFix('''
300-
import 'package:meta/meta.dart';
301-
302-
f({int x = 0}) {}
303-
''');
304-
}
305-
306-
Future<void> test_required_positional() async {
307-
await resolveTestCode('''
308-
import 'package:meta/meta.dart';
309-
310-
f([@required int? x]) {}
311-
''');
312-
await assertHasFix('''
313-
import 'package:meta/meta.dart';
314-
315-
f([int? x]) {}
316-
''');
317-
}
318-
319-
Future<void> test_required_required() async {
320-
await resolveTestCode('''
321-
import 'package:meta/meta.dart';
322-
323-
f(@required int x) {}
324-
''');
325-
await assertHasFix('''
326-
import 'package:meta/meta.dart';
327-
328-
f(int x) {}
329-
''');
330-
}
331-
332293
Future<void> test_sealed() async {
333294
await resolveTestCode('''
334295
import 'package:meta/meta.dart';

pkg/analyzer/lib/src/diagnostic/diagnostic_code_values.g.dart

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,9 +1048,6 @@ const List<DiagnosticCode> diagnosticCodeValues = [
10481048
WarningCode.invalidNonVirtualAnnotation,
10491049
WarningCode.invalidOverrideOfNonVirtualMember,
10501050
WarningCode.invalidReopenAnnotation,
1051-
WarningCode.invalidRequiredNamedParam,
1052-
WarningCode.invalidRequiredOptionalPositionalParam,
1053-
WarningCode.invalidRequiredPositionalParam,
10541051
WarningCode.invalidUseOfDoNotSubmitMember,
10551052
WarningCode.invalidUseOfInternalMember,
10561053
WarningCode.invalidUseOfProtectedMember,

pkg/analyzer/lib/src/error/best_practices_verifier.dart

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -507,12 +507,6 @@ class BestPracticesVerifier extends RecursiveAstVisitor<void> {
507507
super.visitFieldFormalParameter(node);
508508
}
509509

510-
@override
511-
void visitFormalParameterList(FormalParameterList node) {
512-
_checkRequiredParameter(node);
513-
super.visitFormalParameterList(node);
514-
}
515-
516510
@override
517511
void visitFunctionDeclaration(FunctionDeclaration node) {
518512
bool wasInDoNotStoreMember = _inDoNotStoreMember;
@@ -1494,39 +1488,6 @@ class BestPracticesVerifier extends RecursiveAstVisitor<void> {
14941488
}
14951489
}
14961490

1497-
void _checkRequiredParameter(FormalParameterList node) {
1498-
var requiredParameters = node.parameters.where(
1499-
(p) => p.declaredFragment?.element.metadata.hasRequired == true,
1500-
);
1501-
var nonNamedParamsWithRequired = requiredParameters.where(
1502-
(p) => p.isPositional,
1503-
);
1504-
var namedParamsWithRequiredAndDefault = requiredParameters
1505-
.where((p) => p.isNamed)
1506-
.where((p) => p is DefaultFormalParameter && p.defaultValue != null);
1507-
for (var param in nonNamedParamsWithRequired.where((p) => p.isOptional)) {
1508-
_diagnosticReporter.atNode(
1509-
param,
1510-
WarningCode.invalidRequiredOptionalPositionalParam,
1511-
arguments: [_formalParameterNameOrEmpty(param)],
1512-
);
1513-
}
1514-
for (var param in nonNamedParamsWithRequired.where((p) => p.isRequired)) {
1515-
_diagnosticReporter.atNode(
1516-
param,
1517-
WarningCode.invalidRequiredPositionalParam,
1518-
arguments: [_formalParameterNameOrEmpty(param)],
1519-
);
1520-
}
1521-
for (var param in namedParamsWithRequiredAndDefault) {
1522-
_diagnosticReporter.atNode(
1523-
param,
1524-
WarningCode.invalidRequiredNamedParam,
1525-
arguments: [_formalParameterNameOrEmpty(param)],
1526-
);
1527-
}
1528-
}
1529-
15301491
/// In "strict-inference" mode, check that each of the [parameterList]' type
15311492
/// is specified.
15321493
///
@@ -1687,10 +1648,6 @@ class BestPracticesVerifier extends RecursiveAstVisitor<void> {
16871648
return _workspacePackage.contains(library.firstFragment.source);
16881649
}
16891650

1690-
static String _formalParameterNameOrEmpty(FormalParameter node) {
1691-
return node.name?.lexeme ?? '';
1692-
}
1693-
16941651
static bool _hasNonVirtualAnnotation(ExecutableElement element) {
16951652
if (element is PropertyAccessorElement && element.isSynthetic) {
16961653
if (element.variable.metadata.hasNonVirtual) {

pkg/analyzer/lib/src/error/codes.g.dart

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -11694,57 +11694,6 @@ class WarningCode extends DiagnosticCodeWithExpectedTypes {
1169411694
expectedTypes: [],
1169511695
);
1169611696

11697-
/// This warning is generated anywhere where `@required` annotates a named
11698-
/// parameter with a default value.
11699-
///
11700-
/// Parameters:
11701-
/// String p0: the name of the member
11702-
static const WarningTemplate<
11703-
LocatableDiagnostic Function({required String p0})
11704-
>
11705-
invalidRequiredNamedParam = WarningTemplate(
11706-
'INVALID_REQUIRED_NAMED_PARAM',
11707-
"The type parameter '{0}' is annotated with @required but only named "
11708-
"parameters without a default value can be annotated with it.",
11709-
correctionMessage: "Remove @required.",
11710-
withArguments: _withArgumentsInvalidRequiredNamedParam,
11711-
expectedTypes: [ExpectedType.string],
11712-
);
11713-
11714-
/// This warning is generated anywhere where `@required` annotates an optional
11715-
/// positional parameter.
11716-
///
11717-
/// Parameters:
11718-
/// String p0: the name of the member
11719-
static const WarningTemplate<
11720-
LocatableDiagnostic Function({required String p0})
11721-
>
11722-
invalidRequiredOptionalPositionalParam = WarningTemplate(
11723-
'INVALID_REQUIRED_OPTIONAL_POSITIONAL_PARAM',
11724-
"Incorrect use of the annotation @required on the optional positional "
11725-
"parameter '{0}'. Optional positional parameters cannot be required.",
11726-
correctionMessage: "Remove @required.",
11727-
withArguments: _withArgumentsInvalidRequiredOptionalPositionalParam,
11728-
expectedTypes: [ExpectedType.string],
11729-
);
11730-
11731-
/// This warning is generated anywhere where `@required` annotates a
11732-
/// non-optional positional parameter.
11733-
///
11734-
/// Parameters:
11735-
/// String p0: the name of the member
11736-
static const WarningTemplate<
11737-
LocatableDiagnostic Function({required String p0})
11738-
>
11739-
invalidRequiredPositionalParam = WarningTemplate(
11740-
'INVALID_REQUIRED_POSITIONAL_PARAM',
11741-
"Redundant use of the annotation @required on the required positional "
11742-
"parameter '{0}'.",
11743-
correctionMessage: "Remove @required.",
11744-
withArguments: _withArgumentsInvalidRequiredPositionalParam,
11745-
expectedTypes: [ExpectedType.string],
11746-
);
11747-
1174811697
/// Parameters:
1174911698
/// String p0: the name of the member
1175011699
static const WarningTemplate<
@@ -13223,25 +13172,6 @@ class WarningCode extends DiagnosticCodeWithExpectedTypes {
1322313172
return LocatableDiagnosticImpl(invalidOverrideOfNonVirtualMember, [p0, p1]);
1322413173
}
1322513174

13226-
static LocatableDiagnostic _withArgumentsInvalidRequiredNamedParam({
13227-
required String p0,
13228-
}) {
13229-
return LocatableDiagnosticImpl(invalidRequiredNamedParam, [p0]);
13230-
}
13231-
13232-
static LocatableDiagnostic
13233-
_withArgumentsInvalidRequiredOptionalPositionalParam({required String p0}) {
13234-
return LocatableDiagnosticImpl(invalidRequiredOptionalPositionalParam, [
13235-
p0,
13236-
]);
13237-
}
13238-
13239-
static LocatableDiagnostic _withArgumentsInvalidRequiredPositionalParam({
13240-
required String p0,
13241-
}) {
13242-
return LocatableDiagnosticImpl(invalidRequiredPositionalParam, [p0]);
13243-
}
13244-
1324513175
static LocatableDiagnostic _withArgumentsInvalidUseOfDoNotSubmitMember({
1324613176
required String p0,
1324713177
}) {

pkg/analyzer/messages.yaml

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -25821,33 +25821,6 @@ WarningCode:
2582125821
void m() {}
2582225822
}
2582325823
```
25824-
INVALID_REQUIRED_NAMED_PARAM:
25825-
parameters:
25826-
String p0: the name of the member
25827-
problemMessage: "The type parameter '#p0' is annotated with @required but only named parameters without a default value can be annotated with it."
25828-
correctionMessage: Remove @required.
25829-
hasPublishedDocs: false
25830-
comment: |-
25831-
This warning is generated anywhere where `@required` annotates a named
25832-
parameter with a default value.
25833-
INVALID_REQUIRED_OPTIONAL_POSITIONAL_PARAM:
25834-
parameters:
25835-
String p0: the name of the member
25836-
problemMessage: "Incorrect use of the annotation @required on the optional positional parameter '#p0'. Optional positional parameters cannot be required."
25837-
correctionMessage: Remove @required.
25838-
hasPublishedDocs: false
25839-
comment: |-
25840-
This warning is generated anywhere where `@required` annotates an optional
25841-
positional parameter.
25842-
INVALID_REQUIRED_POSITIONAL_PARAM:
25843-
parameters:
25844-
String p0: the name of the member
25845-
problemMessage: "Redundant use of the annotation @required on the required positional parameter '#p0'."
25846-
correctionMessage: Remove @required.
25847-
hasPublishedDocs: false
25848-
comment: |-
25849-
This warning is generated anywhere where `@required` annotates a
25850-
non-optional positional parameter.
2585125824
INVALID_USE_OF_DO_NOT_SUBMIT_MEMBER:
2585225825
parameters:
2585325826
String p0: the name of the member

pkg/analyzer/test/src/diagnostics/invalid_required_named_param_test.dart

Lines changed: 0 additions & 56 deletions
This file was deleted.

0 commit comments

Comments
 (0)