Skip to content

Commit 970d331

Browse files
Merge pull request #778 from ossf/fix_preprocessor_doc
Fix preprocessor documentation
2 parents 50b2c46 + 6df883b commit 970d331

File tree

1 file changed

+30
-27
lines changed

1 file changed

+30
-27
lines changed

docs/labs/create_checker.md

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -619,33 +619,36 @@ requested, and the second is post-processed pattern that should result.
619619
There's no need for a "failure" test suite here, because we
620620
demand exact results for every test case.
621621

622-
Here is an example (expressed in YAML format):
623-
624-
~~~~yaml
625-
preprocessing:
626-
-
627-
- |-
628-
[\n\r]+
629-
- ""
630-
-
631-
- |-
632-
[ \t]+\\s\+[ \t]+
633-
- "\\s+"
634-
-
635-
- |-
636-
(\\s\*)?[ \t]+(\\s\*)?
637-
- "\\s*"
638-
preprocessingTests:
639-
-
640-
- |-
641-
\s* console \. log \( (["'`])Hello,\x20world!\1 \) ; \s*
642-
- |-
643-
\s*console\s*\.\s*log\s*\(\s*(["'`])Hello,\x20world!\1\s*\)\s*;\s*
644-
-
645-
- |-
646-
\s* foo \s+ bar \\string\\ \s*
647-
- |-
648-
\s*foo\s+bar\s*\\string\\\s*
622+
Here is an example:
623+
624+
~~~~javascript
625+
preprocessing: [
626+
[
627+
// Ignore newlines
628+
String.raw`[\n\r]+`,
629+
""
630+
],
631+
[
632+
// Convert \s+ surrounded by tabs/spaces as \s+ (optimization)
633+
String.raw`[ \t]+\\s\+[ \t]+`,
634+
String.raw`\s+`
635+
],
636+
[
637+
// Convert 1+ spaces/tabs, optionally surrounded by \s*, as \s*
638+
String.raw`(\\s\*)?[ \t]+(\\s\*)?`,
639+
String.raw`\s*`
640+
]
641+
],
642+
preprocessingTests: [
643+
[
644+
String.raw`\s* console \. log \( (["'${BACKQUOTE}])Hello,\x20world!\1 \) ; \s*`,
645+
String.raw`\s*console\s*\.\s*log\s*\(\s*(["'${BACKQUOTE}])Hello,\x20world!\1\s*\)\s*;\s*`
646+
],
647+
[
648+
String.raw`\s* foo \s+ bar \\string\\ \s*`,
649+
String.raw`\s*foo\s+bar\s*\\string\\\s*`
650+
]
651+
]
649652
~~~~
650653

651654
Here is an explanation of each of these preprocessing elements

0 commit comments

Comments
 (0)