From ed85e6b3f6989ca415f9b840397230a15aec2a7e Mon Sep 17 00:00:00 2001 From: Richardas Kuchinskas Date: Fri, 25 Oct 2024 14:33:17 +0300 Subject: [PATCH] moved logic of filtering rules to ReportLocation --- src/linter/root.go | 48 ++++++++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/src/linter/root.go b/src/linter/root.go index 44b3dd29..1f5f63de 100644 --- a/src/linter/root.go +++ b/src/linter/root.go @@ -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...) } @@ -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),