mirror of
https://github.com/denoland/deno.git
synced 2024-12-22 23:34:47 -05:00
fix(test): skip typechecking for blocks inside HTML comments (#13889)
This commit is contained in:
parent
38e88e32b7
commit
8db3a9546b
4 changed files with 57 additions and 1 deletions
|
@ -103,6 +103,12 @@ itest!(markdown_full_block_names {
|
||||||
output: "test/markdown_full_block_names.out",
|
output: "test/markdown_full_block_names.out",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
itest!(markdown_ignore_html_comment {
|
||||||
|
args: "test --doc --allow-all test/markdown_with_comment.md",
|
||||||
|
exit_code: 1,
|
||||||
|
output: "test/markdown_with_comment.out",
|
||||||
|
});
|
||||||
|
|
||||||
itest!(text {
|
itest!(text {
|
||||||
args: "test --doc --allow-all test/text.md",
|
args: "test --doc --allow-all test/text.md",
|
||||||
exit_code: 0,
|
exit_code: 0,
|
||||||
|
|
36
cli/tests/testdata/test/markdown_with_comment.md
vendored
Normal file
36
cli/tests/testdata/test/markdown_with_comment.md
vendored
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
# Documentation
|
||||||
|
|
||||||
|
The following examples are inside HTML comments and will not trigger the
|
||||||
|
type-checker:
|
||||||
|
|
||||||
|
<!-- ```ts ignore
|
||||||
|
const value: Invalid = "ignored";
|
||||||
|
``` -->
|
||||||
|
|
||||||
|
<!--
|
||||||
|
```ts
|
||||||
|
const a: string = 42;
|
||||||
|
```
|
||||||
|
-->
|
||||||
|
|
||||||
|
<!--
|
||||||
|
|
||||||
|
This is a comment.
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const a: string = 42;
|
||||||
|
```
|
||||||
|
|
||||||
|
Something something more comments.
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
const a: boolean = "true";
|
||||||
|
```
|
||||||
|
|
||||||
|
-->
|
||||||
|
|
||||||
|
The following example will trigger the type-checker to fail:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const a: string = 42;
|
||||||
|
```
|
5
cli/tests/testdata/test/markdown_with_comment.out
vendored
Normal file
5
cli/tests/testdata/test/markdown_with_comment.out
vendored
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
Check [WILDCARD]/test/markdown_with_comment.md$34-37.ts
|
||||||
|
error: TS2322 [ERROR]: Type 'number' is not assignable to type 'string'.
|
||||||
|
const a: string = 42;
|
||||||
|
^
|
||||||
|
at [WILDCARD]/test/markdown_with_comment.md$34-37.ts:1:7
|
|
@ -543,6 +543,10 @@ 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| {
|
||||||
|
if block.get(1) == None {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
let maybe_attributes: Option<Vec<_>> = block
|
let maybe_attributes: Option<Vec<_>> = block
|
||||||
.get(1)
|
.get(1)
|
||||||
.map(|attributes| attributes.as_str().split(' ').collect());
|
.map(|attributes| attributes.as_str().split(' ').collect());
|
||||||
|
@ -663,7 +667,12 @@ fn extract_files_from_fenced_blocks(
|
||||||
source: &str,
|
source: &str,
|
||||||
media_type: MediaType,
|
media_type: MediaType,
|
||||||
) -> Result<Vec<File>, AnyError> {
|
) -> Result<Vec<File>, AnyError> {
|
||||||
let blocks_regex = Regex::new(r"```([^\r\n]*)\r?\n([\S\s]*?)```")?;
|
// The pattern matches code blocks as well as anything in HTML comment syntax,
|
||||||
|
// but it stores the latter without any capturing groups. This way, a simple
|
||||||
|
// check can be done to see if a block is inside a comment (and skip typechecking)
|
||||||
|
// or not by checking for the presence of capturing groups in the matches.
|
||||||
|
let blocks_regex =
|
||||||
|
Regex::new(r"(?s)<!--.*?-->|```([^\r\n]*)\r?\n([\S\s]*?)```")?;
|
||||||
let lines_regex = Regex::new(r"(?:\# ?)?(.*)")?;
|
let lines_regex = Regex::new(r"(?:\# ?)?(.*)")?;
|
||||||
|
|
||||||
extract_files_from_regex_blocks(
|
extract_files_from_regex_blocks(
|
||||||
|
|
Loading…
Reference in a new issue