@@ -13,7 +13,28 @@ main() {
1313}
1414
1515defineTests () {
16- const src = """
16+ /// Process the given option [fileContents] and produce a corresponding
17+ /// [LintConfig] . Return `null` if [fileContents] is not a YAML map, or
18+ /// does not have the `linter` child map.
19+ List <RuleConfig >? processAnalysisOptionsFile (String fileContents) {
20+ var yaml = loadYamlNode (fileContents);
21+ if (yaml is YamlMap ) {
22+ return parseLintRuleConfigs (yaml);
23+ }
24+ return null ;
25+ }
26+
27+ // In the future, options might be marshaled in maps and passed to rules.
28+ // acme:
29+ // some_rule:
30+ // some_option: # Note this nesting might be arbitrarily complex?
31+ // - param1
32+ // - param2
33+
34+ group ('lint config' , () {
35+ group ('rule' , () {
36+ test ('configs' , () {
37+ var optionsYaml = loadYamlNode ('''
1738files:
1839 include: foo # un-quoted
1940 exclude:
@@ -25,28 +46,16 @@ rules:
2546 camel_case_types: true #enable
2647 pub:
2748 package_names: false
28- """ ;
29-
30- // In the future, options might be marshaled in maps and passed to rules.
31- // acme:
32- // some_rule:
33- // some_option: # Note this nesting might be arbitrarily complex?
34- // - param1
35- // - param2
36-
37- var config = LintConfig .parse (src);
38-
39- group ('lint config' , () {
40- group ('rule' , () {
41- test ('configs' , () {
49+ ''' );
50+ var config = LintConfig .parseMap (optionsYaml as YamlMap );
4251 expect (config.ruleConfigs, hasLength (3 ));
4352 });
4453
4554 test ('config' , () {
46- config = LintConfig .parse ('''
55+ var config = LintConfig .parseMap ( loadYamlNode ('''
4756rules:
4857 style_guide:
49- unnecessary_getters: false''' );
58+ unnecessary_getters: false''' ) as YamlMap ) ;
5059 expect (config.ruleConfigs, hasLength (1 ));
5160 var ruleConfig = config.ruleConfigs[0 ];
5261 expect (ruleConfig.group, 'style_guide' );
@@ -72,8 +81,8 @@ linter:
7281 unnecessary_getters: false #disable
7382 camel_case_types: true #enable
7483''' ;
75- var config = processAnalysisOptionsFile (src)! ;
76- var ruleNames = config. ruleConfigs.map ((rc) => rc.name);
84+ var ruleConfigs = processAnalysisOptionsFile (src)! ;
85+ var ruleNames = ruleConfigs.map ((rc) => rc.name);
7786 expect (ruleNames, hasLength (2 ));
7887 expect (ruleNames, contains ('unnecessary_getters' ));
7988 expect (ruleNames, contains ('camel_case_types' ));
@@ -91,10 +100,10 @@ linter:
91100 rules:
92101 - camel_case_types
93102''' ;
94- var config = processAnalysisOptionsFile (src)! ;
95- expect (config. ruleConfigs.length, 1 );
103+ var ruleConfigs = processAnalysisOptionsFile (src)! ;
104+ expect (ruleConfigs, hasLength ( 1 ) );
96105 // Verify that defaults are enabled.
97- expect (config. ruleConfigs[0 ].args['enabled' ], isTrue);
106+ expect (ruleConfigs[0 ].args['enabled' ], isTrue);
98107 });
99108
100109 test ('rule map (bools)' , () {
@@ -108,8 +117,7 @@ linter:
108117 camel_case_types: true #enable
109118 unnecessary_getters: false #disable
110119''' ;
111- var config = processAnalysisOptionsFile (src)! ;
112- var ruleConfigs = config.ruleConfigs.toList ();
120+ var ruleConfigs = processAnalysisOptionsFile (src)! ;
113121 ruleConfigs.sort ((RuleConfig rc1, RuleConfig rc2) =>
114122 rc1.name! .compareTo (rc2.name! ));
115123 expect (ruleConfigs, hasLength (2 ));
@@ -132,8 +140,8 @@ linter:
132140
133141 group ('options processing' , () {
134142 group ('raw maps' , () {
135- LintConfig parseMap (Map <Object , Object ?> map) {
136- return parseLintConfig (wrap (map) as YamlMap )! ;
143+ List < RuleConfig > parseMap (Map <Object , Object ?> map) {
144+ return parseLintRuleConfigs (wrap (map) as YamlMap )! ;
137145 }
138146
139147 test ('rule list' , () {
@@ -143,9 +151,9 @@ linter:
143151 };
144152 options['linter' ] = lintOptions;
145153
146- var config = parseMap (options);
147- expect (config , isNotNull);
148- expect (config. ruleConfigs, hasLength (1 ));
154+ var ruleConfigs = parseMap (options);
155+ expect (ruleConfigs , isNotNull);
156+ expect (ruleConfigs, hasLength (1 ));
149157 });
150158
151159 test ('rule map (bool)' , () {
@@ -155,9 +163,9 @@ linter:
155163 };
156164 options['linter' ] = lintOptions;
157165
158- var config = parseMap (options);
159- expect (config , isNotNull);
160- expect (config. ruleConfigs, hasLength (1 ));
166+ var ruleConfigs = parseMap (options);
167+ expect (ruleConfigs , isNotNull);
168+ expect (ruleConfigs, hasLength (1 ));
161169 });
162170
163171 test ('rule map (string)' , () {
@@ -167,9 +175,9 @@ linter:
167175 };
168176 options['linter' ] = lintOptions;
169177
170- var config = parseMap (options);
171- expect (config , isNotNull);
172- expect (config. ruleConfigs, hasLength (1 ));
178+ var ruleConfigs = parseMap (options);
179+ expect (ruleConfigs , isNotNull);
180+ expect (ruleConfigs, hasLength (1 ));
173181 });
174182
175183 test ('nested rule map (bool)' , () {
@@ -181,9 +189,9 @@ linter:
181189 };
182190 options['linter' ] = lintOptions;
183191
184- var config = parseMap (options);
185- expect (config , isNotNull);
186- expect (config. ruleConfigs, hasLength (1 ));
192+ var ruleConfigs = parseMap (options);
193+ expect (ruleConfigs , isNotNull);
194+ expect (ruleConfigs, hasLength (1 ));
187195 });
188196
189197 test ('nested rule map (string)' , () {
@@ -195,9 +203,9 @@ linter:
195203 };
196204 options['linter' ] = lintOptions;
197205
198- var config = parseMap (options);
199- expect (config , isNotNull);
200- expect (config. ruleConfigs, hasLength (1 ));
206+ var ruleConfigs = parseMap (options);
207+ expect (ruleConfigs , isNotNull);
208+ expect (ruleConfigs, hasLength (1 ));
201209 });
202210 });
203211 });
0 commit comments