Skip to content

Commit

Permalink
linter: Make operations an array
Browse files Browse the repository at this point in the history
  • Loading branch information
charlieegan3 committed Nov 4, 2024
1 parent 1c1226b commit c231ae4
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 25 deletions.
10 changes: 5 additions & 5 deletions bundle/regal/main/main.rego
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,31 @@ import data.regal.util
# METADATA
# description: set of all notices returned from linter rules
lint.notices := _notices if {
input.regal.operations.lint
"lint" in input.regal.operations
}

# METADATA
# description: map of all ignore directives encountered when linting
lint.ignore_directives[input.regal.file.name] := ast.ignore_directives if {
input.regal.operations.lint
"lint" in input.regal.operations
}

# METADATA
# description: all violations from non-aggregate rules
lint.violations := report if {
input.regal.operations.lint
"lint" in input.regal.operations
}

# METADATA
# description: map of all aggregated data from aggregate rules, keyed by category/title
lint.aggregates := aggregate if {
input.regal.operations.collect
"collect" in input.regal.operations
}

# METADATA
# description: all violations from aggregate rules
lint.aggregate.violations := aggregate_report if {
input.regal.operations.aggregate
"aggregate" in input.regal.operations
}

_rules_to_run[category] contains title if {
Expand Down
10 changes: 5 additions & 5 deletions bundle/regal/main/main_test.rego
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ test_ignore_directive_collected_in_aggregate_rule if {
import data.unresolved
`)

mock_input := object.union(module, {"regal": {"operations": {"lint": true}}})
mock_input := object.union(module, {"regal": {"operations": ["lint"]}})

lint := main.lint with input as mock_input

Expand Down Expand Up @@ -299,7 +299,7 @@ test_camelcase if {
`

module := regal.parse_module("p.rego", policy)
mock_input := object.union(module, {"regal": {"operations": {"lint": true}}})
mock_input := object.union(module, {"regal": {"operations": ["lint"]}})

result := main with input as mock_input
with input.regal.file.name as "stdin"
Expand All @@ -325,7 +325,7 @@ test_main_lint if {

module := regal.parse_module("p.rego", policy)

mock_input := object.union(module, {"regal": {"operations": {"lint": true}}})
mock_input := object.union(module, {"regal": {"operations": ["lint"]}})

cfg := {"rules": {"style": {"use-assignment-operator": {"level": "error"}}}}

Expand Down Expand Up @@ -377,7 +377,7 @@ test_notices if {

notices := main.lint.notices with main._rules_to_run as {"idiomatic": {"testme"}}
with data.regal.rules.idiomatic.testme.notices as {notice}
with input.regal.operations.lint as true
with input.regal.operations as ["lint"]

notices == {notice}
}
Expand Down Expand Up @@ -422,7 +422,7 @@ test_aggregate_report_custom_rule if {
"aggregates_internal": {"custom/test": {}},
"regal": {
"file": {"name": "p.rego"},
"operations": {"aggregate": true},
"operations": ["aggregate"],
},
}

Expand Down
14 changes: 3 additions & 11 deletions internal/embeds/schemas/regal-ast.json
Original file line number Diff line number Diff line change
Expand Up @@ -382,17 +382,9 @@
"type": "object"
},
"operations": {
"type": "object",
"properties": {
"lint": {
"type": "boolean"
},
"collect": {
"type": "boolean"
},
"aggregate": {
"type": "boolean"
}
"type": "array",
"items": {
"type": "string"
}
},
"context": {
Expand Down
11 changes: 7 additions & 4 deletions pkg/linter/linter.go
Original file line number Diff line number Diff line change
Expand Up @@ -841,10 +841,13 @@ func (l Linter) lintWithRegoRules(

regalInput, ok := enhancedAST["regal"].(map[string]any)
if ok {
regalInput["operations"] = map[string]bool{
"lint": true,
"collect": operationCollect,
operations := []string{"lint"}

if operationCollect {
operations = append(operations, "collect")
}

regalInput["operations"] = operations
}

evalArgs := []rego.EvalOption{
Expand Down Expand Up @@ -943,7 +946,7 @@ func (l Linter) lintWithRegoAggregateRules(
// refer to input.regal in an aggregate_report rule
"ignore_directives": ignoreDirectives,
"regal": map[string]any{
"operations": map[string]bool{"aggregate": true},
"operations": []string{"aggregate"},
"file": map[string]any{
"name": "__aggregate_report__",
"lines": []string{},
Expand Down

0 comments on commit c231ae4

Please sign in to comment.