@@ -13,9 +13,39 @@ let badExit = false;
13
13
// error reports an error to the console and sets badExit to true
14
14
// so that the process will exit with a non-zero exit code.
15
15
const error = ( ...data : any [ ] ) => {
16
- console . error ( ...data ) ;
17
- badExit = true ;
18
- }
16
+ console . error ( ...data ) ;
17
+ badExit = true ;
18
+ } ;
19
+
20
+ const verifyCodeBlocks = (
21
+ tokens : marked . Token [ ] ,
22
+ res = {
23
+ codeIsTF : false ,
24
+ codeIsHCL : false ,
25
+ }
26
+ ) => {
27
+ for ( const token of tokens ) {
28
+ // Check in-depth.
29
+ if ( token . type === "list" ) {
30
+ verifyCodeBlocks ( token . items , res ) ;
31
+ continue ;
32
+ }
33
+ if ( token . type === "list_item" ) {
34
+ verifyCodeBlocks ( token . tokens , res ) ;
35
+ continue ;
36
+ }
37
+
38
+ if ( token . type === "code" ) {
39
+ if ( token . lang === "tf" ) {
40
+ res . codeIsTF = true ;
41
+ }
42
+ if ( token . lang === "hcl" ) {
43
+ res . codeIsHCL = true ;
44
+ }
45
+ }
46
+ }
47
+ return res ;
48
+ } ;
19
49
20
50
// Ensures that each README has the proper format.
21
51
// Exits with 0 if all is good!
@@ -89,6 +119,14 @@ for (const dir of dirs) {
89
119
if ( ! code ) {
90
120
error ( dir . name , "missing example code block after paragraph" ) ;
91
121
}
122
+
123
+ const { codeIsTF, codeIsHCL } = verifyCodeBlocks ( tokens ) ;
124
+ if ( ! codeIsTF ) {
125
+ error ( dir . name , "missing example tf code block" ) ;
126
+ }
127
+ if ( codeIsHCL ) {
128
+ error ( dir . name , "hcl code block should be tf" ) ;
129
+ }
92
130
}
93
131
94
132
if ( badExit ) {
0 commit comments