@@ -46,8 +46,8 @@ func PutIssueBuffer(issues []Issue) {
4646
4747// Config contains all configuration options for the goconst analyzer.
4848type Config struct {
49- // IgnoreStrings is a regular expression to filter strings
50- IgnoreStrings string
49+ // IgnoreStrings is a list of regular expressions to filter strings
50+ IgnoreStrings [] string
5151 // IgnoreTests indicates whether test files should be excluded
5252 IgnoreTests bool
5353 // MatchWithConstants enables matching strings with existing constants
@@ -68,11 +68,51 @@ type Config struct {
6868 FindDuplicates bool
6969}
7070
71- // Run analyzes the provided AST files for duplicated strings or numbers
72- // according to the provided configuration.
73- // It returns a slice of Issue objects containing the findings.
74- func Run (files []* ast.File , fset * token.FileSet , cfg * Config ) ([]Issue , error ) {
75- p := New (
71+ // NewWithIgnorePatterns creates a new instance of the parser with support for multiple ignore patterns.
72+ // This is an alternative constructor that takes a slice of ignore string patterns.
73+ func NewWithIgnorePatterns (
74+ path , ignore string ,
75+ ignoreStrings []string ,
76+ ignoreTests , matchConstant , numbers , findDuplicates bool ,
77+ numberMin , numberMax , minLength , minOccurrences int ,
78+ excludeTypes map [Type ]bool ) * Parser {
79+
80+ // Join multiple patterns with OR for regex
81+ var ignoreStringsPattern string
82+ if len (ignoreStrings ) > 0 {
83+ if len (ignoreStrings ) > 1 {
84+ // Wrap each pattern in parentheses and join with OR
85+ patterns := make ([]string , len (ignoreStrings ))
86+ for i , pattern := range ignoreStrings {
87+ patterns [i ] = "(" + pattern + ")"
88+ }
89+ ignoreStringsPattern = strings .Join (patterns , "|" )
90+ } else {
91+ // Single pattern case
92+ ignoreStringsPattern = ignoreStrings [0 ]
93+ }
94+ }
95+
96+ return New (
97+ path ,
98+ ignore ,
99+ ignoreStringsPattern ,
100+ ignoreTests ,
101+ matchConstant ,
102+ numbers ,
103+ findDuplicates ,
104+ numberMin ,
105+ numberMax ,
106+ minLength ,
107+ minOccurrences ,
108+ excludeTypes ,
109+ )
110+ }
111+
112+ // RunWithConfig is a convenience function that runs the analysis with a Config object
113+ // directly supporting multiple ignore patterns.
114+ func RunWithConfig (files []* ast.File , fset * token.FileSet , cfg * Config ) ([]Issue , error ) {
115+ p := NewWithIgnorePatterns (
76116 "" ,
77117 "" ,
78118 cfg .IgnoreStrings ,
@@ -233,3 +273,10 @@ func Run(files []*ast.File, fset *token.FileSet, cfg *Config) ([]Issue, error) {
233273 // Don't return the buffer to pool as the caller now owns it
234274 return issueBuffer , nil
235275}
276+
277+ // Run analyzes the provided AST files for duplicated strings or numbers
278+ // according to the provided configuration.
279+ // It returns a slice of Issue objects containing the findings.
280+ func Run (files []* ast.File , fset * token.FileSet , cfg * Config ) ([]Issue , error ) {
281+ return RunWithConfig (files , fset , cfg )
282+ }
0 commit comments