-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Native way to validate crystal docs code examples #9978
Comments
This has been mentioned in previous discussions (#6315 (comment) ff.) and I've had this in the back of my head for some time. It would be really great to have this! However, I've been thinking a bit wider: Validating Crystal code examples is a most important feature. But actually, I'd also like to be able to validate code blocks in other languages (YAML or HTML for example). Maybe also general Markdown syntax or a style guide on body copy. This approach would have a huge benefit over an internal compiler feature: It can easily re-purposed for other sources of documentation content. The language reference would also get example code validation with exactly the same mechanism. Now the biggest problem is that to my knowledge such kind of validator multiplexer doesn't exist yet. At least not that I'm aware of. There are several instances of Markdown linters available with varying feature sets, but I haven't found one that could delegate code blocks to other tools for processing. This isn't really difficult to implement, I have a basic PoC at https://github.com/straight-shoota/md-code-linter (not sure if it works currently, but the code should given an idea how it works). |
@straight-shoota It is possible expose all code blocks in a serialized format, like JSON. It won't be hard to do, and external tools can consume it for linting. I still think to validate at least Crystal code natively would be a good thing. Of course, it is opt-in with a CLI option. |
Extracting the code blocks really isn't a problem. A relatively simple grep over the source files should do (alternatively over I wouldn't integrate this into docs generator. It's a different task and the generator should just work despite any example code issues. It's more closely related to So we'll have to figure out what's necessary for that. We might have to consider slight changes to the example code format (such annotations to disable checker for code that isn't supposed to compile). |
Thanks to @maiha , there is already https://github.com/maiha/crystal-examples to validate our code blocks examples put in the comments.
I think it will be useful to have this kind of tool natively in the
crystal docs
tool.I already have a (very) basic POC, which adds like ~30 line of codes. Some snippets like this one are failing, obviously:
Result
Note: the
# =>
results are not checked (for now).The text was updated successfully, but these errors were encountered: