Skip to content

Commit 913f59f

Browse files
Modify JavaScript to add trailing commas
Signed-off-by: David A. Wheeler <[email protected]>
1 parent 4fbf010 commit 913f59f

20 files changed

+161
-161
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/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/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+
};

docs/labs/handling-errors.js

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ info =
1717
[ " throw NEW Error(\"Division by zero is forbidden\");" ],
1818
[ " throw new error(\"Division by zero is forbidden\");" ],
1919
[ " throw new ERROR(\"Division by zero is forbidden\");" ]
20-
]
20+
],
2121
},
2222
{
2323
index: 0,
@@ -26,15 +26,15 @@ info =
2626
examples: [
2727
[ " return { success: false, message: \"Division by zero is forbidden\" };" ],
2828
[ " return \"Division by zero is forbidden\" ;" ]
29-
]
29+
],
3030
},
3131
{
3232
index: 1,
3333
absent: "return",
3434
text: "Use the return keyword to return the result of the division.",
3535
examples: [
3636
[ " a / b ;" ]
37-
]
37+
],
3838
},
3939
{
4040
index: 1,
@@ -48,8 +48,8 @@ info =
4848
[
4949
"throw new Error(\"Division by zero is forbidden\");",
5050
" return { result: a / b };"
51-
]
52-
]
51+
],
52+
],
5353
},
5454
{
5555
index: 2,
@@ -60,8 +60,8 @@ info =
6060
"throw new Error(\"Division by zero is forbidden\");",
6161
"return a / b;",
6262
" const result = divide(10, 2);"
63-
]
64-
]
63+
],
64+
],
6565
},
6666
{
6767
index: 2,
@@ -72,8 +72,8 @@ info =
7272
"throw new Error(\"Division by zero is forbidden\");",
7373
"return a / b;",
7474
" try { const result = divide(10 ,2); if( result.success) { console.log ( \"Result:\", result ); "
75-
]
76-
]
75+
],
76+
],
7777
},
7878
{
7979
index: 2,
@@ -84,8 +84,8 @@ info =
8484
"throw new Error(\"Division by zero is forbidden\");",
8585
"return a / b;",
8686
" try { const result = divide(10 ,2); console.log ( \"Result:\", result.result ); "
87-
]
88-
]
87+
],
88+
],
8989
},
9090
{
9191
index: 2,
@@ -96,8 +96,8 @@ info =
9696
"throw new Error(\"Division by zero is forbidden\");",
9797
"return a / b;",
9898
" try { const result = divide(10 ,2); console.log ( \"Result:\", result ); }"
99-
]
100-
]
99+
],
100+
],
101101
},
102102
{
103103
index: 2,
@@ -108,8 +108,8 @@ info =
108108
"throw new Error(\"Division by zero is forbidden\");",
109109
"return a / b;",
110110
" try { const result = divide(10 ,2); console.log ( \"Result:\", result ); } catch {}"
111-
]
112-
]
111+
],
112+
],
113113
},
114114
{
115115
index: 2,
@@ -120,8 +120,8 @@ info =
120120
"throw new Error(\"Division by zero is forbidden\");",
121121
"return a / b;",
122122
" try { const result = divide(10 ,2); console.log ( \"Result:\", result ); } catch (foo) {"
123-
]
124-
]
123+
],
124+
],
125125
},
126126
{
127127
index: 2,
@@ -137,9 +137,9 @@ info =
137137
"throw new Error(\"Division by zero is forbidden\");",
138138
"return a / b;",
139139
" try { const result = divide(10 ,2); console.log ( \"Result:\", result ); } catch (err) { console.error('Error', result );"
140-
]
141-
]
142-
}
140+
],
141+
],
142+
},
143143
],
144144
expected: [
145145
'throw new Error("Division by zero is forbidden");',
@@ -164,4 +164,4 @@ info =
164164
err \. message \) ;
165165
\} \s*`
166166
],
167-
}
167+
};

docs/labs/hardcoded.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ info =
4646
System \. getenv \( "PASSWORD" \) \,
4747
System \. getenv \( "USERNAME" \) \) \; \s* $`,
4848
text: "The order of parameters is wrong. Provide the url, then the username, then the password. You're providing the url, then the password, then the username, which swaps the second and third parameters."
49-
}
49+
},
5050
],
5151
expected: [
5252
`conn = DriverManager.getConnection(url,
@@ -57,4 +57,4 @@ info =
5757
\s* System \. getenv \( "USERNAME" \) \,
5858
\s* System \. getenv \( "PASSWORD" \) \) \; \s*`
5959
],
60-
}
60+
};

0 commit comments

Comments
 (0)