StyraInc / regal

Regal is a linter for Rego, with the goal of making your Rego magnificent!
https://docs.styra.com/regal
Apache License 2.0
237 stars 30 forks source link

style/prefer-snake-case inconsistent #899

Closed srenatus closed 1 day ago

srenatus commented 4 days ago

this PG

package play

import rego.v1

output["initToggled"] if input.karma > 1

output["userKarma"] := input.karma # line 7

shows me one finding, style/prefer-snake-case on line 7

I would expect it to flag line 5 ("initToggled"), too. Or neither one of them; but having one of the two fail seems a little odd 🤔

anderseknert commented 4 days ago

Very! I'll take a look. Thanks for reporting that!

anderseknert commented 4 days ago

Running regal parse p.rego | opa eval -f pretty -I '[h | h := input.rules[_].head]' and looking at the refs, the first one does not come with location attributes, which is why evaluation fails in that case, and the violation remains unreported although it was found.

    "ref": [
      {
        "type": "var",
        "value": "output"
      },
      {
        "type": "string",
        "value": "initToggled"
      }
    ],
    "ref": [
      {
        "location": {
          "col": 1,
          "row": 7,
          "text": "b3V0cHV0"
        },
        "type": "var",
        "value": "output"
      },
      {
        "location": {
          "col": 8,
          "row": 7,
          "text": "InVzZXJLYXJtYSI="
        },
        "type": "string",
        "value": "userKarma"
      }
    ],

OPA bug, I guess? Either way, I'll try to come up with some workaround in the meantime.

anderseknert commented 3 days ago

OPA issue created: https://github.com/open-policy-agent/opa/issues/6860