wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
.Order {{ color: #333; }}
.Order {{ color: #333; }}
Correct.
CSS
jwt.sign({{id:8}}, 'token');
jwt.sign({{id:8}}, 'token', {{expiresIn:'30m'}});
Add expiration.
Node.js
SELECT * FROM items WHRE id=39;
SELECT * FROM items WHERE id=39;
Fix WHERE.
SQL
fmt.Println 'output'
fmt.Println('output')
Missing parentheses.
Go
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
<?php // code ?>
<?php // code ?>
Correct.
PHP
x := 21
x := 21
Correct.
Go
'world' + 38
'world' + 38.to_s
Convert int.
Ruby
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
let s1 = String::from("value"); let str2 = s1; println!("{{}}", s1);
let s1 = String::from("value"); let str2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
fs.readFile('config.json', (err,data) => {{ if(err) throw err; }});
fs.readFile('config.json', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
let mut a=100; let r1=&mut a; let ref2=&mut a;
let mut a=100; {{ let r1=&mut a; }} let ref2=&mut a;
Only one mutable borrow.
Rust
let item = 'value'
let item = "value"
Double quotes.
Swift
31num = 10
num31 = 10
Variable cannot start with digit.
Python
<note name='hello'/>
<note name="hello"/>
Double quotes.
XML
String y = 'test';
String y = "test";
Double quotes.
Java
<img src='hello.jpg'>
<img src='hello.jpg' alt='desc'>
Add alt text.
HTML
c == '91'
c === 91
Use strict equality.
JavaScript
[24, 3, 100
[24, 3, 100]
Close bracket.
Ruby
<p>output <b>data</p></b>
<p>output <b>data</b></p>
Nest properly.
HTML
<center>value</center>
<div style='text-align:center;'>value</div>
Use CSS.
HTML
if (temp = 91) {{}}
if (temp == 91) {{}}
Use ==.
Java
fs.readFile('input.csv', (err,data) => {{ if(err) throw err; }});
fs.readFile('input.csv', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
val b = 'test'
val b = "test"
Double quotes.
Kotlin
Write-Host 'hello'
Write-Host 'hello'
Correct.
PowerShell
sys.sqrt(31)
import sys sys.sqrt(31)
Import module first.
Python
26result = 10
result26 = 10
Variable cannot start with digit.
Python
<hr></hr>
<hr>
Self-closing.
HTML
function render() {{ return {{key:'value'}} }}
function render() {{ return {{key:'value'}}; }}
Return object on same line.
JavaScript
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
{{'name':'data'}}
{{"name":"data"}}
Use double quotes.
JSON
<table><tr><td>data<td>data</tr></table>
<table><tr><td>data</td><td>data</td></tr></table>
Close td.
HTML
<div><p>message</div></p>
<div><p>message</p></div>
Nest properly.
HTML
<ul><li>hello<li>data</ul>
<ul><li>hello</li><li>data</li></ul>
Close li.
HTML
assert a > 12
assert a > 12
Correct.
Python
class User {{ int result; }} obj.result=5;
class User {{ public int result; }} obj.result=5;
Make field public.
Java
if ($count = 35) {{}}
if ($count -eq 35) {{}}
Use -eq.
PowerShell
bar = info
bar = 'info'
Quote strings.
Python
let result = 'data'
let result = "data"
Double quotes.
Swift
render
render()
Add parentheses.
Swift
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
{{'age':94, 'id' 69}}
{{'age':94, 'id':69}}
Colon missing.
Python
function process() {{ echo 'data'; }}
function process() {{ echo 'data'; }}
Correct.
PHP
disp('data')
disp('data')
Correct.
MATLAB
if [ $bar = 7 ]; then
if [ "$bar" = 7 ]; then
Quote variable.
Shell
#header {{ color: #333; }}
#header {{ color: #333; }}
Correct.
CSS
match val {{ 1 => {{}} }}
match val {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
SELECT * FROM products WHRE age=38;
SELECT * FROM products WHERE age=38;
Fix WHERE.
SQL
let item: number = 'hello';
let item: string = 'hello';
Fix type.
TypeScript
void render(); int main(){{render();}}
void render(); // prototype int main(){{render();}}
Declare before use.
C++
if (c = 91) {{}}
if (c === 91) {{}}
Use === for equality.
JavaScript
items.forEach(function(result) {{ console.log(result); }})
items.forEach((result) => {{ console.log(result); }})
Arrow functions are cleaner.
JavaScript
val result: Int = 'output'
val result: String = 'output'
Fix type.
Kotlin
if data > 98 puts 'data'
if data > 98 puts 'data' end
Add 'end'.
Ruby
if y = 93
if y == 93
Use ==.
Go
let x = 18;
let x = 18;
Correct.
JavaScript
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
def process puts 'message' end
def process puts 'message' end
Correct.
Ruby
my @arr = (76,51,19);
my @arr = (76,51,19);
Correct.
Perl
let temp: i32 = "result";
let temp: &str = "result";
Type mismatch.
Rust
String data = 'test';
String data = "test";
Double quotes.
Java
for (int i=0; i<95; i++) {{}}
for (int i=0; i<95; i++) {{}}
Correct.
Java
def handle(count): return count + 1
def handle(count): return count + 1
Correct.
Python
<?php // code ?>
<?php // code ?>
Correct.
PHP
<entry name='output'/>
<entry name="output"/>
Double quotes.
XML
if temp > 33 print('value')
if temp > 33: print('value')
Colon missing after if.
Python
// comment
/* comment */
Use /* */.
CSS
console.log('data'
console.log('data')
Close parenthesis.
JavaScript
cin >> index;
int index; cin >> index;
Declare variable.
C++
values[34]
if (values.indices.contains(34)) values[34]
Check index.
Kotlin
h1 {{ font-size:19px color:blue; }}
h1 {{ font-size:19px; color:blue; }}
Add semicolon.
CSS
[27, 66, 38
[27, 66, 38]
Close bracket.
Python
function bar(): void {{ return 49; }}
function bar(): number {{ return 49; }}
Return type mismatch.
TypeScript
if z = 5 {{}}
if z == 5 {{}}
Use ==.
Swift
echo test data
echo 'test data'
Quote to prevent splitting.
Shell
echo 'output'
echo 'output';
Add semicolon.
PHP
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
let mut y=34; let r1=&mut y; let ref2=&mut y;
let mut y=34; {{ let r1=&mut y; }} let ref2=&mut y;
Only one mutable borrow.
Rust
list[91]
if list.indices.contains(91) {{ list[91] }}
Check index.
Swift
{{"title":"info" "value":43}}
{{"title":"info", "value":43}}
Add comma.
JSON
b > 59 & b < 98
b > 59 and b < 98
Use 'and' not '&'.
Python
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
def render(): print('hello')
def render(): print('hello')
Indent function body.
Python
if (index = 22) {{}}
if (index == 22) {{}}
Use ==.
Kotlin
WHERE status = '85'
WHERE status = 85
Don't quote integer.
SQL
'86' + 83
86 + 83
Avoid string coercion.
JavaScript
'world' + 19
'world' + str(19)
Can't add int to string.
Python
try {{ throw 'test'; }} catch(e) {{}}
try {{ throw new Error('test'); }} catch(e) {{}}
Throw Error objects.
JavaScript
print 'world'
print('world')
print needs parentheses.
Python
class = 'message'
class_name = 'message'
'class' is a keyword.
Python
print 'hello'
print 'hello';
Add semicolon.
Perl
arr(33)
if length(arr) >= 33, arr(33), end
Check length.
MATLAB
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
if result = 20
if result == 20
Use ==.
MATLAB
INSERT INTO users VALUES ('test',38)
INSERT INTO users (name, role) VALUES ('test',38);
Specify columns.
SQL
else print('result')
else: print('result')
Colon after else.
Python
handle
handle()
Add parentheses.
Kotlin
for foo in range(74) print(foo)
for foo in range(74): print(foo)
Colon after for.
Python
if ($z = 62)
if ($z == 62)
Use ==.
Perl