-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Explode loudly on missing Markdown code block language specifier
Summary: # What Fix this foot-gun: # Test something important ``` $ echo fo foo ``` This is *not a test* because the `scrut` language specifier is missing. That is, it should be: # Test something important ```scrut $ echo fo foo ``` To fix this: `scrut` will now explode when any code block in a Markdown test file is missing a language specifier. `plaintext` and `not-scrut-leave-me-alone` are perfectly valid language specifiers! # How * Updated markdown parsing to recognise code blocks without a language specifier as a markdown block - until now, they were treated as plain text lines. * Updated markdown parsing and generation with a `MarkdownToken::VerbatimCodeBlock` token that represents any Markdown code block that's *not* a Scrut test. Renamed `MarkdownToken::CodeBlock` to `MarkdownToken::TestCodeBlock` for clarity and symmetry. * Made the parser explode when a `VerbatimCodeBlock` has no language specified. * Updated the Markdown generator to correctly handle `VerbatimCodeBlock` # Alternatives Considered * Implementing a linter would be a similar amount of work, and require additional integration steps in OSS * We could make this feature opt-in (or opt-out) with a flag for easier migration; however, `scrut` in OSS has little adoption (and no stable release), and so we don't expect this to be an issue. Reviewed By: AndreasBackx Differential Revision: D64597015 fbshipit-source-id: 3f3c7b2a36ee429e64f74d5d1a896cd6f5518c89
- Loading branch information
1 parent
f905070
commit 8c344bc
Showing
5 changed files
with
127 additions
and
9 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
selftest/complex/missing-language/missing-language-empty-block.mdtest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Example EMPTY code block without a language specified | ||
|
||
``` | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Error on code block with no language specified | ||
|
||
```scrut | ||
$ $SCRUT_BIN test --match-markdown "*.mdtest" "$TESTDIR"/missing-language.mdtest 2>&1 | ||
* parse test from "*missing-language.mdtest" with markdown parser (glob) | ||
Caused by: | ||
Code block starting at line 2 is missing language specifier. Use ```scrut to make this block a Scrut test, or any other language to make Scrut skip this block. | ||
* (glob?) | ||
[1] | ||
``` | ||
|
||
# Error on EMPTY code block with no language specified | ||
|
||
```scrut | ||
$ $SCRUT_BIN test --match-markdown "*.mdtest" "$TESTDIR"/missing-language-empty-block.mdtest 2>&1 | ||
* parse test from "*missing-language-empty-block.mdtest" with markdown parser (glob) | ||
Caused by: | ||
Code block starting at line 2 is missing language specifier. Use ```scrut to make this block a Scrut test, or any other language to make Scrut skip this block. | ||
* (glob?) | ||
[1] | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Example code block without a language specified | ||
|
||
``` | ||
$ echo foo | ||
foo | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters