[analyzer] - remove the missing_js_lib_annotation hint
The web compilers now accept `@JS` annotations on classes and members
directly and no longer requires an additional `@JS` library annotation at the
library level. As a result, we no longer need the
`missing_js_lib_annotation` hint.
Support for this landed a few months ago in
https://github.com/dart-lang/sdk/commit/0845ebaad8e2f4ec2d6c05a15ba4551300e44d65
and was released in Dart 2.12.0.
Change-Id: I39acbf6149499e561f18f909dd09f2d2499f5054
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/215684
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Sigmund Cherem <sigmund@google.com>
diff --git a/pkg/analyzer/lib/error/error.dart b/pkg/analyzer/lib/error/error.dart
index 628175a..26d0396 100644
--- a/pkg/analyzer/lib/error/error.dart
+++ b/pkg/analyzer/lib/error/error.dart
@@ -573,7 +573,6 @@
HintCode.INVALID_USE_OF_VISIBLE_FOR_TESTING_MEMBER,
HintCode.INVALID_VISIBILITY_ANNOTATION,
HintCode.INVALID_VISIBLE_FOR_OVERRIDING_ANNOTATION,
- HintCode.MISSING_JS_LIB_ANNOTATION,
HintCode.MISSING_REQUIRED_PARAM,
HintCode.MISSING_REQUIRED_PARAM_WITH_DETAILS,
HintCode.MISSING_RETURN,
diff --git a/pkg/analyzer/lib/src/dart/error/hint_codes.g.dart b/pkg/analyzer/lib/src/dart/error/hint_codes.g.dart
index 07f0e0e..12bbdcc 100644
--- a/pkg/analyzer/lib/src/dart/error/hint_codes.g.dart
+++ b/pkg/analyzer/lib/src/dart/error/hint_codes.g.dart
@@ -1493,16 +1493,6 @@
);
/**
- * Generate a hint for an element that is annotated with `@JS(...)` whose
- * library declaration is not similarly annotated.
- */
- static const HintCode MISSING_JS_LIB_ANNOTATION = HintCode(
- 'MISSING_JS_LIB_ANNOTATION',
- "The @JS() annotation can only be used if it is also declared on the library directive.",
- correctionMessage: "Try adding the annotation to the library directive.",
- );
-
- /**
* Generate a hint for a constructor, function or method invocation where a
* required parameter is missing.
*
diff --git a/pkg/analyzer/lib/src/generated/error_verifier.dart b/pkg/analyzer/lib/src/generated/error_verifier.dart
index ecedd89..647e36b 100644
--- a/pkg/analyzer/lib/src/generated/error_verifier.dart
+++ b/pkg/analyzer/lib/src/generated/error_verifier.dart
@@ -332,7 +332,6 @@
@override
void visitAnnotation(Annotation node) {
_checkForInvalidAnnotationFromDeferredLibrary(node);
- _checkForMissingJSLibAnnotation(node);
super.visitAnnotation(node);
}
@@ -3022,15 +3021,6 @@
}
}
- void _checkForMissingJSLibAnnotation(Annotation node) {
- if (node.elementAnnotation?.isJS ?? false) {
- if (_currentLibrary.hasJS != true) {
- errorReporter.reportErrorForNode(
- HintCode.MISSING_JS_LIB_ANNOTATION, node);
- }
- }
- }
-
/// Verify that the given mixin does not have an explicitly declared
/// constructor. The [mixinName] is the node to report problem on. The
/// [mixinElement] is the mixing to evaluate.
diff --git a/pkg/analyzer/messages.yaml b/pkg/analyzer/messages.yaml
index 268f0cf..ed7de6a 100644
--- a/pkg/analyzer/messages.yaml
+++ b/pkg/analyzer/messages.yaml
@@ -15195,12 +15195,6 @@
```dart
class C {}
```
- MISSING_JS_LIB_ANNOTATION:
- problemMessage: The @JS() annotation can only be used if it is also declared on the library directive.
- correctionMessage: Try adding the annotation to the library directive.
- comment: |-
- Generate a hint for an element that is annotated with `@JS(...)` whose
- library declaration is not similarly annotated.
MISSING_REQUIRED_PARAM:
problemMessage: "The parameter '{0}' is required."
hasPublishedDocs: true
diff --git a/pkg/analyzer/test/src/diagnostics/missing_js_lib_annotation_test.dart b/pkg/analyzer/test/src/diagnostics/missing_js_lib_annotation_test.dart
deleted file mode 100644
index 9f0346b..0000000
--- a/pkg/analyzer/test/src/diagnostics/missing_js_lib_annotation_test.dart
+++ /dev/null
@@ -1,115 +0,0 @@
-// Copyright (c) 2019, 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:analyzer/src/dart/error/hint_codes.dart';
-import 'package:analyzer/src/dart/error/syntactic_errors.dart';
-import 'package:test_reflective_loader/test_reflective_loader.dart';
-
-import '../dart/resolution/context_collection_resolution.dart';
-
-main() {
- defineReflectiveSuite(() {
- defineReflectiveTests(MissingJSLibAnnotationTest);
- defineReflectiveTests(MissingJSLibAnnotationWithoutNullSafetyTest);
- });
-}
-
-@reflectiveTest
-class MissingJSLibAnnotationTest extends PubPackageResolutionTest {
- @override
- void setUp() {
- super.setUp();
-
- writeTestPackageConfig(PackageConfigFileBuilder(), js: true);
- }
-
- test_class() async {
- await assertErrorsInCode('''
-library foo;
-
-import 'package:js/js.dart';
-
-@JS()
-class A { }
-''', [
- error(HintCode.MISSING_JS_LIB_ANNOTATION, 44, 5),
- ]);
- }
-
- test_function() async {
- await assertErrorsInCode('''
-library foo;
-
-import 'package:js/js.dart';
-
-@JS('acxZIndex')
-set _currentZIndex(int value) { }
-''', [
- error(HintCode.MISSING_JS_LIB_ANNOTATION, 44, 16),
- error(HintCode.UNUSED_ELEMENT, 65, 14),
- ]);
- }
-
- test_method() async {
- await assertErrorsInCode('''
-library foo;
-
-import 'package:js/js.dart';
-
-class A {
- @JS()
- void a() { }
-}
-''', [
- error(HintCode.MISSING_JS_LIB_ANNOTATION, 56, 5),
- ]);
- }
-
- test_notMissing() async {
- await assertNoErrorsInCode('''
-@JS()
-library foo;
-
-import 'package:js/js.dart';
-
-@JS()
-class A { }
-''');
- }
-
- test_variable() async {
- await assertErrorsInCode('''
-import 'package:js/js.dart';
-
-@JS()
-dynamic variable;
-''', [
- error(HintCode.MISSING_JS_LIB_ANNOTATION, 30, 5),
- ]);
- }
-}
-
-@reflectiveTest
-class MissingJSLibAnnotationWithoutNullSafetyTest
- extends PubPackageResolutionTest with WithoutNullSafetyMixin {
- @override
- void setUp() {
- super.setUp();
-
- writeTestPackageConfig(PackageConfigFileBuilder(), js: true);
- }
-
- test_externalField() async {
- // https://github.com/dart-lang/sdk/issues/26987
- await assertErrorsInCode('''
-import 'package:js/js.dart';
-
-@JS()
-external dynamic exports;
-''', [
- error(HintCode.MISSING_JS_LIB_ANNOTATION, 30, 5),
- error(ParserErrorCode.EXTERNAL_FIELD, 36, 8),
- ]);
- }
-}
diff --git a/pkg/analyzer/test/src/diagnostics/test_all.dart b/pkg/analyzer/test/src/diagnostics/test_all.dart
index 33a5243..263958a 100644
--- a/pkg/analyzer/test/src/diagnostics/test_all.dart
+++ b/pkg/analyzer/test/src/diagnostics/test_all.dart
@@ -402,7 +402,6 @@
as missing_enum_constant_in_switch;
import 'missing_exception_value_test.dart' as missing_exception_value;
import 'missing_field_type_in_struct_test.dart' as missing_field_type_in_struct;
-import 'missing_js_lib_annotation_test.dart' as missing_js_lib_annotation;
import 'missing_required_param_test.dart' as missing_required_param;
import 'missing_return_test.dart' as missing_return;
import 'missing_size_annotation_carray_test.dart'
@@ -981,7 +980,6 @@
missing_enum_constant_in_switch.main();
missing_exception_value.main();
missing_field_type_in_struct.main();
- missing_js_lib_annotation.main();
missing_required_param.main();
missing_return.main();
missing_size_annotation_carray.main();