@@ -18,6 +18,7 @@ package rules
1818
1919import (
2020 "bufio"
21+ "errors"
2122 "fmt"
2223 "os"
2324 "path/filepath"
@@ -49,10 +50,8 @@ type FileTypeConfig struct {
4950
5051// LicenseInfo contains information about parsed license
5152type LicenseInfo struct {
52- Type string // "CE", "EE", or empty
53- Year string // Extracted year
54- Valid bool // Whether license is valid
55- Error string // Error message if invalid
53+ Type string // "CE", "EE", or empty
54+ Year string // Extracted year
5655}
5756
5857// LicenseParser handles license parsing and validation
@@ -198,15 +197,14 @@ func initFileConfigs() map[string]FileTypeConfig {
198197 return configs
199198}
200199
200+ var ErrUnsupportedFileType = fmt .Errorf ("unsupported file type" )
201+
201202// ParseFile parses a file and extracts license information
202203func (p * LicenseParser ) ParseFile (filename string ) (* LicenseInfo , error ) {
203204 // Get file type configuration
204205 config := p .getFileConfig (filename )
205206 if config == nil {
206- return & LicenseInfo {
207- Valid : false ,
208- Error : fmt .Sprintf ("unsupported file type: %s" , filename ),
209- }, nil
207+ return nil , fmt .Errorf ("%w: %s" , ErrUnsupportedFileType , filename )
210208 }
211209
212210 // Read file header
@@ -215,35 +213,29 @@ func (p *LicenseParser) ParseFile(filename string) (*LicenseInfo, error) {
215213 if err != nil {
216214 return nil , fmt .Errorf ("failed to read file: %w" , err )
217215 }
216+
218217 // Check for generated file markers
219218 if isHeaderMarkedAsGenerated (header ) {
220- return & LicenseInfo {Valid : true }, nil
219+ return & LicenseInfo {}, nil
221220 }
222221
223222 // Try to extract license text from header
224223 licenseText := p .extractLicenseText (header , config )
225224 if licenseText == "" {
226- return & LicenseInfo {
227- Valid : false ,
228- Error : "no license header found" ,
229- }, nil
225+ return nil , errors .New ("no license header found" )
230226 }
231227
232228 // Match against known licenses
233229 for _ , license := range p .licenses {
234230 if matched , year := p .matchLicense (licenseText , license ); matched {
235231 return & LicenseInfo {
236- Type : license .Type ,
237- Year : year ,
238- Valid : true ,
232+ Type : license .Type ,
233+ Year : year ,
239234 }, nil
240235 }
241236 }
242237
243- return & LicenseInfo {
244- Valid : false ,
245- Error : "license header does not match any known license" ,
246- }, nil
238+ return nil , errors .New ("license header does not match any known license" )
247239}
248240
249241// getFileConfig returns the configuration for a given file
0 commit comments