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
251 stars 34 forks source link

Allow linting Rego in Markdown files #611

Open anderseknert opened 5 months ago

anderseknert commented 5 months ago

It would be neat if it was possible to point Regal at Markdown files and have it lint any code blocks with rego set as the language identifier. This should probably be opt-in when Regal is pointed at a directory, but regal lint doc.md should just work.

We'll need to consider that example Rego in markdown files are often just snippets, so we can't assume things like a package declaration. This should be similar to rq in that regard, so we can probably borrow some logic from that project.

Similarly, we'll want to disable any aggregate rules in this context, as those don't make any sense when dealing with snippets.

Later, we might want to allow different configuration options for this, as opa fmt formatting and tabs in particular sadly doesn't look great in most markdown docs (displayed as 8 spaces). But that can be dealt with in follow-up issues.

srenatus commented 5 months ago

This is a cool idea. Having a quick look for prior art, this is the only thing I came across: https://github.com/eslint/eslint-plugin-markdown -- it's for JS, but it validates the idea ✔️

anderseknert commented 5 months ago

Thanks! Yeah, and it'd be a good way to ensure we're not unintentionally breaking our own rules in our own docs. Not sure how we'd best handle linting the "Avoid" blocks, but that's a problem for later 😄