revert @IncompatibleWith (#1918)
diff --git a/lib/src/meta.dart b/lib/src/meta.dart
deleted file mode 100644
index 4c84f21..0000000
--- a/lib/src/meta.dart
+++ /dev/null
@@ -1,36 +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.
-
-/// Linter metadata annotations.
-library linter_meta;
-
-/// Used to annotate a lint rule `r` whose semantics are incompatible with
-/// a given list of rules `r1`...`rn`.
-///
-/// For example, the incompatibility between `prefer_local_finals` and
-/// `unnecessary_final` could be captured in the `PreferFinalLocals` class
-/// declaration like this:
-///
-/// @IncompatibleWith(['unnecessary_final'])
-/// class PreferFinalLocals extends LintRule implements NodeLintRule {
-/// ...
-/// }
-///
-/// For consistency of documentation, incompatibility should be declared in both
-/// directions. That is, all conflicting rules `r1`...`rn` should annotate
-/// their incompatibility with `r`. In this case, `'unnecessary_final'` would
-/// look like this:
-///
-/// @IncompatibleWith(['prefer_local_finals'])
-/// class UnnecessaryFinal extends LintRule implements NodeLintRule {
-/// ...
-/// }
-///
-class IncompatibleWith {
- /// A list of the ids of incompatible rules.
- final List<String> rules;
-
- /// Initialize a newly created instance to have the given [rules].
- const IncompatibleWith(this.rules);
-}
diff --git a/lib/src/rules/prefer_final_locals.dart b/lib/src/rules/prefer_final_locals.dart
index db619b6..64cb2bd 100644
--- a/lib/src/rules/prefer_final_locals.dart
+++ b/lib/src/rules/prefer_final_locals.dart
@@ -6,7 +6,6 @@
import 'package:analyzer/dart/ast/visitor.dart';
import '../analyzer.dart';
-import '../meta.dart';
const _desc =
r'Prefer final for variable declarations if they are not reassigned.';
@@ -47,7 +46,6 @@
''';
-@IncompatibleWith(['unnecessary_final'])
class PreferFinalLocals extends LintRule implements NodeLintRule {
PreferFinalLocals()
: super(
diff --git a/lib/src/rules/unnecessary_final.dart b/lib/src/rules/unnecessary_final.dart
index 57b4f99..d6f29f8 100644
--- a/lib/src/rules/unnecessary_final.dart
+++ b/lib/src/rules/unnecessary_final.dart
@@ -6,7 +6,6 @@
import 'package:analyzer/dart/ast/visitor.dart';
import '../analyzer.dart';
-import '../meta.dart';
const _desc = "Don't use `final` for local variables.";
@@ -36,7 +35,6 @@
```
''';
-@IncompatibleWith(['prefer_final_locals'])
class UnnecessaryFinal extends LintRule implements NodeLintRule {
UnnecessaryFinal()
: super(
diff --git a/lib/src/util/lint_cache.dart b/lib/src/util/lint_cache.dart
deleted file mode 100644
index ec61fee..0000000
--- a/lib/src/util/lint_cache.dart
+++ /dev/null
@@ -1,124 +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 'dart:io';
-
-import 'package:analyzer/dart/analysis/analysis_context_collection.dart';
-import 'package:analyzer/dart/ast/ast.dart';
-import 'package:analyzer/dart/ast/visitor.dart';
-import 'package:analyzer/dart/element/element.dart';
-import 'package:analyzer/file_system/physical_file_system.dart';
-
-import '../analyzer.dart';
-import '../rules.dart';
-import '../utils.dart';
-
-const String _INCOMPATIBLE_WITH_CLASS_NAME = 'IncompatibleWith';
-const String _LINT_RULE_CLASS_NAME = 'LintRule';
-const String _LINTER_META_LIB_NAME = 'linter_meta';
-
-bool _isIncompatibleWithAnnotation(Element element) =>
- element is ConstructorElement &&
- element.enclosingElement.name == _INCOMPATIBLE_WITH_CLASS_NAME &&
- element.library?.name == _LINTER_META_LIB_NAME;
-
-class LintCache {
- List<LintRuleDetails> details = <LintRuleDetails>[];
-
- bool _initialized = false;
-
- LintRuleDetails findDetailsByClassName(String className) {
- for (var detail in details) {
- if (detail.className == className) {
- return detail;
- }
- }
- return null;
- }
-
- LintRuleDetails findDetailsById(String id) {
- for (var detail in details) {
- if (detail.id == id) {
- return detail;
- }
- }
- return null;
- }
-
- Future<void> init() async {
- if (_initialized) {
- return;
- }
- registerLintRules();
-
- // Setup details.
- for (var lint in Analyzer.facade.registeredRules) {
- details.add(LintRuleDetails(lint.runtimeType.toString(), lint.name));
- }
-
- // Process compatibility annotations.
- final rulePath = File('lib/src/rules').absolute.path;
- final collection = AnalysisContextCollection(
- includedPaths: [rulePath],
- resourceProvider: PhysicalResourceProvider.INSTANCE,
- );
-
- final visitor = _LintVisitor();
- for (var context in collection.contexts) {
- for (var filePath in context.contextRoot.analyzedFiles()) {
- if (isDartFileName(filePath)) {
- final result = await context.currentSession.getResolvedUnit(filePath);
- result.unit.accept(visitor);
- }
- }
- }
-
- for (var classElement in visitor.classElements) {
- for (var annotation in classElement.metadata) {
- if (_isIncompatibleWithAnnotation(annotation.element)) {
- final constantValue = annotation.computeConstantValue();
- final ruleObjects = constantValue?.getField('rules')?.toListValue();
- if (ruleObjects != null) {
- final lintClassName = classElement.thisType.name;
- final ruleDetails = findDetailsByClassName(lintClassName);
- for (var ruleObject in ruleObjects) {
- final ruleId = ruleObject.toStringValue();
- ruleDetails.incompatibleRules.add(ruleId);
- }
- }
- }
- }
- }
- _initialized = true;
- }
-}
-
-class LintRuleDetails {
- final String className;
- final String id;
- final List<String> incompatibleRules = <String>[];
- LintRuleDetails(this.className, this.id);
-
- @override
- String toString() => '$className:$id';
-}
-
-class _LintVisitor extends RecursiveAstVisitor {
- final List<ClassElement> classElements = <ClassElement>[];
-
- @override
- void visitClassDeclaration(ClassDeclaration node) {
- final classElement = node.declaredElement;
- if (classElement == null) {
- return;
- }
-
- for (var superType in classElement.allSupertypes) {
- if (superType.name == _LINT_RULE_CLASS_NAME) {
- classElements.add(classElement);
- return;
- }
- }
- }
-}
diff --git a/test/validate_metadata.dart b/test/validate_metadata.dart
index aaf97c2..5be62fa 100644
--- a/test/validate_metadata.dart
+++ b/test/validate_metadata.dart
@@ -2,30 +2,22 @@
// 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:linter/src/analyzer.dart';
-import 'package:linter/src/rules.dart';
-import 'package:linter/src/util/lint_cache.dart';
-import 'package:test/test.dart';
-
void main() {
- final lintCache = LintCache();
-
- group('check for incompatible rules:', () {
- registerLintRules();
- for (var rule in Analyzer.facade.registeredRules) {
- test(rule.name, () async {
- await lintCache.init();
- var lintDetail = lintCache.findDetailsById(rule.name);
- for (var incompatibleRule in lintDetail.incompatibleRules) {
- final ruleDetail = lintCache.findDetailsById(incompatibleRule);
- expect(ruleDetail, isNotNull,
- reason:
- 'No rule found for id: $incompatibleRule (check for typo?)');
- expect(ruleDetail.incompatibleRules, contains(lintDetail.id),
- reason:
- '${ruleDetail.id} should declare ${lintDetail.id} as `@IncompatibleWith` but does not.');
- }
- });
- }
- });
+// todo (pq): re-introduce check when analyzer >0.39.3-dev is published
+// group('check for incompatible rules:', () {
+// registerLintRules();
+// for (var rule in Analyzer.facade.registeredRules) {
+// test(rule.name, () async {
+// for (var incompatibleRule in lintDetail.incompatibleRules) {
+// final ruleDetail = lintCache.findDetailsById(incompatibleRule);
+// expect(ruleDetail, isNotNull,
+// reason:
+// 'No rule found for id: $incompatibleRule (check for typo?)');
+// expect(ruleDetail.incompatibleRules, contains(lintDetail.id),
+// reason:
+// '${ruleDetail.id} should declare ${lintDetail.id} as `@IncompatibleWith` but does not.');
+// }
+// });
+// }
+// });
}