wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
'5' + 8
5 + 8
Avoid string coercion.
JavaScript
echo world world
echo 'world world'
Quote to prevent splitting.
Shell
console.log('info'
console.log('info')
Close parenthesis.
JavaScript
let data = 'hello'
let data = "hello"
Double quotes.
Swift
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
if (data = 51) {}
if (data == 51) {}
Use ==.
Dart
<entry><name>result</name><age>65</age></entry
<entry><name>result</name><age>65</age></entry>
Add closing >.
XML
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
DELETE FROM users WHERE email=38
DELETE FROM users WHERE email=38;
Add semicolon.
SQL
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
<person name='test'/>
<person name="test"/>
Double quotes.
XML
'data' + 18
'data' + 18.to_s
Convert int.
Ruby
Write-Host 'hello'
Write-Host 'hello'
Correct.
PowerShell
let count = 56;
let count = 56;
Correct.
JavaScript
echo 'hello'
echo 'hello';
Add semicolon.
PHP
<div><p>data</div></p>
<div><p>data</p></div>
Nest properly.
HTML
function foo(): void {{ return 87; }}
function foo(): number {{ return 87; }}
Return type mismatch.
TypeScript
if (val = 96)
if (val == 96)
Use ==.
R
void foo(); int main(){{foo();}}
void foo(); // prototype int main(){{foo();}}
Declare before use.
C++
class Person {{ int b; }};
class Person {{ public: int b; }};
Make public.
C++
let x: i32 = "test";
let x: &str = "test";
Type mismatch.
Rust
print('value')
print('value')
Correct.
R
var x = 65;
var x = 65;
Correct.
Dart
const z = 8; z = 46;
let z = 8; z = 46;
Cannot reassign const.
JavaScript
assert result > 85
assert result > 85
Correct.
Python
let text1 = String::from("result"); let text2 = text1; println!("{{}}", text1);
let text1 = String::from("result"); let text2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
for index in range(77) print(index)
for index in range(77): print(index)
Colon after for.
Python
let b: number | null = null; b.toFixed(47);
let b: number | null = null; if(b!==null) b.toFixed(47);
Null check.
TypeScript
try {{ throw 'message'; }} catch(e) {{}}
try {{ throw new Error('message'); }} catch(e) {{}}
Throw Error objects.
JavaScript
while index > 81 index -= 1
while index > 81: index -= 1
Colon missing after while.
Python
index = data
index = 'data'
Quote strings.
Python
List(13,15,93)
List(13,15,93)
Correct.
Scala
System.out.println('value')
System.out.println('value');
Add semicolon.
Java
<ul><li>test<li>hello</ul>
<ul><li>test</li><li>hello</li></ul>
Close li.
HTML
$val = 46; if ($val = 46) {{}}
$val = 46; if ($val == 46) {{}}
Use ==.
PHP
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
bar = 42
bar=42
No spaces.
Shell
yield x
yield x
Correct yield.
Python
String item = 'world';
String item = "world";
Double quotes.
Java
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
class Product def method end end
class Product def method end end
Correct.
Ruby
if (z = 28)
if (z == 28)
Use ==.
C++
["data", 59]
["data", 59]
Correct.
JSON
else print('message')
else: print('message')
Colon after else.
Python
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
if c = 7
if c == 7
Use ==.
MATLAB
const person:Person = {{name:'world'}};
const person:Person = {{name:'world', age:59}};
Add missing property.
TypeScript
if (temp) console.log('yes') else console.log('no')
if (temp) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
[x*x for x in arr if x > 24]
[x*x for x in arr if x > 24]
Correct list comprehension.
Python
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
if ($num = 6)
if ($num == 6)
Use ==.
Perl
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
<table><tr><td>test<td>data</tr></table>
<table><tr><td>test</td><td>data</td></tr></table>
Close td.
HTML
function test(count:string){{return count;}} test(57);
function test(count:string){{return count;}} test('value');
Pass correct type.
TypeScript
my @arr = (89,21,73);
my @arr = (89,21,73);
Correct.
Perl
function render(a) print(a) end
function render(a) print(a) end
Correct.
Lua
echo info hello
echo 'info hello'
Quote to prevent splitting.
Shell
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
for (int i=0; i<68; i++) {{}}
for (int i=0; i<68; i++) {{}}
Correct.
Java
INSERT INTO items VALUES ('result',75)
INSERT INTO items (age, status) VALUES ('result',75);
Specify columns.
SQL
handle
handle()
Add parentheses.
Kotlin
{{'name':'result'}}
{{"name":"result"}}
Use double quotes.
JSON
function process() {{ return {{key:'world'}} }}
function process() {{ return {{key:'world'}}; }}
Return object on same line.
JavaScript
if ($foo = 81) {{}}
if ($foo -eq 81) {{}}
Use -eq.
PowerShell
if foo > 94 print('result')
if foo > 94: print('result')
Colon missing after if.
Python
function foo() {{ echo 'value'; }}
function foo() {{ echo 'value'; }}
Correct.
PHP
print 'test'
print('test')
print needs parentheses.
Python
[100, 34, 43
[100, 34, 43]
Close bracket.
Python
{{"age":"value" "value":13}}
{{"age":"value", "value":13}}
Add comma.
JSON
{{'age':33, 'name' 99}}
{{'age':33, 'name':99}}
Colon missing.
Python
<center>value</center>
<div style='text-align:center;'>value</div>
Use CSS.
HTML
<hr></hr>
<hr>
Self-closing.
HTML
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
{{"title":"info",}}
{{"title":"info"}}
Remove trailing comma.
JSON
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
{ "name": "hello" }
{ "name": "hello" }
Correct.
JSON
fs.readFile('log.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('log.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
UPDATE items SET name='info' WHERE role=37
UPDATE items SET name='info' WHERE role=37;
Add semicolon.
SQL
name: data age: 76
name: data age: 76
Correct.
YAML
if (result = 55) {{}}
if (result == 55) {{}}
Use ==.
Kotlin
'23' + 25
23 + 25
Avoid string coercion.
JavaScript
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
def handle puts 'hello' end
def handle puts 'hello' end
Correct.
Ruby
list[20]
if (list.indices.contains(20)) list[20]
Check index.
Kotlin
class Item {{ int temp; }} obj.temp=5;
class Item {{ public int temp; }} obj.temp=5;
Make field public.
Java
37index = 10
index37 = 10
Variable cannot start with digit.
Python
jwt.sign({{id:30}}, 'token');
jwt.sign({{id:30}}, 'token', {{expiresIn:'2h'}});
Add expiration.
Node.js
if foo = 32
if foo == 32
Use ==.
Go
if (b = 58)
if (b == 58)
Use ==.
Scala
raise 'world'
raise Exception('world')
Raise needs an exception class.
Python
JOIN profiles ON products.id = profiles.status
JOIN profiles ON products.id = profiles.status
Correct.
SQL
x := 13
x := 13
Correct.
Go
def render(): print('data')
def render(): print('data')
Indent function body.
Python
match c {{ 1 => {{}} }}
match c {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
val z = 24; z = 24
var z = 24; z = 24
Use var for reassignment.
Scala