@@ -76,8 +76,8 @@ const _analyzerErrorKeys = <String>['uri_has_not_been_generated'];
7676/// Such options are:
7777/// - the `include:` predicate,
7878/// - the `formatter:` options (without any filtering),
79- /// - the `analyzer: / errors:` keys passing through keys
80- /// from [_analyzerErrorKeys] ,
79+ /// - the `analyzer: / errors:` keys passing the values if
80+ /// their key is not present in [custom] or are in [_analyzerErrorKeys] ,
8181/// - the `linter: / rules:` section, passing `true` /`false`
8282/// values if their key is not present in [custom] .
8383String updatePassthroughOptions ({
@@ -93,21 +93,23 @@ String updatePassthroughOptions({
9393 origMap ?? = {};
9494
9595 final customMap =
96- json.decode (json.encode (yaml.loadYaml (custom))) ?? < String , dynamic > {};
96+ (json.decode (json.encode (yaml.loadYaml (custom))) as Map ? ) ??
97+ < String , dynamic > {};
9798
98- final origAnalyzer = origMap[ 'analyzer' ] ;
99- if (origAnalyzer is Map ) {
100- final origErrors = origAnalyzer[ 'errors' ];
101- if (origErrors is Map ) {
99+ final appliedCustomRules = _extractAppliedRules (customMap) ;
100+
101+ if (origMap case { 'analyzer' : Map origAnalyzer}) {
102+ if (origAnalyzer case { 'errors' : Map origErrors} ) {
102103 final customAnalyzer =
103104 customMap.putIfAbsent ('analyzer' , () => < String , Object ? > {}) as Map ;
104105 final customErrors =
105106 customAnalyzer.putIfAbsent ('errors' , () => < String , Object ? > {})
106107 as Map ;
107108
108- for (var key in _analyzerErrorKeys) {
109- if (origErrors.containsKey (key)) {
110- customErrors[key] = origErrors[key];
109+ for (var entry in origErrors.entries) {
110+ if (_analyzerErrorKeys.contains (entry.key) ||
111+ ! appliedCustomRules.contains (entry.key)) {
112+ customErrors[entry.key] = entry.value;
111113 }
112114 }
113115 }
@@ -138,7 +140,7 @@ String updatePassthroughOptions({
138140 }
139141 if (customRules is Map ) {
140142 for (var e in origRules.entries) {
141- if (customRules. containsKey (e.key)) {
143+ if (appliedCustomRules. contains (e.key)) {
142144 continue ;
143145 }
144146 customRules[e.key] = e.value;
@@ -160,3 +162,17 @@ String updatePassthroughOptions({
160162
161163 return json.encode (customMap);
162164}
165+
166+ Set <String > _extractAppliedRules (Map map) {
167+ final appliedRules = < String > {};
168+ if (map case {'linter' : {'rules' : List rules}}) {
169+ appliedRules.addAll (rules.map ((e) => e.toString ()));
170+ }
171+ if (map case {'linter' : {'rules' : Map rules}}) {
172+ appliedRules.addAll (rules.keys.map ((e) => e.toString ()));
173+ }
174+ if (map case {'analyzer' : {'errors' : Map errors}}) {
175+ appliedRules.addAll (errors.keys.map ((e) => e.toString ()));
176+ }
177+ return appliedRules;
178+ }
0 commit comments