diff options
author | Geert-Jan Zwiers <34610306+GJZwiers@users.noreply.github.com> | 2022-03-11 02:14:32 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-11 02:14:32 +0100 |
commit | 8db3a9546b59fdd5e7203f2e63a828e3c5108e7e (patch) | |
tree | 2b3e91d39f7891c69c16d7b62ea6c6f9969a3fb2 /cli/tools/test.rs | |
parent | 38e88e32b79cf9605b57751802aef1ebff924d98 (diff) |
fix(test): skip typechecking for blocks inside HTML comments (#13889)
Diffstat (limited to 'cli/tools/test.rs')
-rw-r--r-- | cli/tools/test.rs | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/cli/tools/test.rs b/cli/tools/test.rs index 74646986d..61a37c7ff 100644 --- a/cli/tools/test.rs +++ b/cli/tools/test.rs @@ -543,6 +543,10 @@ fn extract_files_from_regex_blocks( let files = blocks_regex .captures_iter(source) .filter_map(|block| { + if block.get(1) == None { + return None; + } + let maybe_attributes: Option<Vec<_>> = block .get(1) .map(|attributes| attributes.as_str().split(' ').collect()); @@ -663,7 +667,12 @@ fn extract_files_from_fenced_blocks( source: &str, media_type: MediaType, ) -> 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"(?:\# ?)?(.*)")?; extract_files_from_regex_blocks( |