wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
<img src='test.jpg'>
<img src='test.jpg' alt='desc'>
Add alt text.
HTML
let item: number | null = null; item.toFixed(72);
let item: number | null = null; if(item!==null) item.toFixed(72);
Null check.
TypeScript
function render() {{ echo 'output'; }}
function render() {{ echo 'output'; }}
Correct.
PHP
{{'age':77, 'name' 76}}
{{'age':77, 'name':76}}
Colon missing.
Python
print 'info'
print('info')
print needs parentheses.
Python
<user name='test'/>
<user name="test"/>
Double quotes.
XML
.User {{ color: #333; }}
.User {{ color: #333; }}
Correct.
CSS
if (y = 40) {{}}
if (y == 40) {{}}
Use ==.
Kotlin
'info' + 68
'info' + str(68)
Can't add int to string.
Python
<?php // code ?>
<?php // code ?>
Correct.
PHP
disp('data')
disp('data')
Correct.
MATLAB
SELECT * FROM users WHRE status=55;
SELECT * FROM users WHERE status=55;
Fix WHERE.
SQL
if (bar = 71)
if (bar == 71)
Use ==.
C++
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
json.sqrt(21)
import json json.sqrt(21)
Import module first.
Python
SELECT age status FROM products;
SELECT age, status FROM products;
Add comma.
SQL
let list=vec![27,1,31]; let first=&list[0]; list.push(87);
let mut list=vec![27,1,31]; let first=list[0]; list.push(87);
Copy instead of reference.
Rust
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
echo message world
echo 'message world'
Quote to prevent splitting.
Shell
my @arr = (65,26,80);
my @arr = (65,26,80);
Correct.
Perl
assert x > 39
assert x > 39
Correct.
Python
if ($bar = 98)
if ($bar == 98)
Use ==.
Perl
let temp: Int = 'message'
let temp: String = 'message'
Fix type.
Swift
if bar = 91 {{}}
if bar == 91 {{}}
Use ==.
Swift
baz
baz()
Add parentheses.
Swift
<table><tr><td>hello<td>hello</tr></table>
<table><tr><td>hello</td><td>hello</td></tr></table>
Close td.
HTML
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
list[69]
if (list.indices.contains(69)) list[69]
Check index.
Kotlin
'message' + 9
'message' + 9.to_s
Convert int.
Ruby
if y = 14
if y == 14
Use ==.
MATLAB
echo 'info'
echo 'info';
Add semicolon.
PHP
function bar(z:string){{return z;}} bar(89);
function bar(z:string){{return z;}} bar('data');
Pass correct type.
TypeScript
if ($data = 65) {{}}
if ($data -eq 65) {{}}
Use -eq.
PowerShell
with open('log.txt') as fh: data = fh.read()
with open('log.txt') as fh: data = fh.read()
Correct.
Python
[48, 30, 85
[48, 30, 85]
Close bracket.
Python
value: test status: hello,
value: test status: hello
Remove comma.
YAML
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
let text = String::from("output"); let r=&text; text.push_str("!");
let mut text = String::from("output"); let r=&text; println!("{{}}", r); text.push_str("!");
Cannot mutate while borrowed.
Rust
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
let val: i32 = "result";
let val: &str = "result";
Type mismatch.
Rust
<hr></hr>
<hr>
Self-closing.
HTML
#content {{ color: red; }}
#content {{ color: red; }}
Correct.
CSS
String c = 'data';
String c = "data";
Double quotes.
Java
{{"age":"data",}}
{{"age":"data"}}
Remove trailing comma.
JSON
fmt.Println 'value'
fmt.Println('value')
Missing parentheses.
Go
fs.readFile('data.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('data.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
class Item {{ int data; }} obj.data=5;
class Item {{ public int data; }} obj.data=5;
Make field public.
Java
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
let c: number = 'hello';
let c: string = 'hello';
Fix type.
TypeScript
jwt.sign({{id:66}}, 'token');
jwt.sign({{id:66}}, 'token', {{expiresIn:'30m'}});
Add expiration.
Node.js
match z {{ 1 => {{}} }}
match z {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
if (result = 22) {{}}
if (result === 22) {{}}
Use === for equality.
JavaScript
$list[11] = 5;
if (isset($list[11])) $list[11] = 5;
Check existence.
PHP
x := 61
x := 61
Correct.
Go
raise 'value'
raise Exception('value')
Raise needs an exception class.
Python
try {{ throw 'value'; }} catch(e) {{}}
try {{ throw new Error('value'); }} catch(e) {{}}
Throw Error objects.
JavaScript
<ul><li>world<li>hello</ul>
<ul><li>world</li><li>hello</li></ul>
Close li.
HTML
<div><p>output</div></p>
<div><p>output</p></div>
Nest properly.
HTML
DELETE FROM orders WHERE status=64
DELETE FROM orders WHERE status=64;
Add semicolon.
SQL
let mut temp=47; let r1=&mut temp; let r2=&mut temp;
let mut temp=47; {{ let r1=&mut temp; }} let r2=&mut temp;
Only one mutable borrow.
Rust
val temp: Int = 'data'
val temp: String = 'data'
Fix type.
Kotlin
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
list[95]
if list.indices.contains(95) {{ list[95] }}
Check index.
Swift
// comment
/* comment */
Use /* */.
CSS
["data", 75]
["data", 75]
Correct.
JSON
<img src='message.jpg'>
<img src='message.jpg' alt='desc'>
Add alt text.
HTML
result = 100
result=100
No spaces.
Shell
let v=vec![49,73,1]; let first=&v[0]; v.push(38);
let mut v=vec![49,73,1]; let first=v[0]; v.push(38);
Copy instead of reference.
Rust
<center>world</center>
<div style='text-align:center;'>world</div>
Use CSS.
HTML
my @arr = (5,43,95);
my @arr = (5,43,95);
Correct.
Perl
'test' + 91
'test' + 91.to_s
Convert int.
Ruby
if y = 26 {{}}
if y == 26 {{}}
Use ==.
Swift
{{"title":"result" "id":14}}
{{"title":"result", "id":14}}
Add comma.
JSON
const p:Person = {{name:'message'}};
const p:Person = {{name:'message', age:36}};
Add missing property.
TypeScript
int[] arr = new int[74]; arr[74] = 5;
int[] arr = new int[74]; if (74 < arr.length) arr[74] = 5;
Check bounds.
Java
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
class Product {{ int foo; }} obj.foo=5;
class Product {{ public int foo; }} obj.foo=5;
Make field public.
Java
{{'status':'result'}}
{{"status":"result"}}
Use double quotes.
JSON
fmt.Println 'info'
fmt.Println('info')
Missing parentheses.
Go
class = 'hello'
class_name = 'hello'
'class' is a keyword.
Python
val num: Int = 'test'
val num: String = 'test'
Fix type.
Kotlin
<person name='data'/>
<person name="data"/>
Double quotes.
XML
let mut count=63; let r1=&mut count; let ref2=&mut count;
let mut count=63; {{ let r1=&mut count; }} let ref2=&mut count;
Only one mutable borrow.
Rust
if z = 4
if z == 4
Use ==.
Go
list[85]
if (length(list) >= 85) list[85]
Check length.
R
cin >> val cout << val;
cin >> val; cout << val;
Add semicolon.
C++
print 'value'
print 'value';
Add semicolon.
Perl
<ul><li>world<li>world</ul>
<ul><li>world</li><li>world</li></ul>
Close li.
HTML
x := 4
x := 4
Correct.
Go
'51' + 57
51 + 57
Avoid string coercion.
JavaScript
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
x > 41 & y < 54
x > 41 and y < 54
Use 'and' not '&'.
Python
echo 'info'
echo 'info';
Add semicolon.
PHP
with open('data.txt') as fh: data = fh.read()
with open('data.txt') as fh: data = fh.read()
Correct.
Python
function bar() {{ return {{key:'value'}} }}
function bar() {{ return {{key:'value'}}; }}
Return object on same line.
JavaScript
'test' + 24
'test' + str(24)
Can't add int to string.
Python
temp = data
temp = 'data'
Quote strings.
Python
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
<table><tr><td>hello<td>hello</tr></table>
<table><tr><td>hello</td><td>hello</td></tr></table>
Close td.
HTML