1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-25 15:29:32 -05:00

fix(cli): explicitly scan for ignore attribute in inline tests (#11647)

This commits adds "ignore" as a known attribute for Markdown 
codeblock which drops a code block early whenever it is seen 
in documentation tests.
This commit is contained in:
Casper Beyer 2021-08-14 18:33:58 +08:00 committed by GitHub
parent 1d1507384b
commit f90231924d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 11 deletions

View file

@ -18,6 +18,12 @@ The following block should be given a ts extension on extraction:
console.log("ts");
```
The following example contains the ignore attribute and will be ignored:
```ts ignore
const value: Invalid = "ignored";
```
The following example will trigger the type-checker to fail:
```ts

View file

@ -1,7 +1,7 @@
Check [WILDCARD]/test/markdown.md$11-14.js
Check [WILDCARD]/test/markdown.md$17-20.ts
Check [WILDCARD]/test/markdown.md$23-26.ts
Check [WILDCARD]/test/markdown.md$29-32.ts
error: TS2322 [ERROR]: Type 'number' is not assignable to type 'string'.
const a: string = 42;
^
at [WILDCARD]/test/markdown.md$23-26.ts:1:7
at [WILDCARD]/test/markdown.md$29-32.ts:1:7

View file

@ -300,17 +300,21 @@ fn extract_files_from_regex_blocks(
let files = blocks_regex
.captures_iter(source)
.filter_map(|block| {
let maybe_attributes = block
let maybe_attributes: Option<Vec<_>> = block
.get(1)
.map(|attributes| attributes.as_str().split(' '));
.map(|attributes| attributes.as_str().split(' ').collect());
let file_media_type = if let Some(mut attributes) = maybe_attributes {
match attributes.next() {
Some("js") => MediaType::JavaScript,
Some("jsx") => MediaType::Jsx,
Some("ts") => MediaType::TypeScript,
Some("tsx") => MediaType::Tsx,
Some("") => *media_type,
let file_media_type = if let Some(attributes) = maybe_attributes {
if attributes.contains(&"ignore") {
return None;
}
match attributes.get(0) {
Some(&"js") => MediaType::JavaScript,
Some(&"jsx") => MediaType::Jsx,
Some(&"ts") => MediaType::TypeScript,
Some(&"tsx") => MediaType::Tsx,
Some(&"") => *media_type,
_ => MediaType::Unknown,
}
} else {