-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
linter: mask filtering rules path #1244
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1526,21 +1526,79 @@ func IsRuleEnabledForPath(root *RuleNode, filePath string, checkRule string) boo | |
// Starting with global state. We have guarantee while parsing config that rule is `on` and exist | ||
ruleState := true | ||
|
||
for _, part := range parts { | ||
i := 0 | ||
for i < len(parts) { | ||
part := parts[i] | ||
if part == "" { | ||
i++ | ||
continue | ||
} | ||
if node, exists := currentNode.Children[part]; exists { | ||
if node.Disabled[checkRule] { | ||
ruleState = false // Disable on this path | ||
|
||
// 1) Try to find precision node (part) | ||
nextNode, ok := currentNode.Children[part] | ||
if ok { | ||
// If found precision node: apply Enabled/Disabled | ||
if nextNode.Disabled[checkRule] { | ||
ruleState = false | ||
} | ||
if node.Enabled[checkRule] { | ||
ruleState = true // Enable on this path | ||
if nextNode.Enabled[checkRule] { | ||
ruleState = true | ||
} | ||
currentNode = node | ||
} else { | ||
currentNode = nextNode | ||
i++ | ||
continue | ||
} | ||
|
||
// 2) If there is no exact match, lets find node "*" (wildcard) | ||
starNode, ok := currentNode.Children["*"] | ||
if !ok { | ||
// not precision matching & not "*" | ||
break | ||
} | ||
|
||
// Apply Enabled/Disabled for "*" | ||
if starNode.Disabled[checkRule] { | ||
ruleState = false | ||
} | ||
if starNode.Enabled[checkRule] { | ||
ruleState = true | ||
} | ||
|
||
// move to node "*" | ||
currentNode = starNode | ||
|
||
// Now the logic is to "swallow" several directories: | ||
// | ||
// Until we meet an exact match in `Children` in the next step | ||
// (except "*"), we can continue to "eat" directories while remaining in `starNode`. | ||
// | ||
// Or if we have reached the end of the path, we exit the loop. | ||
|
||
for { | ||
i++ | ||
if i >= len(parts) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you don't change the |
||
// the path ended - all remaining directories were swallowed | ||
return ruleState | ||
} | ||
AfterStarPart := parts[i] | ||
|
||
// if starNode have Children[AfterStarPart] (except "*"), | ||
// so we found the next "literal" node, we exit the inner loop, | ||
// to go through the usual logic at the top level. | ||
if AfterStarPart == "" { | ||
continue | ||
} | ||
|
||
_, hasLiteral := currentNode.Children[AfterStarPart] | ||
if hasLiteral { | ||
// Let's exit - let the outer loop handle it | ||
break | ||
} | ||
|
||
// There are directories left - we eat them, continuing the while loop | ||
} | ||
// Exit to outer loop: i points to potential literal part | ||
// (or "*"), but the outer iteration will re-check it | ||
} | ||
|
||
return ruleState | ||
|
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in go
for-range
returns the index and the value of the elements in each index. Are you sure you should have changed it tofor-loop
?