Skip to content

Commit

Permalink
moved logic of filtering rules to ReportLocation
Browse files Browse the repository at this point in the history
  • Loading branch information
Hidanio committed Oct 25, 2024
1 parent d4f7a6d commit b6be64f
Showing 1 changed file with 29 additions and 19 deletions.
48 changes: 29 additions & 19 deletions src/linter/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -1584,25 +1584,6 @@ func (d *rootWalker) Report(n ir.Node, level int, checkName, msg string, args ..
}
}

filePath := d.file.Name()

if d.config.ProjectPath != "" {
// Convert absolute path to relative to the project root

relativePath, err := filepath.Rel(d.config.ProjectPath, filePath)
if err != nil {
d.ReportLocation(loc, level, checkName, msg, args...)
return
}
filePath = relativePath
}

rootNode := d.config.PathRules

if !IsRuleEnabledForPath(rootNode, filePath, checkName) {
return
}

d.ReportLocation(loc, level, checkName, msg, args...)
}

Expand Down Expand Up @@ -1644,6 +1625,35 @@ func (d *rootWalker) ReportLocation(loc ir.Location, level int, checkName, msg s
}
}

filePath := d.file.Name()

if d.config.ProjectPath != "" {
// Convert absolute path to relative to the project root

relativePath, err := filepath.Rel(d.config.ProjectPath, filePath)
if err != nil {
d.reports = append(d.reports, &Report{
CheckName: checkName,
Context: string(contextLine),
StartChar: loc.StartChar,
EndChar: loc.EndChar,
Line: loc.StartLine + 1,
Level: level,
Filename: strings.ReplaceAll(d.ctx.st.CurrentFile, "\\", "/"), // To make output stable between platforms, see #572
Message: fmt.Sprintf(msg, args...),
Hash: hash,
})
return
}
filePath = relativePath
}

rootNode := d.config.PathRules

if !IsRuleEnabledForPath(rootNode, filePath, checkName) {
return
}

d.reports = append(d.reports, &Report{
CheckName: checkName,
Context: string(contextLine),
Expand Down

0 comments on commit b6be64f

Please sign in to comment.