-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
all: added support for multi-file rule sets (#64)
-rules flag becomes a comma-separated list of rule filenames. If only one filename is provided, no effects will be noticed. If more than one filenames are provided, they are merged into one rule set that combines all rules. To avoid information loss, we pass GoRuleInfo object to the Report() callback, so the application can figure out which file provided a rule that triggered. As a demonstration, cmd/ruleguard now appends the "(filename)" suffix to the warning messages when executed with multiple rule files. The new ruleguard.MergeRuleSets() function can be used in integrations like go-critic/go-critic#947 Signed-off-by: Iskander Sharipov <[email protected]>
- Loading branch information
Showing
6 changed files
with
84 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package ruleguard | ||
|
||
func mergeRuleSets(toMerge []*GoRuleSet) *GoRuleSet { | ||
out := &GoRuleSet{ | ||
local: &scopedGoRuleSet{}, | ||
universal: &scopedGoRuleSet{}, | ||
} | ||
|
||
for _, x := range toMerge { | ||
out.local = appendScopedRuleSet(out.local, x.local) | ||
out.universal = appendScopedRuleSet(out.universal, x.universal) | ||
} | ||
|
||
return out | ||
} | ||
|
||
func appendScopedRuleSet(dst, src *scopedGoRuleSet) *scopedGoRuleSet { | ||
dst.uncategorized = append(dst.uncategorized, src.uncategorized...) | ||
for cat, rules := range src.rulesByCategory { | ||
dst.rulesByCategory[cat] = append(dst.rulesByCategory[cat], rules...) | ||
dst.categorizedNum += len(rules) | ||
} | ||
return dst | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters