Skip to content

Commit 5af313d

Browse files
Merge pull request #764 from ossf/trailing_comma
Trailing comma
2 parents 6e49d68 + b4777d0 commit 5af313d

22 files changed

+200
-168
lines changed

docs/labs/argument-injection.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ info =
7070
{
7171
present: String.raw`\) \) =>`,
7272
text: "The `exec` function should be closed in later lines, not here."
73-
}
73+
},
7474
],
7575
expected: [
7676
`execFile('git', ['blame', '--', filePath], { shell: false }, (error, stdout, stderr) => {`
@@ -89,7 +89,7 @@ info =
8989
" execFile('git', ['blame', '--', filePath], { shell: false }, (error, stdout, stderr) => {",
9090
" execFile('git', ['blame', '--', filePath], (error, stdout, stderr) => {",
9191
" execFile('git', ['blame', '--', filePath], {}, (error, stdout, stderr) => {"
92-
]
92+
],
9393
],
9494
failures: [
9595
[
@@ -100,6 +100,6 @@ info =
100100
],
101101
[
102102
" execFile('git blame', [filePath], { shell: false }, (error, stdout, stderr) => {"
103-
]
104-
]
105-
}
103+
],
104+
],
105+
};

docs/labs/assert.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ info =
66
text: "The whole point of this exercise is to NOT use `assert` as a way to validate input from untrusted users.",
77
examples: [
88
[ "assert !bindingResult.hasErrors();\n" ]
9-
]
9+
],
1010
},
1111
{
1212
absent: String.raw`^\s* if `,
1313
text: "Begin with `if` so you can return a result if there are errors.",
1414
examples: [
1515
[ "return \"form\";" ]
16-
]
16+
],
1717
},
1818
{
1919
present: "(bindingresult|BindingResult)",
@@ -28,14 +28,14 @@ info =
2828
text: "In Java, after the keyword `if` you must have an open left parenthesis. Conventionally there is one space between the `if` keyword and the open left parenthesis.",
2929
examples: [
3030
[ "if bindingResult.hasErrors" ]
31-
]
31+
],
3232
},
3333
{
3434
present: String.raw`^\s*if\s*\(\s*\!binding`,
3535
text: "You have an extraneous `!` (not operator). Use the expression if (bindingResult.hasErrors()) ...",
3636
examples: [
3737
[ "if (!bindingResult.hasErrors())" ]
38-
]
38+
],
3939
},
4040
{
4141
absent: String.raw`^ if \( bindingResult \. hasErrors \( \) \) `,
@@ -79,5 +79,5 @@ info =
7979
[ "if ( ! bindingResult . hasErrors ( ) ) { return \"form\" ; }\n" ],
8080
[ "if bindingResult . hasErrors ( ) { return \"form\" ; }\n" ],
8181
[ "if ( bindingResult . hasErrors ) { return \"form\" ; }\n" ],
82-
]
83-
}
82+
],
83+
};

docs/labs/commaize

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/sh
2+
# Add trailing commas and terminating semicolon to lab data files
3+
4+
for file in [a-z]*.js
5+
do
6+
# Skip checker, that has more than data in it.
7+
if [ "$file" == 'checker.js' ]; then
8+
continue
9+
fi
10+
11+
# Skip anything that isn't a lab data file.
12+
if ! grep -q 'info =' "$file"; then
13+
continue
14+
fi
15+
16+
htmlfile="${file%.js}.html"
17+
echo "Modifying $file for $htmlfile"
18+
19+
sed -E -e 's/^( +(\]|\}))$/\1,/' -e '$s/^\}$/};/' "$file" > ,1
20+
mv ,1 "$file"
21+
done

docs/labs/conversion.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ info =
88
{
99
present: String.raw`unsigned\s+queue_count`,
1010
text: "The declared return type of get_queue is `unsigned int`; you should match it exactly instead of using a synonym like `unsigned`."
11-
}
11+
},
1212
],
1313
expected: [
1414
'unsigned int queue_count = 0;'
1515
],
1616
correct: [
1717
String.raw`^ unsigned\s+int\s+queue_count = 0 ; $`
1818
],
19-
}
19+
};

docs/labs/create_checker.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,11 @@ The basic inputs are:
128128
The number of attempt fields (in the HTML), the number of `expected` values,
129129
and the number of `correct` values much match.
130130

131-
### JavaScript strings
131+
### JavaScript notation
132132

133-
The lab data is expressed using JavaScript strings.
134-
There's more than one way to express a string in JavaScript, each
133+
The lab data is expressed using JavaScript, primarily as
134+
JavaScript strings.
135+
There's more than one way to express a string in JavaScript, and each
135136
has its advantages:
136137

137138
* "..." - double-quoted string. You don't need to do anything special to
@@ -148,6 +149,15 @@ has its advantages:
148149
These are often useful for patterns.
149150
Use ${BACKQUOTE} for ` and ${DOLLAR} for $.
150151

152+
JavaScript allows trailing commas, and we encourage using them.
153+
In other words,
154+
a list in JavaScript can have the form `[ 'a', 'b', 'c', ]`
155+
(note the trailing comma after `'c'`).
156+
Using trailing commas reduces the likelihood of
157+
a common error: forgetting to add a comma when you add an item to a list.
158+
Using trailing commas means that when you add a new item (`'d'`) at the end,
159+
you *already* have the comma ready for use.
160+
151161
### Expressing correct answer patterns
152162

153163
The patterns used for `correct` and `hints`
@@ -299,6 +309,8 @@ Here's an explanation of this pattern:
299309
This that one of the following patterns is allowed:
300310
`'id'` or `"id"` or <tt>&#96;id&#96</tt> (and nothing else).
301311
Again, the space after it means 0+ spaces are allowed.
312+
WARNING: If you use JavaScript raw strings or templates, you
313+
need to escape the backquote (&#96;) character.
302314

303315
5. The `\)` matches a literal close parenthesis,
304316
while `\.` matches a literal period.

docs/labs/csp1.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ info =
77
examples: [
88
[
99
"import express from \"express\";"
10-
]
11-
]
10+
],
11+
],
1212
},
1313
{
1414
absent: "const",
@@ -20,21 +20,21 @@ info =
2020
examples: [
2121
[ "const" ],
2222
[ "consthelmet = " ]
23-
]
23+
],
2424
},
2525
{
2626
present: String.raw`require \( helmet \)`,
2727
text: "The parameter of a requirement statement must be string. Surround the term helment with double-quotes.",
2828
examples: [
2929
[ " const helmet = require(helmet);" ]
30-
]
30+
],
3131
},
3232
{
3333
absent: "; $",
3434
text: "JavaScript doesn''t require semicolon terminators, but the rest of the code uses them. You should try to match a coding style when modifying existing code unless there''s an important reason not to. Please update the first statment.",
3535
examples: [
3636
[ " const helmet = require(\"helmet\")" ]
37-
]
37+
],
3838
},
3939
{
4040
absent: String.raw`\s* app \. use \( helmet \( \{`,
@@ -83,7 +83,7 @@ info =
8383
},
8484
{
8585
text: "I do not have more specific hints to provide. Please ensure that the parentheses, braces, and brackets pair correctly, as that is often the problem."
86-
}
86+
},
8787
],
8888
expected: [
8989
'const helmet = require("helmet");',
@@ -93,7 +93,7 @@ info =
9393
"script-src": ["'self'", "https://example.com"],
9494
"style-src": ["'self'"]
9595
},
96-
}
96+
},
9797
}));`
9898
],
9999
correct: [
@@ -107,4 +107,4 @@ info =
107107
\} ,?
108108
\} \) \) ; \s*`
109109
],
110-
}
110+
};

docs/labs/deserialization.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ info =
2828
{
2929
term: "CONDALL",
3030
value: "(COND0 && (COND1 && COND2|COND2 && COND1))"
31-
}
31+
},
3232
],
3333
hints: [
3434
{
@@ -61,8 +61,8 @@ info =
6161
[
6262
"const data = JSON.parse(base64Decoded);",
6363
"if data.username {\n"
64-
]
65-
]
64+
],
65+
],
6666
},
6767
{
6868
absent: String.raw`data \. username
@@ -100,9 +100,9 @@ info =
100100
[
101101
"const data = JSON.parse(base64Decoded);",
102102
"if (typeof data.username == 'string' && data.username.length < 20 && data.username) {"
103-
]
104-
]
105-
}
103+
],
104+
],
105+
},
106106
],
107107
expected: [
108108
' const data = JSON.parse(base64Decoded);',
@@ -128,12 +128,12 @@ info =
128128
[
129129
"const data = JSON.parse(base64Decoded);",
130130
"if (data.username && typeof data.username == 'string' && (data.username.length < 20)) {"
131-
]
131+
],
132132
],
133133
failures: [
134134
[
135135
"const data = JSON.parse(base64Decoded);",
136136
"if (data.username && (typeof data.username == 'string')) && (data.username.length < 20)) {"
137-
]
138-
]
139-
}
137+
],
138+
],
139+
};

docs/labs/format-strings.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ info =
2222
absent: String.raw`\'\{event.level\},\{event.message\}\'
2323
`,
2424
text: "The constant text `'{event.level},{event.message}'` should be present."
25-
}
25+
},
2626
],
2727
expected: [
2828
String.raw`def format_event(new_event):
@@ -31,4 +31,4 @@ info =
3131
correct: [
3232
String.raw`(\r?\n)*def\x20+format_event\x20*\( new_event \)\x20*:(\r?\n)\x20+return\x20+'{event\.level},{event\.message}'\x20*\.\x20*format\x20*\( event = new_event \) \s*`
3333
],
34-
}
34+
};

docs/labs/free.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ info =
77
examples: [
88
[
99
"free(s);\nasprintf(&result, \"pre_%s_post\", s);"
10-
]
11-
]
10+
],
11+
],
1212
},
1313
{
1414
present: String.raw`\s* asprintf \(`,
@@ -17,8 +17,8 @@ info =
1717
examples: [
1818
[
1919
"asprintf(&result, \"\"pre_%s_post\"\", s);"
20-
]
21-
]
20+
],
21+
],
2222
},
2323
{
2424
absent: "return",
@@ -30,18 +30,18 @@ info =
3030
examples: [
3131
[
3232
"asprintf(&result, \"pre_%s_post\", s);\nfree(s);\nreturn result"
33-
]
34-
]
33+
],
34+
],
3535
},
3636
{
3737
present: String.raw`\s* return result ; free \s*`,
3838
text: "Do not do anything after the return, it will not execute.",
3939
examples: [
4040
[
4141
"asprintf(&result, \"pre_%s_post\", s);\nreturn result;\nfree(s);"
42-
]
43-
]
44-
}
42+
],
43+
],
44+
},
4545
],
4646
expected: [
4747
` asprintf(&result, "pre_%s_post", s);
@@ -54,4 +54,4 @@ info =
5454
free \( s \) ;
5555
return result ; \s*`
5656
],
57-
}
57+
};

0 commit comments

Comments
 (0)