Skip to content

Commit d07ab77

Browse files
srawlinsCommit Queue
authored andcommitted
analyzer: Simplify ErrorConfig
Normally I'm all in favor of breaking up methods to improve readability, especially to reduce indentation. But I was able to inline `_process` and `_toSeverity`, and stop relying on `utilities_general.dart` and keep the code with minimal indentation. Change-Id: I1e0fe3be4b135de15400f9d2c854c21ae5f47240 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/389041 Reviewed-by: Konstantin Shcheglov <[email protected]> Commit-Queue: Samuel Rawlins <[email protected]>
1 parent 3029a69 commit d07ab77

File tree

1 file changed

+19
-24
lines changed

1 file changed

+19
-24
lines changed

pkg/analyzer/lib/source/error_processor.dart

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

55
import 'package:analyzer/error/error.dart';
66
import 'package:analyzer/src/generated/engine.dart';
7-
import 'package:analyzer/src/generated/utilities_general.dart';
87
import 'package:analyzer/src/task/options.dart';
9-
import 'package:analyzer/src/util/yaml.dart';
108
import 'package:yaml/yaml.dart';
119

1210
/// String identifiers mapped to associated severities.
@@ -27,33 +25,30 @@ class ErrorConfig {
2725
/// will create a processor config that turns `missing_return` warnings into
2826
/// errors.
2927
ErrorConfig(YamlNode? codeMap) {
30-
_processMap(codeMap);
31-
}
32-
33-
void _process(String? code, Object action) {
34-
code = toUpperCase(code);
35-
var actionStr = toLowerCase(action);
36-
if (AnalyzerOptions.ignoreSynonyms.contains(actionStr)) {
37-
processors.add(ErrorProcessor.ignore(code!));
38-
} else {
39-
var severity = _toSeverity(actionStr);
40-
if (severity != null) {
41-
processors.add(ErrorProcessor(code!, severity));
42-
}
28+
if (codeMap is YamlMap) {
29+
_processMap(codeMap);
4330
}
4431
}
4532

46-
void _processMap(YamlNode? codes) {
47-
if (codes is YamlMap) {
48-
codes.nodes.forEach((k, v) {
49-
if (k is YamlScalar && v is YamlScalar) {
50-
_process(k.value as String?, v.valueOrThrow);
33+
void _processMap(YamlMap codes) {
34+
codes.nodes.forEach((k, v) {
35+
if (k is YamlScalar && v is YamlScalar) {
36+
var code = k.value;
37+
if (code is! String) return;
38+
39+
code = code.toUpperCase();
40+
var action = v.value.toString().toLowerCase();
41+
if (AnalyzerOptions.ignoreSynonyms.contains(action)) {
42+
processors.add(ErrorProcessor.ignore(code));
43+
} else {
44+
var severity = severityMap[action];
45+
if (severity != null) {
46+
processors.add(ErrorProcessor(code, severity));
47+
}
5148
}
52-
});
53-
}
49+
}
50+
});
5451
}
55-
56-
ErrorSeverity? _toSeverity(String? severity) => severityMap[severity];
5752
}
5853

5954
/// Process errors by filtering or changing associated [ErrorSeverity].

0 commit comments

Comments
 (0)