Skip to content
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

feat(queries): fix equals pattern matching regal lint issue #7363

Open
wants to merge 50 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
4477f67
add initial regal lint setup
ArturRibeiro-CX Feb 23, 2025
3cd6fc2
test regal linter
ArturRibeiro-CX Feb 23, 2025
bb6bc2f
revert rego changes
ArturRibeiro-CX Feb 23, 2025
b012c13
opa fmt lint fixes on all rego files
ArturRibeiro-CX Feb 23, 2025
336243f
ignore all linter rules besides opa-fmt
ArturRibeiro-CX Feb 23, 2025
70b2757
add new lint rules to ignore
ArturRibeiro-CX Feb 23, 2025
7223ef4
reorganize lint rules into the right rule
ArturRibeiro-CX Feb 23, 2025
24470f0
add more rules to the config file
ArturRibeiro-CX Feb 23, 2025
505e5c4
add more rules and fix opa-fmt problem
ArturRibeiro-CX Feb 23, 2025
3da838e
test to check lint rule-shadows-builtin issues
ArturRibeiro-CX Feb 24, 2025
4a7a327
fix rule shadows builtin lint issue in .rego queries
ArturRibeiro-CX Feb 24, 2025
2f8f66d
fix lint
ArturRibeiro-CX Feb 24, 2025
a1c5db6
update level on var-shadows-builtin to tackle lint issues
ArturRibeiro-CX Feb 24, 2025
853b31f
fix var-shadows-builtin lint issues
ArturRibeiro-CX Feb 24, 2025
5e4cbf8
fix var-shadows-builtin lint issues
ArturRibeiro-CX Feb 25, 2025
f6b7aa8
Merge branch 'master' into regal-var-shadows-builtin
ArturRibeiro-CX Feb 25, 2025
d0bfc17
Merge branch 'regal-var-shadows-builtin' of https://github.com/Checkm…
ArturRibeiro-CX Feb 25, 2025
0954762
fix var-shadows-builtin lint issues
ArturRibeiro-CX Feb 25, 2025
383e6c5
first commit to trigger regal linter non-raw-regex-pattern
ArturRibeiro-CX Feb 26, 2025
f8740d1
fix non-raw-regex-pattern lint issues
ArturRibeiro-CX Feb 26, 2025
14bc51e
fix non-raw-regex-pattern lint issues
ArturRibeiro-CX Feb 26, 2025
b70dd5b
initial commit to trigger regal linter no-whitespace-comment rule
ArturRibeiro-CX Feb 28, 2025
03a7880
Merge branch 'master' into regal-no-whitespace-comment
ArturRibeiro-CX Feb 28, 2025
84eb2e8
initial fix to regal linter no-whitespace-comment rule
ArturRibeiro-CX Feb 28, 2025
1a12a27
fix to regal linter no-whitespace-comment rule
ArturRibeiro-CX Feb 28, 2025
d872fb5
fix to regal linter no-whitespace-comment rule
ArturRibeiro-CX Feb 28, 2025
5837e53
fix to regal linter no-whitespace-comment rule
ArturRibeiro-CX Feb 28, 2025
543fd8e
fix to regal linter no-whitespace-comment rule
ArturRibeiro-CX Feb 28, 2025
d18bcdb
initial commit to trigger to regal linter use-in-operator rule
ArturRibeiro-CX Feb 28, 2025
a0e06ca
Fix regal linter use-in-operator rule
ArturRibeiro-CX Feb 28, 2025
b1f6f12
Fix regal linter use-in-operator rule
ArturRibeiro-CX Feb 28, 2025
5b15168
Fix regal linter use-in-operator rule
ArturRibeiro-CX Feb 28, 2025
c6dbf01
test fix reverting one lint change
ArturRibeiro-CX Mar 1, 2025
8bcdb28
test fix reverting one lint change
ArturRibeiro-CX Mar 1, 2025
356ed5b
fix all tests by reverting some lint change
ArturRibeiro-CX Mar 1, 2025
030c9ef
fix use in operator lint issue
ArturRibeiro-CX Mar 1, 2025
a40dddd
fix openAPI tests removing in keyword
ArturRibeiro-CX Mar 1, 2025
9f187c2
fix openAPI lint issues
ArturRibeiro-CX Mar 1, 2025
35d47fe
fix gcp test errors
ArturRibeiro-CX Mar 1, 2025
6918d24
fix unit k8s tests
ArturRibeiro-CX Mar 1, 2025
8a74e62
Initial commit to trigger custom has key construct regal lint issue
ArturRibeiro-CX Mar 1, 2025
78c3227
revert last commit
ArturRibeiro-CX Mar 1, 2025
f3e6a01
Initial commit to trigger custom has key construct regal lint issue
ArturRibeiro-CX Mar 1, 2025
5d565c5
fix custom has key construct regal lint issue
ArturRibeiro-CX Mar 1, 2025
5122515
fix errors
ArturRibeiro-CX Mar 1, 2025
a5003ec
fix errors
ArturRibeiro-CX Mar 1, 2025
ed8fce6
fix remaining regal lint issues
ArturRibeiro-CX Mar 1, 2025
e308947
remove unused function
ArturRibeiro-CX Mar 1, 2025
012069c
initial commit to trigger equals-pattern-matching regal lint issue
ArturRibeiro-CX Mar 1, 2025
694621e
fix equals-pattern-matching regal lint issue
ArturRibeiro-CX Mar 1, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
24 changes: 24 additions & 0 deletions .github/workflows/validate-rego.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: validate-rego

on:
pull_request:
paths:
- "assets/**/*.rego"

jobs:
lint-rego:
name: Run Regal Linter on Rego Files
runs-on: ubuntu-latest
steps:
- name: Check out repository code
uses: actions/checkout@v4
with:
persist-credentials: false

- name: Setup Regal
uses: StyraInc/setup-regal@33a142b1189004e0f14bf42b15972c67eecce776 #v1.0.0
with:
version: v0.31.0

- name: Run Regal Linter
run: regal lint --format=github assets --config-file=assets/.regal/config.yml
138 changes: 138 additions & 0 deletions assets/.regal/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
# Since the linting rules will be tackled in separate PRs, we are temporarily ignoring all rules.
# We will update rule severities as each PR is merged.

rules:
bugs:
not-equals-in-loop:
# https://docs.styra.com/regal/rules/bugs/not-equals-in-loop
level: ignore
rule-shadows-builtin:
# https://docs.styra.com/regal/rules/bugs/rule-shadows-builtin
level: warn
var-shadows-builtin:
# https://docs.styra.com/regal/rules/bugs/var-shadows-builtin
level: warn
unused-output-variable:
# https://docs.styra.com/regal/rules/bugs/unused-output-variable
level: ignore
deprecated-builtin:
# https://docs.styra.com/regal/rules/bugs/deprecated-builtin
level: ignore
leaked-internal-reference:
# https://docs.styra.com/regal/rules/bugs/leaked-internal-reference
level: ignore
sprintf-arguments-mismatch:
# https://docs.styra.com/regal/rules/bugs/sprintf-arguments-mismatch
level: ignore
inconsistent-args:
# https://docs.styra.com/regal/rules/bugs/inconsistent-args
level: ignore
redundant-existence-check:
# https://docs.styra.com/regal/rules/bugs/redundant-existence-check
level: ignore
idiomatic:
no-defined-entrypoint:
# https://docs.styra.com/regal/rules/idiomatic/no-defined-entrypoint
# No single entrypoint for this project
level: ignore
# temporary
non-raw-regex-pattern:
# https://docs.styra.com/regal/rules/idiomatic/non-raw-regex-pattern
level: warn
use-in-operator:
# https://docs.styra.com/regal/rules/idiomatic/use-in-operator
level: warn
use-some-for-output-vars:
# https://docs.styra.com/regal/rules/idiomatic/use-some-for-output-vars
# These would be good to address, but would require a concentrated effort
level: ignore
custom-has-key-construct:
# https://docs.styra.com/regal/rules/idiomatic/custom-has-key-construct
level: warn
equals-pattern-matching:
# https://docs.styra.com/regal/rules/idiomatic/equals-pattern-matching
level: warn
use-contains:
# https://docs.styra.com/regal/rules/idiomatic/use-contains
level: ignore
use-if:
# https://docs.styra.com/regal/rules/idiomatic/use-if
level: ignore
directory-package-mismatch:
# https://docs.styra.com/regal/rules/idiomatic/directory-package-mismatch
level: ignore
custom-in-construct:
# https://docs.styra.com/regal/rules/idiomatic/custom-in-construct
level: ignore
style:
avoid-get-and-list-prefix:
# https://docs.styra.com/regal/rules/style/avoid-get-and-list-prefix
level: ignore
external-reference:
# https://docs.styra.com/regal/rules/style/external-reference
level: ignore
file-length:
# https://docs.styra.com/regal/rules/style/file-length
level: ignore
line-length:
# https://docs.styra.com/regal/rules/style/line-length
level: ignore
no-whitespace-comment:
# https://docs.styra.com/regal/rules/style/no-whitespace-comment
level: warn
opa-fmt:
# https://docs.styra.com/regal/rules/style/opa-fmt
level: warn
prefer-some-in-iteration:
# https://docs.styra.com/regal/rules/style/prefer-some-in-iteration
# 10000+ violations fixed but way more to go
level: ignore
prefer-snake-case:
# https://docs.styra.com/regal/rules/style/prefer-snake-case
level: ignore
rule-length:
# https://docs.styra.com/regal/rules/style/rule-length
level: ignore
todo-comment:
# https://docs.styra.com/regal/rules/style/todo-comment
# only one TODO comment in the codebase to fix this issue
level: ignore
use-assignment-operator:
# https://docs.styra.com/regal/rules/style/use-assignment-operator
level: ignore
rule-name-repeats-package:
# https://docs.styra.com/regal/rules/style/rule-name-repeats-package
level: ignore
messy-rule:
# https://docs.styra.com/regal/rules/style/messy-rule
level: ignore
comprehension-term-assignment:
# https://docs.styra.com/regal/rules/style/comprehension-term-assignment
level: ignore
pointless-reassignment:
# https://docs.styra.com/regal/rules/style/pointless-reassignment
level: ignore
unconditional-assignment:
# https://docs.styra.com/regal/rules/style/unconditional-assignment
level: ignore
default-over-else:
# https://docs.styra.com/regal/rules/style/default-over-else
level: ignore
imports:
use-rego-v1:
# https://docs.styra.com/regal/rules/imports/use-rego-v1
level: ignore
redundant-alias:
# https://docs.styra.com/regal/rules/performance/non-loop-expression
level: ignore
import-after-rule:
# https://docs.styra.com/regal/rules/imports/import-after-rule
level: ignore
performance:
non-loop-expression:
# https://docs.styra.com/regal/rules/performance/non-loop-expression
level: ignore
defer-assignment:
# https://docs.styra.com/regal/rules/performance/defer-assignment
level: ignore

30 changes: 14 additions & 16 deletions assets/libraries/ansible.rego
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package generic.ansible

import future.keywords.in

# Global variable with all tasks in input
tasks := TasksPerDocument

Expand Down Expand Up @@ -33,14 +35,12 @@ getTasksFromBlocks(playbook) = result {
not task.block
validPath(path)
]
} else = [playbook] {
true
}
} else = [playbook]

# Validates the path of a nested element inside a block task to assure it's a task
validPath(path) {
count(path) > 1
validGroup(path[minus(count(path), 2)])
validGroup(path[count(path) - 2])
}

# Identifies a block task
Expand Down Expand Up @@ -95,10 +95,8 @@ allowsPort(allowed, port) {
low <= portNumber
high >= portNumber
} else {
allowed.ports[_] == port
} else = false {
true
}
port in allowed.ports
} else = false

# Checks if a given port is included in a network rule
isPortInRule(rule, portNumber) {
Expand All @@ -112,7 +110,7 @@ isPortInRule(rule, portNumber) {
}

isPortInRule(rule, portNumber) {
rule.ports[_] == portNumber
portNumber in rule.ports
}

isPortInRule(rule, portNumber) {
Expand Down Expand Up @@ -149,11 +147,11 @@ isEntireNetwork(cidr) {
}

installer_modules := [
"community.general.apk", "ansible.builtin.apt", "ansible.builtin.apt", "community.general.bundler", "ansible.builtin.dnf", "community.general.easy_install",
"community.general.gem", "community.general.homebrew", "community.general.jenkins_plugin", "community.general.npm", "community.general.openbsd_pkg",
"ansible.builtin.package", "ansible.builtin.package", "community.general.pear", "community.general.pacman", "ansible.builtin.pip", "community.general.pkg5",
"community.general.pkgutil", "community.general.pkgutil", "community.general.portage", "community.general.slackpkg", "community.general.sorcery",
"community.general.swdepot", "win_chocolatey", "community.general.yarn", "ansible.builtin.yum", "community.general.zypper", "apk", "apt", "bower", "bundler",
"dnf", "easy_install", "gem", "homebrew", "jenkins_plugin", "npm", "openbsd_package", "openbsd_pkg", "package", "pacman", "pear", "pip", "pkg5", "pkgutil",
"community.general.apk", "ansible.builtin.apt", "ansible.builtin.apt", "community.general.bundler", "ansible.builtin.dnf", "community.general.easy_install",
"community.general.gem", "community.general.homebrew", "community.general.jenkins_plugin", "community.general.npm", "community.general.openbsd_pkg",
"ansible.builtin.package", "ansible.builtin.package", "community.general.pear", "community.general.pacman", "ansible.builtin.pip", "community.general.pkg5",
"community.general.pkgutil", "community.general.pkgutil", "community.general.portage", "community.general.slackpkg", "community.general.sorcery",
"community.general.swdepot", "win_chocolatey", "community.general.yarn", "ansible.builtin.yum", "community.general.zypper", "apk", "apt", "bower", "bundler",
"dnf", "easy_install", "gem", "homebrew", "jenkins_plugin", "npm", "openbsd_package", "openbsd_pkg", "package", "pacman", "pear", "pip", "pkg5", "pkgutil",
"portage", "slackpkg", "sorcery", "swdepot", "win_chocolatey", "yarn", "yum", "zypper",
]
]
21 changes: 10 additions & 11 deletions assets/libraries/azureresourcemanager.rego
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ package generic.azureresourcemanager

# gets the network security group properties for two types of resource ('Microsoft.Network/networkSecurityGroups' and 'Microsoft.Network/networkSecurityGroups/securityRules')
get_sg_info(value) = typeInfo {
value.type == "Microsoft.Network/networkSecurityGroups/securityRules"
value.type == "Microsoft.Network/networkSecurityGroups/securityRules"
typeInfo := {
"type": value.type,
"properties": value.properties,
"type": value.type,
"properties": value.properties,
"path": "resources.type={{Microsoft.Network/networkSecurityGroups/securityRules}}.properties",
"sl": ["properties"]
}
"sl": ["properties"],
}
} else = typeInfo {
value.type == "securityRules"
typeInfo := {
"type": value.type,
"properties": value.properties,
"type": value.type,
"properties": value.properties,
"path": "resources.type={{securityRules}}.properties",
"sl": ["properties"]
"sl": ["properties"],
}
}

Expand Down Expand Up @@ -84,11 +84,10 @@ isParameterReference(valueToCheck) = parameterName {
parameterName := trim_right(trim_left(trim_left(valueToCheck, "[parameters"), "('"), "')]")
}


isDisabledOrUndefined(doc, resource, parametersPath){
isDisabledOrUndefined(doc, resource, parametersPath) {
object.get(resource, split(parametersPath, "."), "not defined") == "not defined"
} else {
value := object.get(resource, split(parametersPath, "."),"")
value := object.get(resource, split(parametersPath, "."), "")
[check, _] := getDefaultValueFromParametersIfPresent(doc, value)
check == false
}
1 change: 0 additions & 1 deletion assets/libraries/cicd.rego
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
package generic.cicd

Loading
Loading