Back to Opa

use-strings-count

docs/projects/regal/rules/idiomatic/use-strings-count.md

1.16.1995 B
Original Source

use-strings-count

Summary: Use strings.count where possible

Category: Idiomatic

Avoid

rego
package policy

num_as := count(indexof_n("foobarbaz", "a"))

Prefer

rego
package policy

num_as := strings.count("foobarbaz", "a")

Rationale

The strings.count function added in OPA v0.67.0 is both more readable and efficient compared to using count(indexof_n(...)) and should therefore be preferred.

Configuration Options

This linter rule provides the following configuration options:

yaml
rules:
  idiomatic:
    use-strings-count:
      # one of "error", "warning", "ignore"
      level: error