StyraInc / regal

Regal is a linter and language server for Rego, bringing your policy development experience to the next level!
https://docs.styra.com/regal
Apache License 2.0
264 stars 37 forks source link

Use .gitignore for filtering #336

Open anderseknert opened 1 year ago

anderseknert commented 1 year ago

Some configuration options to the ignore attribute that would be nice additions:

ignore:
  # both of these would be true by default
  dot-git-dir: true
  use-git-ignore: true
  files:
    - foo.rego

We currently hard code .git and .idea as we never will want to parse whatever is in there, but exposing these options in config, and using the .gitignore file, would be a better approach.

Thanks @srenatus for the idea.

srenatus commented 3 months ago

https://pkg.go.dev/github.com/sabhiram/go-gitignore#example-CompileIgnoreLines looks like a solid little module for this.

anderseknert commented 3 months ago

While I'm sure it's nowhere near feature complete, @kristiansvalland wrote a simple implementation in Rego way back that we've been using for the ignore patterns users can set in .regal/config.yaml 😃

https://github.com/StyraInc/regal/blob/main/bundle/regal/config/exclusion.rego#L25

It would likely cover our needs, and if not, we should extend it to do that. We'd still need to read the file in Go an provide it as input, of course. And some things I'm not sure about, like if we should handle nested .gitignore files.

srenatus commented 3 months ago

I think defaulting to respecting gitignore files anywhere would be a good call. Like, in mono repos, I'd imagine them to be common, and I personally like to use them on a nested way, too...

anderseknert commented 3 months ago

Yeah, me too. Although if we support that, we should also support nested Regal configurations, which we also don't do 😅