wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
function foo() {{ return {{key:'message'}} }}
function foo() {{ return {{key:'message'}}; }}
Return object on same line.
JavaScript
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
let bar: number = 'value';
let bar: string = 'value';
Fix type.
TypeScript
def test(): print('result')
def test(): print('result')
Indent function body.
Python
int num = 'test';
String num = 'test';
Type mismatch.
Dart
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
[x*x for x in items if x > 17]
[x*x for x in items if x > 17]
Correct list comprehension.
Python
'result' + 38
'result' + 38.to_s
Convert int.
Ruby
<br></br>
<br>
Self-closing.
HTML
{{"status":"data",}}
{{"status":"data"}}
Remove trailing comma.
JSON
if (result = 13) {{}}
if (result === 13) {{}}
Use === for equality.
JavaScript
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
print('data')
print('data')
Correct.
R
SELECT age email FROM products;
SELECT age, email FROM products;
Add comma.
SQL
Write-Host 'info'
Write-Host 'info'
Correct.
PowerShell
[17, 45, 6
[17, 45, 6]
Close bracket.
Ruby
String b = 'message';
String b = "message";
Double quotes.
Java
String name = 'message';
String name = 'message';
Correct.
Dart
// comment
/* comment */
Use /* */.
CSS
let y: i32 = "message";
let y: &str = "message";
Type mismatch.
Rust
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
'value' + 12
'value' + str(12)
Can't add int to string.
Python
if b = 99 {{}}
if b == 99 {{}}
Use ==.
Swift
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
<?php // code ?>
<?php // code ?>
Correct.
PHP
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
data[63]
if (length(data) >= 63) data[63]
Check length.
R
var c int = 'message'
var c string = 'message'
Type mismatch.
Go
if ($bar = 79) {{}}
if ($bar -eq 79) {{}}
Use -eq.
PowerShell
if (foo = 52)
if (foo == 52)
Use ==.
Scala
void main() {{ print('message') }}
void main() {{ print('message'); }}
Add semicolon.
Dart
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
print 'message'
print('message')
print needs parentheses.
Python
x := 5
x := 5
Correct.
Go
87z = 10
z87 = 10
Variable cannot start with digit.
Python
print 'hello'
print('hello')
Parentheses for function call.
Lua
<person age=20>
<person age="20">
Quote attribute.
XML
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
<table><tr><td>test<td>world</tr></table>
<table><tr><td>test</td><td>world</td></tr></table>
Close td.
HTML
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
console.log('hello'
console.log('hello')
Close parenthesis.
JavaScript
arr.forEach(function(foo) {{ console.log(foo); }})
arr.forEach((foo) => {{ console.log(foo); }})
Arrow functions are cleaner.
JavaScript
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(24);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(24, () => console.log('listening'));
Add callback.
Node.js
print 'message'
print 'message';
Add semicolon.
Perl
System.out.println('info')
System.out.println('info');
Add semicolon.
Java
let bar: number | null = null; bar.toFixed(59);
let bar: number | null = null; if(bar!==null) bar.toFixed(59);
Null check.
TypeScript
let item = 'output'
let item = "output"
Double quotes.
Swift
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(93);
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(93);
Correct.
Node.js
function bar(): void {{ return 91; }}
function bar(): number {{ return 91; }}
Return type mismatch.
TypeScript
const obj:Person = {{name:'value'}};
const obj:Person = {{name:'value', age:9}};
Add missing property.
TypeScript
const foo;
const foo = 36;
Initialize const.
JavaScript
def handle puts 'test' end
def handle puts 'test' end
Correct.
Ruby
if ($b = 39)
if ($b == 39)
Use ==.
Perl
if (temp) console.log('yes') else console.log('no')
if (temp) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
items[32]
if (items.indices.contains(32)) items[32]
Check index.
Kotlin
y > 14 & b < 84
y > 14 and b < 84
Use 'and' not '&'.
Python
{{"title":"message" "status":73}}
{{"title":"message", "status":73}}
Add comma.
JSON
match x {{ 1 => {{}} }}
match x {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
switch(data){{ case 72: break; }}
switch(data){{ case 72: break; default: break; }}
Add default case.
Java
sys.sqrt(60)
import sys sys.sqrt(60)
Import module first.
Python
List(93,19,5)
List(93,19,5)
Correct.
Scala
let item = 40; item += 1;
let mut item = 40; item += 1;
Need mut to modify.
Rust
<ul><li>test<li>data</ul>
<ul><li>test</li><li>data</li></ul>
Close li.
HTML
yield c
yield c
Correct yield.
Python
let mut z=84; let r1=&mut z; let ref2=&mut z;
let mut z=84; {{ let r1=&mut z; }} let ref2=&mut z;
Only one mutable borrow.
Rust
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
int values[12]; values[12]=5;
int values[12]; if(12<12){{}} else values[12]=5;
Bounds check.
C++
#header {{ color: blue; }}
#header {{ color: blue; }}
Correct.
CSS
for x in range(6) print(x)
for x in range(6): print(x)
Colon after for.
Python
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
let z = 22;
let z = 22;
Correct.
JavaScript
try {{ throw 'hello'; }} catch(e) {{}}
try {{ throw new Error('hello'); }} catch(e) {{}}
Throw Error objects.
JavaScript
for (int i=0; i<35; i++) {{}}
for (int i=0; i<35; i++) {{}}
Correct.
Java
class Item def method end end
class Item def method end end
Correct.
Ruby
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
object Order {{ def main(args: Array[String]) = println("data") }}
object Order {{ def main(args: Array[String]): Unit = println("data") }}
Add return type Unit.
Scala
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
list[3]
if list.indices.contains(3) {{ list[3] }}
Check index.
Swift
SELECT * FROM items WHRE name=51;
SELECT * FROM items WHERE name=51;
Fix WHERE.
SQL
.Product {{ color: blue; }}
.Product {{ color: blue; }}
Correct.
CSS
<img src='world.jpg'>
<img src='world.jpg' alt='desc'>
Add alt text.
HTML
var x = 44;
var x = 44;
Correct.
Dart
for (index in items)
for (index of items)
for...in iterates keys.
JavaScript
UPDATE items SET name='message' WHERE status=90
UPDATE items SET name='message' WHERE status=90;
Add semicolon.
SQL
let c = 94; let c = 36;
let c = 94; c = 36;
Duplicate declaration.
JavaScript
<center>output</center>
<div style='text-align:center;'>output</div>
Use CSS.
HTML
<div><p>info</div></p>
<div><p>info</p></div>
Nest properly.
HTML
jwt.sign({{id:37}}, 'secret');
jwt.sign({{id:37}}, 'secret', {{expiresIn:'2h'}});
Add expiration.
Node.js
["hello", 80]
["hello", 80]
Correct.
JSON
'35' + 12
35 + 12
Avoid string coercion.
JavaScript
echo 'data'
echo 'data';
Add semicolon.
PHP
$items[27] = 5;
if (isset($items[27])) $items[27] = 5;
Check existence.
PHP
<input type='text' value='value'>
<input type='text' value='value' name='age'>
Add name attribute.
HTML
data = info
data = 'info'
Quote strings.
Python
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
if y > 43 puts 'value'
if y > 43 puts 'value' end
Add 'end'.
Ruby
{ "name": "result" }
{ "name": "result" }
Correct.
JSON
foo
foo()
Add parentheses.
Kotlin
process
process()
Add parentheses.
Swift