Allow to validate yaml file against its modeline schema#526
Allow to validate yaml file against its modeline schema#526nikaro wants to merge 1 commit intopython-jsonschema:mainfrom
Conversation
| @click.option( | ||
| "--modeline-schema", | ||
| is_flag=True, | ||
| help="Use the schema defined in the modeline.", | ||
| ) |
There was a problem hiding this comment.
Maybe --yaml-modeline-schema? Since this is very specific to YAML for now... or maybe going with this and raising a NotImplementedError on other content than yaml?
| pattern = r"^# yaml-language-server: \$schema=(?P<schema>.*)$" | ||
| match = re.match(pattern, modeline.decode()) | ||
| if not match: | ||
| raise Exception("Modeline with schema not found.") |
There was a problem hiding this comment.
Maybe there is something better than raising a bare Exception here.
|
Thanks for the idea and the PR! I'm still thinking about this, but I'm actually pretty well inclined towards this solution. I've wanted a generic flag for picking up on the schema from files for YAML modelines and from JSON files which use My big questions right now are about how we parse the modeline. And we'll need some tests to validate the behavior. I need to give this more attention to get the details right, but this is a great start! |
As an user of check-jsonschema through pre-commit hooks, I would find very convenient to enable this for all yaml files using a dedicated hook or an additional argument in one of the existing hooks.
As this feature request is inspired from a vscode extension, I have looked for the way they handle it. Here is the piece of code they use to find the modeline: if I am not mistaken, it basically checks every yaml comments of the source file. |
Hello 👋
This is a quick and dirty attempt at implementing #340
I submit it to gather some feedback before eventually going further... Am i going in the right way? What would your suggestions and improvements?
Regards.