1
+ import 'package:analyzer/error/error.dart' ;
1
2
import 'package:analyzer/file_system/file_system.dart' ;
2
3
import 'package:collection/collection.dart' ;
3
4
import 'package:meta/meta.dart' ;
@@ -17,6 +18,7 @@ class CustomLintConfigs {
17
18
required this .verbose,
18
19
required this .debug,
19
20
required this .rules,
21
+ required this .errors,
20
22
});
21
23
22
24
/// Decode a [CustomLintConfigs] from a file.
@@ -108,11 +110,33 @@ class CustomLintConfigs {
108
110
}
109
111
}
110
112
113
+ final errors = < String , ErrorSeverity > {...includedOptions.errors};
114
+
115
+ final errorsYaml = customLint['errors' ] as Object ? ;
116
+ if (errorsYaml is Map ) {
117
+ for (final entry in errorsYaml.entries) {
118
+ final value = entry.value;
119
+ if (entry.key case final String key? ) {
120
+ final severity = ErrorSeverity .values.firstWhereOrNull (
121
+ (e) => e.displayName == value,
122
+ );
123
+ if (severity == null ) {
124
+ throw ArgumentError (
125
+ 'Provided error severity: $value specified for key: $key is not valid. '
126
+ 'Valid error severities are: ${ErrorSeverity .values .map ((e ) => e .displayName ).join (', ' )}' ,
127
+ );
128
+ }
129
+ errors[key] = severity;
130
+ }
131
+ }
132
+ }
133
+
111
134
return CustomLintConfigs (
112
135
enableAllLintRules: enableAllLintRules,
113
136
verbose: verbose,
114
137
debug: debug,
115
138
rules: UnmodifiableMapView (rules),
139
+ errors: UnmodifiableMapView (errors),
116
140
);
117
141
}
118
142
@@ -123,6 +147,7 @@ class CustomLintConfigs {
123
147
verbose: false ,
124
148
debug: false ,
125
149
rules: {},
150
+ errors: {},
126
151
);
127
152
128
153
/// A field representing whether to enable/disable lint rules that are not
@@ -147,20 +172,26 @@ class CustomLintConfigs {
147
172
/// Whether enable hot-reload and log the VM-service URI.
148
173
final bool debug;
149
174
175
+ /// A map of lint rules to their severity. This is used to override the severity
176
+ /// of a lint rule for a specific lint.
177
+ final Map <String , ErrorSeverity > errors;
178
+
150
179
@override
151
180
bool operator == (Object other) =>
152
181
other is CustomLintConfigs &&
153
182
other.enableAllLintRules == enableAllLintRules &&
154
183
other.verbose == verbose &&
155
184
other.debug == debug &&
156
- const MapEquality <String , LintOptions >().equals (other.rules, rules);
185
+ const MapEquality <String , LintOptions >().equals (other.rules, rules) &&
186
+ const MapEquality <String , ErrorSeverity >().equals (other.errors, errors);
157
187
158
188
@override
159
189
int get hashCode => Object .hash (
160
190
enableAllLintRules,
161
191
verbose,
162
192
debug,
163
193
const MapEquality <String , LintOptions >().hash (rules),
194
+ const MapEquality <String , ErrorSeverity >().hash (errors),
164
195
);
165
196
}
166
197
0 commit comments