Skip to content

Commit

Permalink
added multiple path
Browse files Browse the repository at this point in the history
  • Loading branch information
Hidanio committed Jul 10, 2024
1 parent 3e99dc9 commit 5c73dfd
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 16 deletions.
22 changes: 12 additions & 10 deletions src/linter/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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)
}
Expand Down
8 changes: 5 additions & 3 deletions src/rules/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion src/rules/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 4 additions & 2 deletions src/rules/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 5c73dfd

Please sign in to comment.