-
Notifications
You must be signed in to change notification settings - Fork 52
Allow to validate yaml file against its modeline schema #526
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
@click.option( | ||
"--modeline-schema", | ||
is_flag=True, | ||
help="Use the schema defined in the modeline.", | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.