@@ -18,6 +18,23 @@ import (
1818 "github.com/ajitpratap0/GoSQLX/pkg/sql/parser"
1919)
2020
21+ // builtinRules returns all built-in lint rules. This is the single source of
22+ // truth — both defaultLinter() and allRules() derive from it.
23+ func builtinRules () []linter.Rule {
24+ return []linter.Rule {
25+ whitespace .NewTrailingWhitespaceRule (), // L001
26+ whitespace .NewMixedIndentationRule (), // L002
27+ whitespace .NewConsecutiveBlankLinesRule (2 ), // L003
28+ whitespace .NewIndentationDepthRule (10 , 4 ), // L004
29+ whitespace .NewLongLinesRule (120 ), // L005
30+ style .NewColumnAlignmentRule (), // L006
31+ keywords .NewKeywordCaseRule (keywords .CaseUpper ), // L007
32+ style .NewCommaPlacementRule (style .CommaTrailing ), // L008
33+ style .NewAliasingConsistencyRule (true ), // L009
34+ whitespace .NewRedundantWhitespaceRule (), // L010
35+ }
36+ }
37+
2138var (
2239 actionFiles string
2340 actionRules string
@@ -293,19 +310,40 @@ type lintViolation struct {
293310 Message string
294311}
295312
296- // defaultLinter creates a linter with standard rules.
313+ // defaultLinter creates a linter with all built-in rules.
297314func defaultLinter () * linter.Linter {
298- return linter .New (
299- whitespace .NewTrailingWhitespaceRule (),
300- whitespace .NewMixedIndentationRule (),
301- keywords .NewKeywordCaseRule (keywords .CaseUpper ),
302- style .NewColumnAlignmentRule (),
303- )
315+ return linter .New (builtinRules ()... )
316+ }
317+
318+ // allRules returns every built-in rule keyed by its ID.
319+ func allRules () map [string ]linter.Rule {
320+ all := builtinRules ()
321+ m := make (map [string ]linter.Rule , len (all ))
322+ for _ , r := range all {
323+ m [r .ID ()] = r
324+ }
325+ return m
304326}
305327
306328// lintFile runs the linter on a file and returns violations.
307- func lintFile (filePath string , _ []string ) []lintViolation {
308- l := defaultLinter ()
329+ // When ruleList is non-empty only the rules whose IDs match are executed.
330+ func lintFile (filePath string , ruleList []string ) []lintViolation {
331+ var l * linter.Linter
332+ if len (ruleList ) == 0 {
333+ l = defaultLinter ()
334+ } else {
335+ available := allRules ()
336+ var selected []linter.Rule
337+ for _ , id := range ruleList {
338+ if r , ok := available [id ]; ok {
339+ selected = append (selected , r )
340+ }
341+ }
342+ if len (selected ) == 0 {
343+ return nil
344+ }
345+ l = linter .New (selected ... )
346+ }
309347 result := l .LintFile (filePath )
310348
311349 if result .Error != nil {
0 commit comments