From 5c73dfdef4ff7b7e03d4eb78d3cf347d3a5f1554 Mon Sep 17 00:00:00 2001 From: Richardas Kuchinskas Date: Wed, 10 Jul 2024 15:00:58 +0300 Subject: [PATCH] added multiple path --- src/linter/utils.go | 22 ++++++++++++---------- src/rules/parser.go | 8 +++++--- src/rules/rules.go | 2 +- src/rules/util.go | 6 ++++-- 4 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/linter/utils.go b/src/linter/utils.go index f673fdc8..4cc8809c 100644 --- a/src/linter/utils.go +++ b/src/linter/utils.go @@ -68,15 +68,15 @@ func mergeTypeMaps(left types.Map, right types.Map) types.Map { // The types are inferred as follows: // 1. If there is a @return annotation, then its value becomes the return type; // -// 2. If there is a type hint, then it is added to the types from the @return. -// If the @return is empty, then the type matches the type hint itself; +// 2. If there is a type hint, then it is added to the types from the @return. +// If the @return is empty, then the type matches the type hint itself; // -// 3. If the resulting type is mixed[], then if the actual type is a specific -// array type, then we use it, otherwise we combine this type with the -// resulting mixed[] type. +// 3. If the resulting type is mixed[], then if the actual type is a specific +// array type, then we use it, otherwise we combine this type with the +// resulting mixed[] type. // -// 4. If there is no @return annotation and type hint, then the return type is equal to -// the union of the types that are returned from the function by return. +// 4. If there is no @return annotation and type hint, then the return type is equal to +// the union of the types that are returned from the function by return. func functionReturnType(phpdocReturnType types.Map, hintReturnType types.Map, actualReturnTypes types.Map) types.Map { var returnTypes types.Map if !phpdocReturnType.Empty() || !hintReturnType.Empty() { @@ -494,10 +494,12 @@ func cloneRulesForFile(filename string, ruleSet *rules.ScopedSet) *rules.ScopedS for kind, ruleByKind := range &ruleSet.RulesByKind { res := make([]rules.Rule, 0, len(ruleByKind)) for _, rule := range ruleByKind { - if !strings.Contains(filename, rule.Path) || isFilePathExcluded(filename, rule) { - continue + for _, path := range rule.Path { + if !strings.Contains(filename, path) || isFilePathExcluded(filename, rule) { + continue + } + res = append(res, rule) } - res = append(res, rule) } clone.Set(ir.NodeKind(kind), res) } diff --git a/src/rules/parser.go b/src/rules/parser.go index 3eb6fd3e..e3a99b4d 100644 --- a/src/rules/parser.go +++ b/src/rules/parser.go @@ -231,10 +231,12 @@ func (p *parser) parseRuleInfo(st ir.Node, labelStmt ir.Node, proto *Rule) (Rule if len(part.Params) != 1 { return rule, p.errorf(st, "@path expects exactly 1 param, got %d", len(part.Params)) } - if rule.Path != "" { - return rule, p.errorf(st, "duplicate @path constraint") + + if rule.Path == nil { + rule.Path = make([]string, 0) } - rule.Path = part.Params[0] + + rule.Path = append(rule.Path, part.Params...) case "path-exclude": if len(part.Params) != 1 { return rule, p.errorf(st, "@exclude expects exactly 1 param, got %d", len(part.Params)) diff --git a/src/rules/rules.go b/src/rules/rules.go index 5480585b..875af3bc 100644 --- a/src/rules/rules.go +++ b/src/rules/rules.go @@ -98,7 +98,7 @@ type Rule struct { // Path is a filter-like rule switcher. // A rule is only applied to a file that contains a Path as a substring in its name. - Path string + Path []string // PathExcludes is a filter-like rule switcher. // A rule is not applied to a file that contains a PathExcludes as a substring in its name. diff --git a/src/rules/util.go b/src/rules/util.go index af84c003..1d8a2aee 100644 --- a/src/rules/util.go +++ b/src/rules/util.go @@ -20,8 +20,10 @@ func formatRule(r *Rule) string { buf.WriteString(" * @maybe " + r.Message + "\n") } - if r.Path != "" { - buf.WriteString(" * @path " + r.Path + "\n") + if len(r.Path) > 0 { + for _, path := range r.Path { + buf.WriteString(" * @path " + path + "\n") + } } if r.PathExcludes != nil {