@@ -303,9 +303,40 @@ func defaultLinter() *linter.Linter {
303303 )
304304}
305305
306+ // allRules returns every built-in rule keyed by its ID.
307+ func allRules () map [string ]linter.Rule {
308+ all := []linter.Rule {
309+ whitespace .NewTrailingWhitespaceRule (),
310+ whitespace .NewMixedIndentationRule (),
311+ keywords .NewKeywordCaseRule (keywords .CaseUpper ),
312+ style .NewColumnAlignmentRule (),
313+ }
314+ m := make (map [string ]linter.Rule , len (all ))
315+ for _ , r := range all {
316+ m [r .ID ()] = r
317+ }
318+ return m
319+ }
320+
306321// lintFile runs the linter on a file and returns violations.
307- func lintFile (filePath string , _ []string ) []lintViolation {
308- l := defaultLinter ()
322+ // When ruleList is non-empty only the rules whose IDs match are executed.
323+ func lintFile (filePath string , ruleList []string ) []lintViolation {
324+ var l * linter.Linter
325+ if len (ruleList ) == 0 {
326+ l = defaultLinter ()
327+ } else {
328+ available := allRules ()
329+ var selected []linter.Rule
330+ for _ , id := range ruleList {
331+ if r , ok := available [id ]; ok {
332+ selected = append (selected , r )
333+ }
334+ }
335+ if len (selected ) == 0 {
336+ return nil
337+ }
338+ l = linter .New (selected ... )
339+ }
309340 result := l .LintFile (filePath )
310341
311342 if result .Error != nil {
0 commit comments