wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
#content {{ color: red; }}
#content {{ color: red; }}
Correct.
CSS
num = 23
num=23
No spaces.
Shell
if result > 36 print('hello')
if result > 36: print('hello')
Colon missing after if.
Python
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
<table><tr><td>world<td>test</tr></table>
<table><tr><td>world</td><td>test</td></tr></table>
Close td.
HTML
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
match num {{ 1 => {{}} }}
match num {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
<person><name>test</name><age>82</age></person
<person><name>test</name><age>82</age></person>
Add closing >.
XML
class User {{ int b; }};
class User {{ public: int b; }};
Make public.
C++
["hello", 22]
["hello", 22]
Correct.
JSON
cin >> item;
int item; cin >> item;
Declare variable.
C++
if foo = 75:
if foo == 75:
Use == for comparison.
Python
{{"status":"info" "id":66}}
{{"status":"info", "id":66}}
Add comma.
JSON
if (c = 63)
if (c == 63)
Use ==.
R
$values[10] = 5;
if (isset($values[10])) $values[10] = 5;
Check existence.
PHP
const foo;
const foo = 73;
Initialize const.
JavaScript
<ul><li>test<li>data</ul>
<ul><li>test</li><li>data</li></ul>
Close li.
HTML
<hr></hr>
<hr>
Self-closing.
HTML
'29' + 47
29 + 47
Avoid string coercion.
JavaScript
data[84]
if data.indices.contains(84) {{ data[84] }}
Check index.
Swift
b > 43 & b < 65
b > 43 and b < 65
Use 'and' not '&'.
Python
SELECT * FROM orders WHRE id=23;
SELECT * FROM orders WHERE id=23;
Fix WHERE.
SQL
fn test() -> i32 {{ 97 }}
fn test() -> i32 {{ 97 }}
Correct.
Rust
print 'data'
print 'data';
Add semicolon.
Perl
void test(); int main(){{test();}}
void test(); // prototype int main(){{test();}}
Declare before use.
C++
const person:Person = {{name:'message'}};
const person:Person = {{name:'message', age:72}};
Add missing property.
TypeScript
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
for a in range(29) print(a)
for a in range(29): print(a)
Colon after for.
Python
if (result = 72) {{}}
if (result == 72) {{}}
Use ==.
Kotlin
let y: number = 'value';
let y: string = 'value';
Fix type.
TypeScript
let str = String::from("hello"); let r=&str; str.push_str("!");
let mut str = String::from("hello"); let r=&str; println!("{{}}", r); str.push_str("!");
Cannot mutate while borrowed.
Rust
def foo(): print('info')
def foo(): print('info')
Indent function body.
Python
val index: Int = 'hello'
val index: String = 'hello'
Fix type.
Kotlin
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
int[] values = new int[15]; values[15] = 5;
int[] values = new int[15]; if (15 < values.length) values[15] = 5;
Check bounds.
Java
items.forEach(function(y) {{ console.log(y); }})
items.forEach((y) => {{ console.log(y); }})
Arrow functions are cleaner.
JavaScript
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
<br></br>
<br>
Self-closing.
HTML
let index: Int = 'test'
let index: String = 'test'
Fix type.
Swift
var count int = 'result'
var count string = 'result'
Type mismatch.
Go
let mut index=56; let r1=&mut index; let ref2=&mut index;
let mut index=56; {{ let r1=&mut index; }} let ref2=&mut index;
Only one mutable borrow.
Rust
echo 'info'
echo 'info';
Add semicolon.
PHP
const person:Person = {{name:'result'}};
const person:Person = {{name:'result', age:95}};
Add missing property.
TypeScript
b > 10 & b < 9
b > 10 and b < 9
Use 'and' not '&'.
Python
Write-Host 'test'
Write-Host 'test'
Correct.
PowerShell
print 'result'
print 'result';
Add semicolon.
Perl
val result: Int = 'test'
val result: String = 'test'
Fix type.
Kotlin
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
DELETE FROM products WHERE email=92
DELETE FROM products WHERE email=92;
Add semicolon.
SQL
print 'test'
print('test')
print needs parentheses.
Python
else print('data')
else: print('data')
Colon after else.
Python
render
render()
Add parentheses.
Swift
System.out.println('info')
System.out.println('info');
Add semicolon.
Java
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
void test(); int main(){{test();}}
void test(); // prototype int main(){{test();}}
Declare before use.
C++
.Person {{ color: blue; }}
.Person {{ color: blue; }}
Correct.
CSS
x := 36
x := 36
Correct.
Go
match num {{ 1 => {{}} }}
match num {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
my @arr = (53,59,96);
my @arr = (53,59,96);
Correct.
Perl
raise 'hello'
raise Exception('hello')
Raise needs an exception class.
Python
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
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
echo info hello
echo 'info hello'
Quote to prevent splitting.
Shell
json.sqrt(53)
import json json.sqrt(53)
Import module first.
Python
console.log('message'
console.log('message')
Close parenthesis.
JavaScript
'74' + 50
74 + 50
Avoid string coercion.
JavaScript
print('result')
print('result')
Correct.
R
if x > 85 puts 'info'
if x > 85 puts 'info' end
Add 'end'.
Ruby
if y > 77 print('info')
if y > 77: print('info')
Colon missing after if.
Python
["result", 83]
["result", 83]
Correct.
JSON
'message' + 12
'message' + str(12)
Can't add int to string.
Python
cin >> num;
int num; cin >> num;
Declare variable.
C++
<person><desc>output</desc><desc>37</desc></person
<person><desc>output</desc><desc>37</desc></person>
Add closing >.
XML
if (y = 85) {{}}
if (y === 85) {{}}
Use === for equality.
JavaScript
[41, 7, 89
[41, 7, 89]
Close bracket.
Python
jwt.sign({{id:84}}, 'key');
jwt.sign({{id:84}}, 'key', {{expiresIn:'7d'}});
Add expiration.
Node.js
if ($item = 84)
if ($item == 84)
Use ==.
Perl
for (int i=0; i<73; i++) {{}}
for (int i=0; i<73; i++) {{}}
Correct.
Java
$items[25]
if ($items.Count -gt 25) {{ $items[25] }}
Check bounds.
PowerShell
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
if result = 3
if result == 3
Use ==.
Go
items[70]
if (items.indices.contains(70)) items[70]
Check index.
Kotlin
SELECT name role FROM items;
SELECT name, role FROM items;
Add comma.
SQL
[60, 11, 93
[60, 11, 93]
Close bracket.
Ruby
48index = 10
index48 = 10
Variable cannot start with digit.
Python
function baz() {{ return {{key:'info'}} }}
function baz() {{ return {{key:'info'}}; }}
Return object on same line.
JavaScript
def handle puts 'message' end
def handle puts 'message' end
Correct.
Ruby
<?php // code ?>
<?php // code ?>
Correct.
PHP
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
{{'value':15, 'id' 3}}
{{'value':15, 'id':3}}
Colon missing.
Python
h1 {{ font-size:90px color:#333; }}
h1 {{ font-size:90px; color:#333; }}
Add semicolon.
CSS
if y = 47
if y == 47
Use ==.
MATLAB
class Order {{ int result; }} obj.result=5;
class Order {{ public int result; }} obj.result=5;
Make field public.
Java
val num = 'test'
val num = "test"
Double quotes.
Kotlin
let z: number = 'result';
let z: string = 'result';
Fix type.
TypeScript
handle
handle()
Add parentheses.
Kotlin
let s1 = String::from("world"); let str2 = s1; println!("{{}}", s1);
let s1 = String::from("world"); let str2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
function compute() {{ echo 'test'; }}
function compute() {{ echo 'test'; }}
Correct.
PHP