gpoore / codebraid

Live code in Pandoc Markdown
BSD 3-Clause "New" or "Revised" License
367 stars 13 forks source link

lint embedded code #19

Open micheelengronne opened 4 years ago

micheelengronne commented 4 years ago

I currently have separated doc linted with markdown-lint and scripts linted with shellcheck. I would like to merge the 2 to avoid doc maintenance.

Is there a way to run shellcheck with codebraid to lint the embedded code and not break the execution afterward ?

Thanks.

gpoore commented 4 years ago

There isn't a built-in way to do this, but there are several ways it could be done.

The fastest way to get something working would be to extract the code from the markdown via regex and then lint it, keeping track of line numbers between markdown and extracted code for tracing back line numbers. You could take the shellcheck messages, and then substitute line numbers to get back to markdown. I'm planning to add a codebraid feature that will allow all embedded code to be extracted and saved into separate files, so at some point using that will be an option. That will be cleaner than using a regex, but otherwise similar overall.

Here's another option that may be more interesting, but would also involve a bit more work and thus could take longer to get going. codebraid already has built-in machinery for treating code as input for a compiler or interpreter, and then syncing stdout and stderr with markdown and including it in the output document. I could modify that slightly so that code can also be treated as input for a linter, and then linting messages could appear in the output document next to the relevant code just like stderr does now.

micheelengronne commented 4 years ago

That looks promising. I will test the codebraid feature that extracts code when released. I put this issue in my bookmarks.