mirror of
https://github.com/dart-lang/sdk
synced 2024-10-14 12:30:03 +00:00
[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
0845ebaad8
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>
This commit is contained in:
parent
ff0e760ac2
commit
24a7318725
|
@ -573,7 +573,6 @@ const List<ErrorCode> errorCodeValues = [
|
|||
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,
|
||||
|
|
|
@ -1492,16 +1492,6 @@ class HintCode extends AnalyzerErrorCode {
|
|||
hasPublishedDocs: true,
|
||||
);
|
||||
|
||||
/**
|
||||
* 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.
|
||||
|
|
|
@ -332,7 +332,6 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
|
|||
@override
|
||||
void visitAnnotation(Annotation node) {
|
||||
_checkForInvalidAnnotationFromDeferredLibrary(node);
|
||||
_checkForMissingJSLibAnnotation(node);
|
||||
super.visitAnnotation(node);
|
||||
}
|
||||
|
||||
|
@ -3022,15 +3021,6 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
|
|||
}
|
||||
}
|
||||
|
||||
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.
|
||||
|
|
|
@ -15195,12 +15195,6 @@ HintCode:
|
|||
```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
|
||||
|
|
|
@ -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),
|
||||
]);
|
||||
}
|
||||
}
|
|
@ -402,7 +402,6 @@ import 'missing_enum_constant_in_switch_test.dart'
|
|||
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 @@ main() {
|
|||
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();
|
||||
|
|
Loading…
Reference in a new issue