Commit 8c344bc
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: 3f3c7b2a36ee429e64f74d5d1a896cd6f5518c891 parent f905070 commit 8c344bc
File tree
5 files changed
+127
-9
lines changed- selftest/complex/missing-language
- src
- generators
- parsers
5 files changed
+127
-9
lines changedLines changed: 4 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
67 | | - | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
68 | 77 | | |
69 | 78 | | |
70 | 79 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
96 | 96 | | |
97 | 97 | | |
98 | 98 | | |
99 | | - | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
100 | 112 | | |
101 | 113 | | |
102 | 114 | | |
| |||
140 | 152 | | |
141 | 153 | | |
142 | 154 | | |
143 | | - | |
| 155 | + | |
144 | 156 | | |
145 | 157 | | |
146 | 158 | | |
147 | 159 | | |
148 | 160 | | |
149 | 161 | | |
150 | | - | |
| 162 | + | |
151 | 163 | | |
152 | 164 | | |
153 | 165 | | |
| |||
160 | 172 | | |
161 | 173 | | |
162 | 174 | | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
163 | 187 | | |
164 | 188 | | |
165 | 189 | | |
| |||
202 | 226 | | |
203 | 227 | | |
204 | 228 | | |
205 | | - | |
| 229 | + | |
206 | 230 | | |
207 | 231 | | |
208 | | - | |
209 | | - | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
210 | 257 | | |
211 | 258 | | |
212 | 259 | | |
| |||
220 | 267 | | |
221 | 268 | | |
222 | 269 | | |
223 | | - | |
224 | 270 | | |
225 | 271 | | |
226 | 272 | | |
| |||
238 | 284 | | |
239 | 285 | | |
240 | 286 | | |
241 | | - | |
| 287 | + | |
242 | 288 | | |
243 | 289 | | |
244 | 290 | | |
| |||
294 | 340 | | |
295 | 341 | | |
296 | 342 | | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
297 | 347 | | |
298 | 348 | | |
299 | 349 | | |
| |||
339 | 389 | | |
340 | 390 | | |
341 | 391 | | |
| 392 | + | |
342 | 393 | | |
343 | 394 | | |
344 | 395 | | |
| |||
761 | 812 | | |
762 | 813 | | |
763 | 814 | | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
764 | 840 | | |
0 commit comments