Skip to content

Commit 4232c45

Browse files
srawlinsCommit Queue
authored andcommitted
linter: Remove dead linter options: include and exclude
The options validator reports if you ever use `include` or `exclude` as a key under `linter`, so these are dead and unused options. Change-Id: I5883e05753f3c6e3f4370c070343d8f31655fd5b Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/390808 Reviewed-by: Phil Quitslund <[email protected]> Commit-Queue: Samuel Rawlins <[email protected]>
1 parent 2ac5765 commit 4232c45

File tree

5 files changed

+28
-80
lines changed

5 files changed

+28
-80
lines changed

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

Lines changed: 7 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5+
import 'package:analyzer/src/task/options.dart';
56
import 'package:analyzer/src/util/yaml.dart';
67
import 'package:yaml/yaml.dart';
78

@@ -31,13 +32,9 @@ LintConfig? processAnalysisOptionsFile(String fileContents, {String? fileUrl}) {
3132

3233
/// The configuration of lint rules within an analysis options file.
3334
class LintConfig {
34-
final List<String> fileIncludes;
35-
36-
final List<String> fileExcludes;
37-
3835
final List<RuleConfig> ruleConfigs;
3936

40-
LintConfig(this.fileIncludes, this.fileExcludes, this.ruleConfigs);
37+
LintConfig(this.ruleConfigs);
4138

4239
factory LintConfig.parse(String source, {String? sourceUrl}) {
4340
var yaml = loadYamlNode(source,
@@ -51,37 +48,13 @@ class LintConfig {
5148
}
5249

5350
factory LintConfig.parseMap(YamlMap yaml) {
54-
var fileIncludes = <String>[];
55-
var fileExcludes = <String>[];
5651
var ruleConfigs = <RuleConfig>[];
57-
58-
yaml.nodes.forEach((key, value) {
59-
if (key is! YamlScalar) {
60-
return;
61-
}
62-
switch (key.toString()) {
63-
case 'files':
64-
if (value is YamlMap) {
65-
_addAsListOrString(value['include'], fileIncludes);
66-
_addAsListOrString(value['exclude'], fileExcludes);
67-
}
68-
69-
case 'rules':
70-
ruleConfigs.addAll(_ruleConfigs(value));
71-
}
72-
});
73-
74-
return LintConfig(fileIncludes, fileExcludes, ruleConfigs);
75-
}
76-
77-
static void _addAsListOrString(Object? value, List<String> list) {
78-
if (value is List) {
79-
for (var entry in value) {
80-
list.add(entry as String);
81-
}
82-
} else if (value is String) {
83-
list.add(value);
52+
var rulesNode = yaml.valueAt(AnalyzerOptions.rules);
53+
if (rulesNode != null) {
54+
ruleConfigs.addAll(_ruleConfigs(rulesNode));
8455
}
56+
57+
return LintConfig(ruleConfigs);
8558
}
8659

8760
static bool? _asBool(YamlNode scalar) {

pkg/analyzer/lib/src/task/options.dart

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,9 @@ class AnalyzerOptions {
266266
// Formatter options.
267267
static const String pageWidth = 'page_width';
268268

269+
// Linter options.
270+
static const String rules = 'rules';
271+
269272
static const String propagateLinterExceptions = 'propagate-linter-exceptions';
270273

271274
/// Ways to say `true` or `false`.
@@ -297,6 +300,10 @@ class AnalyzerOptions {
297300
strictRawTypes,
298301
];
299302

303+
static const List<String> linterOptions = [
304+
rules,
305+
];
306+
300307
/// Supported 'analyzer' optional checks options.
301308
static const List<String> optionalChecksOptions = [
302309
chromeOsManifestChecks,
@@ -749,7 +756,7 @@ class LanguageOptionValidator extends OptionsValidator {
749756
/// Validates `linter` top-level options.
750757
// TODO(pq): move into `linter` package and plugin.
751758
class LinterOptionsValidator extends TopLevelOptionValidator {
752-
LinterOptionsValidator() : super('linter', const ['rules']);
759+
LinterOptionsValidator() : super('linter', AnalyzerOptions.linterOptions);
753760
}
754761

755762
/// Validates `analyzer` optional-checks value configuration options.

pkg/analyzer/test/src/lint/config_test.dart

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,6 @@ rules:
3737
var config = LintConfig.parse(src);
3838

3939
group('lint config', () {
40-
group('file', () {
41-
test('includes', () {
42-
expect(config.fileIncludes, unorderedEquals(['foo']));
43-
});
44-
test('excludes', () {
45-
expect(
46-
config.fileExcludes, unorderedEquals(['test/**', '**/_data.dart']));
47-
});
48-
});
4940
group('rule', () {
5041
test('configs', () {
5142
expect(config.ruleConfigs, hasLength(3));

pkg/linter/pubspec.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ dev_dependencies:
2424
analyzer_utilities: any
2525
args: any
2626
cli_util: any
27-
glob: any
2827
http: any
2928
lints: any
3029
test: any

pkg/linter/tool/benchmark.dart

Lines changed: 13 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,10 @@ import 'dart:async';
66
import 'dart:io';
77
import 'dart:math' as math;
88

9-
import 'package:analyzer/error/error.dart';
109
import 'package:analyzer/src/lint/config.dart';
1110
import 'package:analyzer/src/lint/io.dart';
1211
import 'package:analyzer/src/lint/registry.dart';
1312
import 'package:args/args.dart';
14-
import 'package:glob/glob.dart';
1513
import 'package:linter/src/analyzer.dart';
1614
import 'package:linter/src/extensions.dart';
1715
import 'package:linter/src/rules.dart';
@@ -28,7 +26,7 @@ Future<void> main(List<String> args) async {
2826
const unableToProcessExitCode = 64;
2927

3028
Future<Iterable<AnalysisErrorInfo>> lintFiles(
31-
TestLinter linter, List<File> filesToLint, LintFilter filter) async {
29+
TestLinter linter, List<File> filesToLint) async {
3230
// Setup an error watcher to track whether an error was logged to stderr so
3331
// we can set the exit code accordingly.
3432
var errorWatcher = _ErrorWatchingSink(errorSink);
@@ -37,7 +35,7 @@ Future<Iterable<AnalysisErrorInfo>> lintFiles(
3735
if (errorWatcher.encounteredError) {
3836
exitCode = loggedAnalyzerErrorExitCode;
3937
} else if (errors.isNotEmpty) {
40-
exitCode = _maxSeverity(errors, filter);
38+
exitCode = _maxSeverity(errors);
4139
}
4240

4341
return errors;
@@ -94,12 +92,11 @@ Future<void> runLinter(List<String> args) async {
9492
var ruleNames = options['rules'];
9593

9694
LinterOptions linterOptions;
97-
LintFilter? filter;
9895
if (configFile is String) {
9996
var config = LintConfig.parse(readFile(configFile));
10097
var enabledRules = Registry.ruleRegistry.where((LintRule rule) =>
10198
!config.ruleConfigs.any((rc) => rc.disables(rule.name)));
102-
filter = _FileGlobFilter(config.fileIncludes, config.fileExcludes);
99+
103100
linterOptions = LinterOptions(enabledRules: enabledRules);
104101
} else if (ruleNames is Iterable<String> && ruleNames.isNotEmpty) {
105102
var rules = <LintRule>[];
@@ -115,7 +112,6 @@ Future<void> runLinter(List<String> args) async {
115112
} else {
116113
linterOptions = LinterOptions();
117114
}
118-
filter ??= _FileGlobFilter([], []);
119115

120116
var customSdk = options['dart-sdk'];
121117
if (customSdk is String) {
@@ -131,14 +127,18 @@ Future<void> runLinter(List<String> args) async {
131127
.map(File.new),
132128
];
133129

134-
await writeBenchmarks(outSink, filesToLint, linterOptions, filter);
130+
await writeBenchmarks(
131+
outSink,
132+
filesToLint,
133+
linterOptions,
134+
);
135135
}
136136

137-
Future<void> writeBenchmarks(StringSink out, List<File> filesToLint,
138-
LinterOptions linterOptions, LintFilter filter) async {
137+
Future<void> writeBenchmarks(
138+
StringSink out, List<File> filesToLint, LinterOptions linterOptions) async {
139139
var timings = <String, int>{};
140140
for (var i = 0; i < benchmarkRuns; ++i) {
141-
await lintFiles(TestLinter(linterOptions), filesToLint, filter);
141+
await lintFiles(TestLinter(linterOptions), filesToLint);
142142
lintRuleTimers.timers.forEach((n, t) {
143143
var timing = t.elapsedMilliseconds;
144144
var previous = timings[n];
@@ -168,19 +168,12 @@ Future<void> writeBenchmarks(StringSink out, List<File> filesToLint,
168168
out.writeTimings(stats, 0);
169169
}
170170

171-
int _maxSeverity(List<AnalysisErrorInfo> infos, LintFilter filter) {
172-
var filteredErrors = infos
173-
.expand((i) => i.errors)
174-
.where((AnalysisError e) => !filter.filter(e));
171+
int _maxSeverity(List<AnalysisErrorInfo> infos) {
172+
var filteredErrors = infos.expand((i) => i.errors);
175173
return filteredErrors.fold(
176174
0, (value, e) => math.max(value, e.errorCode.errorSeverity.ordinal));
177175
}
178176

179-
/// Filtered lints are omitted from linter output.
180-
abstract class LintFilter {
181-
bool filter(AnalysisError lint);
182-
}
183-
184177
class _ErrorWatchingSink implements StringSink {
185178
bool encounteredError = false;
186179

@@ -207,18 +200,3 @@ class _ErrorWatchingSink implements StringSink {
207200
delegate.writeln(obj);
208201
}
209202
}
210-
211-
class _FileGlobFilter extends LintFilter {
212-
final List<Glob> includes;
213-
final List<Glob> excludes;
214-
215-
_FileGlobFilter(Iterable<String> includeGlobs, Iterable<String> excludeGlobs)
216-
: includes = includeGlobs.map(Glob.new).toList(),
217-
excludes = excludeGlobs.map(Glob.new).toList();
218-
219-
@override
220-
bool filter(AnalysisError lint) =>
221-
// TODO(srawlins): specify order.
222-
excludes.any((glob) => glob.matches(lint.source.fullName)) &&
223-
!includes.any((glob) => glob.matches(lint.source.fullName));
224-
}

0 commit comments

Comments
 (0)