python-jsonschema / check-jsonschema

A CLI and set of pre-commit hooks for jsonschema validation with built-in support for GitHub Workflows, Renovate, Azure Pipelines, and more!
https://check-jsonschema.readthedocs.io/en/stable
Other
191 stars 38 forks source link

Support for `default.json` for `renovate` #337

Closed paddyroddy closed 9 months ago

paddyroddy commented 9 months ago

If you have a shareable preset then renovate recommends having it in a repo called renovate-config and have the file in there called default.json, i.e. https://github.com/paddyroddy/renovate-config/blob/main/default.json. I would like to validate that this default.json is valid, but currently it would be skipped.

sirosen commented 9 months ago

I believe that this is supported today by taking the renovate schema and running it explicitly against the file.

e.g. In pre-commit config:

- repo: https://github.com/python-jsonschema/check-jsonschema
  rev: 0.27.0
  hooks:
  - id: check-renovate-default
    name: Validate default.json Renovate Config
    description: 'Validate Renovate config in default.json'
    entry: check-jsonschema --builtin-schema vendor.renovate
    files: ^default\.json$

You can also run it manually with

check-jsonschema --builtin-schema vendor.renovate default.json

(The pre-commit config I showed is just the config for running this exact command with some nice description.)

I don't see any clear way to support the default.json name out of the box -- it's not a renovate-specific filename outside of the broader context that if you already know that it's a renovate config, it's the recommended name.


Does that satisfy your needs? If not, I'll need more info about the context to understand.

paddyroddy commented 9 months ago

Yes, that would work nicely!

sirosen commented 9 months ago

I've closed this as solved. If it comes up again, I'll consider adding an FAQ doc or similar.

Thanks for stopping by with your question; it helps build the knowledge base!

paddyroddy commented 9 months ago

Just to check (might have missed something obvious), I can see how that can go into .pre-commit-hooks.yaml, is there a way I can - as a user - use that in my .pre-commit-config.yaml?

sirosen commented 8 months ago

That config should be valid for pre-commit-config.

The hooks config looks very similar, so I can understand the confusion. If I've made a mistake such that it's not valid for the user config file, let me know and we can fix it, but it looks right to me (from a mobile device, so I can't test it at the moment).

paddyroddy commented 8 months ago

Think it was just a case of changing the id to match the existing one

- repo: https://github.com/python-jsonschema/check-jsonschema
  rev: 0.27.0
  hooks:
  - id: check-renovate
    name: Validate default.json Renovate Config
    description: 'Validate Renovate config in default.json'
    entry: check-jsonschema --builtin-schema vendor.renovate
    files: ^default\.json$