Skip to content

Commit fadaa36

Browse files
srawlinsCommit Queue
authored andcommitted
linter: Remove support for unmocked lint rule legacy tests
The `unsafe_html` lint rule was the last (or only?) rule to use an unmocked SDK in legacy tests, and it is removed. Change-Id: I86cdb77fd0e98fab5ec9351962d38af74ba87bd0 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/394568 Commit-Queue: Phil Quitslund <[email protected]> Auto-Submit: Samuel Rawlins <[email protected]> Reviewed-by: Phil Quitslund <[email protected]>
1 parent 901b2eb commit fadaa36

File tree

1 file changed

+9
-43
lines changed

1 file changed

+9
-43
lines changed

pkg/linter/test/rule_test.dart

Lines changed: 9 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@
44

55
import 'dart:io';
66

7-
import 'package:analyzer/dart/analysis/analysis_context_collection.dart';
8-
import 'package:analyzer/dart/analysis/results.dart';
97
import 'package:analyzer/error/error.dart';
10-
import 'package:analyzer/file_system/physical_file_system.dart';
118
import 'package:analyzer/src/dart/analysis/analysis_options.dart';
129
import 'package:analyzer/src/lint/io.dart';
1310
import 'package:analyzer/src/lint/registry.dart';
@@ -75,53 +72,22 @@ void defineRuleUnitTests() {
7572
});
7673
}
7774

78-
void testRule(String ruleName, File file, {bool useMockSdk = true}) {
75+
void testRule(String ruleName, File file) {
7976
test(ruleName, () async {
8077
if (!file.existsSync()) {
8178
throw Exception('No rule found defined at: ${file.path}');
8279
}
8380

84-
var errorInfos =
85-
await _getErrorInfos(ruleName, file, useMockSdk: useMockSdk);
86-
_validateExpectedLints(file, errorInfos);
87-
});
88-
}
89-
90-
Future<Iterable<AnalysisErrorInfo>> _getErrorInfos(String ruleName, File file,
91-
{required bool useMockSdk}) async {
92-
registerLintRules();
93-
var rule = Registry.ruleRegistry[ruleName];
94-
if (rule == null) {
95-
fail('rule `$ruleName` is not registered; unable to test.');
96-
}
81+
registerLintRules();
82+
var rule = Registry.ruleRegistry[ruleName];
83+
if (rule == null) {
84+
fail('rule `$ruleName` is not registered; unable to test.');
85+
}
9786

98-
if (useMockSdk) {
9987
var driver = buildDriver(rule, file);
100-
return await driver.lintFiles([file]);
101-
}
102-
103-
var path = p.normalize(file.absolute.path);
104-
var collection = AnalysisContextCollection(
105-
includedPaths: [path],
106-
resourceProvider: PhysicalResourceProvider.INSTANCE,
107-
);
108-
109-
var context = collection.contexts.first;
110-
var contextFile = (context.currentSession.getFile(path) as FileResult).file;
111-
var options =
112-
context.getAnalysisOptionsForFile(contextFile) as AnalysisOptionsImpl;
113-
options.lintRules = options.lintRules.toList();
114-
115-
// TODO(pq): consider a different way to configure lints
116-
// https://github.com/dart-lang/sdk/issues/54045
117-
options.lintRules.add(rule);
118-
options.lint = true;
119-
120-
var result =
121-
await context.currentSession.getResolvedUnit(path) as ResolvedUnitResult;
122-
return [
123-
AnalysisErrorInfo(result.errors, result.lineInfo),
124-
];
88+
var errorInfos = await driver.lintFiles([file]);
89+
_validateExpectedLints(file, errorInfos);
90+
});
12591
}
12692

12793
/// Parse lint annotations in the given [file] and validate that they correspond

0 commit comments

Comments
 (0)