Skip to content

Commit 8f6f186

Browse files
srawlinsCommit Queue
authored andcommitted
analyzer: Remove unused LinterOptions.analysisOptions field.
The only position where it was used was in a linter test, `rule_test.dart`, where every directory under `pkg/linter/test/configs` was used to create a test. But there aren't any more directories under `pkg/linter/test/config`. So delete that test, and various `analysisOptions` parameters. Change-Id: If37029a44681a0bc9adeb26318d3151ca1d99dc3 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/390563 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Samuel Rawlins <[email protected]>
1 parent 2f2cf79 commit 8f6f186

File tree

6 files changed

+17
-63
lines changed

6 files changed

+17
-63
lines changed

pkg/analyzer/lib/src/lint/analysis.dart

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,11 @@ import 'package:analyzer/file_system/physical_file_system.dart';
1010
import 'package:analyzer/instrumentation/instrumentation.dart';
1111
import 'package:analyzer/source/file_source.dart';
1212
import 'package:analyzer/source/source.dart';
13-
import 'package:analyzer/src/analysis_options/analysis_options_provider.dart';
14-
import 'package:analyzer/src/analysis_options/apply_options.dart';
1513
import 'package:analyzer/src/dart/analysis/analysis_context_collection.dart';
1614
import 'package:analyzer/src/generated/engine.dart';
1715
import 'package:analyzer/src/lint/io.dart';
1816
import 'package:analyzer/src/lint/linter.dart';
1917

20-
AnalysisOptionsProvider _optionsProvider = AnalysisOptionsProvider();
21-
2218
Source createSource(Uri uri) {
2319
var filePath = uri.toFilePath();
2420
var file = PhysicalResourceProvider.INSTANCE.getFile(filePath);
@@ -35,11 +31,6 @@ void _updateAnalyzerOptions(
3531
AnalysisOptionsImpl analysisOptions,
3632
LinterOptions options,
3733
) {
38-
if (options.analysisOptions != null) {
39-
var map = _optionsProvider.getOptionsFromString(options.analysisOptions);
40-
analysisOptions.applyOptions(map);
41-
}
42-
4334
analysisOptions.lint = options.enableLints;
4435
analysisOptions.warning = false;
4536
analysisOptions.enableTiming = options.enableTiming;

pkg/analyzer/lib/src/lint/linter.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,9 @@ final class LinterContextWithResolvedResults implements LinterContext {
186186

187187
class LinterOptions extends DriverOptions {
188188
final Iterable<LintRule> enabledRules;
189-
final String? analysisOptions;
190189

191190
LinterOptions({
192191
Iterable<LintRule>? enabledRules,
193-
this.analysisOptions,
194192
}) : enabledRules = enabledRules ?? Registry.ruleRegistry;
195193
}
196194

pkg/linter/lib/src/test_utilities/test_resource_provider.dart

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import 'test_linter.dart';
1616

1717
/// Builds the [TestLinter] with appropriate mock SDK, resource providers, and
1818
/// package config path.
19-
TestLinter buildDriver(LintRule rule, File file, {String? analysisOptions}) {
19+
TestLinter buildDriver(LintRule rule, File file) {
2020
var memoryResourceProvider = MemoryResourceProvider(
2121
context: PhysicalResourceProvider.INSTANCE.pathContext);
2222
var resourceProvider = TestResourceProvider(memoryResourceProvider);
@@ -29,9 +29,7 @@ TestLinter buildDriver(LintRule rule, File file, {String? analysisOptions}) {
2929
root: sdkRoot,
3030
);
3131

32-
var options =
33-
LinterOptions(enabledRules: [rule], analysisOptions: analysisOptions)
34-
..dartSdkPath = sdkRoot.path;
32+
var options = LinterOptions(enabledRules: [rule])..dartSdkPath = sdkRoot.path;
3533

3634
return TestLinter(options, resourceProvider: resourceProvider);
3735
}

pkg/linter/test/configs/README

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

pkg/linter/test/rule_test.dart

Lines changed: 15 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import 'package:analyzer/dart/analysis/analysis_context_collection.dart';
88
import 'package:analyzer/dart/analysis/results.dart';
99
import 'package:analyzer/error/error.dart';
1010
import 'package:analyzer/file_system/physical_file_system.dart';
11-
import 'package:analyzer/src/analysis_options/analysis_options_provider.dart';
12-
import 'package:analyzer/src/analysis_options/apply_options.dart';
1311
import 'package:analyzer/src/generated/engine.dart';
1412
import 'package:analyzer/src/lint/io.dart';
1513
import 'package:analyzer/src/lint/registry.dart';
@@ -41,17 +39,10 @@ void defineRuleTests() {
4139
group('rule', () {
4240
group('dart', () {
4341
// Rule tests run with default analysis options.
44-
testRules(ruleTestDataDir);
45-
46-
// Rule tests run against specific configurations.
47-
for (var entry in Directory(testConfigDir).listSync()) {
48-
if (entry is! Directory) continue;
49-
group('(config: ${p.basename(entry.path)})', () {
50-
var analysisOptionsFile =
51-
File(p.join(entry.path, 'analysis_options.yaml'));
52-
var analysisOptions = analysisOptionsFile.readAsStringSync();
53-
testRules(ruleTestDataDir, analysisOptions: analysisOptions);
54-
});
42+
for (var entry in Directory(ruleTestDataDir).listSync()) {
43+
if (entry is! File || !isDartFile(entry)) continue;
44+
var ruleName = p.basenameWithoutExtension(entry.path);
45+
testRule(ruleName, entry);
5546
}
5647
});
5748
});
@@ -107,37 +98,28 @@ void defineRuleUnitTests() {
10798
});
10899
}
109100

110-
void testRule(String ruleName, File file,
111-
{bool useMockSdk = true, String? analysisOptions}) {
101+
void testRule(String ruleName, File file, {bool useMockSdk = true}) {
112102
test(ruleName, () async {
113103
if (!file.existsSync()) {
114104
throw Exception('No rule found defined at: ${file.path}');
115105
}
116106

117-
var errorInfos = await _getErrorInfos(ruleName, file,
118-
useMockSdk: useMockSdk, analysisOptions: analysisOptions);
119-
_validateExpectedLints(file, errorInfos, analysisOptions: analysisOptions);
107+
var errorInfos =
108+
await _getErrorInfos(ruleName, file, useMockSdk: useMockSdk);
109+
_validateExpectedLints(file, errorInfos);
120110
});
121111
}
122112

123-
void testRules(String ruleDir, {String? analysisOptions}) {
124-
for (var entry in Directory(ruleDir).listSync()) {
125-
if (entry is! File || !isDartFile(entry)) continue;
126-
var ruleName = p.basenameWithoutExtension(entry.path);
127-
testRule(ruleName, entry, analysisOptions: analysisOptions);
128-
}
129-
}
130-
131113
Future<Iterable<AnalysisErrorInfo>> _getErrorInfos(String ruleName, File file,
132-
{required bool useMockSdk, required String? analysisOptions}) async {
114+
{required bool useMockSdk}) async {
133115
registerLintRules();
134116
var rule = Registry.ruleRegistry[ruleName];
135117
if (rule == null) {
136118
fail('rule `$ruleName` is not registered; unable to test.');
137119
}
138120

139121
if (useMockSdk) {
140-
var driver = buildDriver(rule, file, analysisOptions: analysisOptions);
122+
var driver = buildDriver(rule, file);
141123
return await driver.lintFiles([file]);
142124
}
143125

@@ -170,8 +152,10 @@ Future<Iterable<AnalysisErrorInfo>> _getErrorInfos(String ruleName, File file,
170152

171153
/// Parse lint annotations in the given [file] and validate that they correspond
172154
/// with errors in the provided [errorInfos].
173-
void _validateExpectedLints(File file, Iterable<AnalysisErrorInfo> errorInfos,
174-
{String? analysisOptions}) {
155+
void _validateExpectedLints(
156+
File file,
157+
Iterable<AnalysisErrorInfo> errorInfos,
158+
) {
175159
var expected = <AnnotationMatcher>[];
176160

177161
var lineNumber = 1;
@@ -213,12 +197,7 @@ void _validateExpectedLints(File file, Iterable<AnalysisErrorInfo> errorInfos,
213197
// Dump results for debugging purposes.
214198

215199
// AST
216-
var optionsProvider = AnalysisOptionsProvider();
217-
var optionMap = optionsProvider.getOptionsFromString(analysisOptions);
218-
var optionsImpl = AnalysisOptionsImpl();
219-
optionsImpl.applyOptions(optionMap);
220-
221-
var features = optionsImpl.contextFeatures;
200+
var features = AnalysisOptionsImpl().contextFeatures;
222201

223202
FileSpelunker(file.absolute.path, featureSet: features).spelunk();
224203
printToConsole('');

pkg/linter/test/test_constants.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,3 @@ final String integrationTestDir =
99
final String ruleTestDataDir =
1010
pathRelativeToPackageRoot(['test_data', 'rules']);
1111
final String ruleTestDir = pathRelativeToPackageRoot(['test', 'rules']);
12-
final String testConfigDir = pathRelativeToPackageRoot(['test', 'configs']);

0 commit comments

Comments
 (0)