mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 17:34:47 -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:
parent
1d1507384b
commit
f90231924d
3 changed files with 21 additions and 11 deletions
6
cli/tests/testdata/test/markdown.md
vendored
6
cli/tests/testdata/test/markdown.md
vendored
|
@ -18,6 +18,12 @@ The following block should be given a ts extension on extraction:
|
||||||
console.log("ts");
|
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:
|
The following example will trigger the type-checker to fail:
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
|
|
4
cli/tests/testdata/test/markdown.out
vendored
4
cli/tests/testdata/test/markdown.out
vendored
|
@ -1,7 +1,7 @@
|
||||||
Check [WILDCARD]/test/markdown.md$11-14.js
|
Check [WILDCARD]/test/markdown.md$11-14.js
|
||||||
Check [WILDCARD]/test/markdown.md$17-20.ts
|
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'.
|
error: TS2322 [ERROR]: Type 'number' is not assignable to type 'string'.
|
||||||
const a: string = 42;
|
const a: string = 42;
|
||||||
^
|
^
|
||||||
at [WILDCARD]/test/markdown.md$23-26.ts:1:7
|
at [WILDCARD]/test/markdown.md$29-32.ts:1:7
|
||||||
|
|
|
@ -300,17 +300,21 @@ fn extract_files_from_regex_blocks(
|
||||||
let files = blocks_regex
|
let files = blocks_regex
|
||||||
.captures_iter(source)
|
.captures_iter(source)
|
||||||
.filter_map(|block| {
|
.filter_map(|block| {
|
||||||
let maybe_attributes = block
|
let maybe_attributes: Option<Vec<_>> = block
|
||||||
.get(1)
|
.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 {
|
let file_media_type = if let Some(attributes) = maybe_attributes {
|
||||||
match attributes.next() {
|
if attributes.contains(&"ignore") {
|
||||||
Some("js") => MediaType::JavaScript,
|
return None;
|
||||||
Some("jsx") => MediaType::Jsx,
|
}
|
||||||
Some("ts") => MediaType::TypeScript,
|
|
||||||
Some("tsx") => MediaType::Tsx,
|
match attributes.get(0) {
|
||||||
Some("") => *media_type,
|
Some(&"js") => MediaType::JavaScript,
|
||||||
|
Some(&"jsx") => MediaType::Jsx,
|
||||||
|
Some(&"ts") => MediaType::TypeScript,
|
||||||
|
Some(&"tsx") => MediaType::Tsx,
|
||||||
|
Some(&"") => *media_type,
|
||||||
_ => MediaType::Unknown,
|
_ => MediaType::Unknown,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Reference in a new issue