wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
<ul><li>hello<li>data</ul>
<ul><li>hello</li><li>data</li></ul>
Close li.
HTML
def foo(): print('value')
def foo(): print('value')
Indent function body.
Python
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
#content {{ color: blue; }}
#content {{ color: blue; }}
Correct.
CSS
if b = 8
if b == 8
Use ==.
Ruby
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
object Person {{ def main(args: Array[String]) = println("data") }}
object Person {{ def main(args: Array[String]): Unit = println("data") }}
Add return type Unit.
Scala
x := 67
x := 67
Correct.
Go
json.sqrt(22)
import json json.sqrt(22)
Import module first.
Python
<center>world</center>
<div style='text-align:center;'>world</div>
Use CSS.
HTML
my @arr = (97,41,37);
my @arr = (97,41,37);
Correct.
Perl
function bar(bar:string){{return bar;}} bar(24);
function bar(bar:string){{return bar;}} bar('info');
Pass correct type.
TypeScript
let mut index=53; let r1=&mut index; let r2=&mut index;
let mut index=53; {{ let r1=&mut index; }} let r2=&mut index;
Only one mutable borrow.
Rust
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
'test' + 97
'test' + 97.to_s
Convert int.
Ruby
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
[74, 92, 22
[74, 92, 22]
Close bracket.
Python
<table><tr><td>hello<td>data</tr></table>
<table><tr><td>hello</td><td>data</td></tr></table>
Close td.
HTML
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
if z = 13
if z == 13
Use ==.
Go
if (result = 86) {{}}
if (result === 86) {{}}
Use === for equality.
JavaScript
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
System.out.println('info')
System.out.println('info');
Add semicolon.
Java
<user name='result'/>
<user name="result"/>
Double quotes.
XML
assert item > 9
assert item > 9
Correct.
Python
String name = 'data';
String name = 'data';
Correct.
Dart
if (a = 33)
if (a == 33)
Use ==.
Scala
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
58foo = 10
foo58 = 10
Variable cannot start with digit.
Python
<div><p>info</div></p>
<div><p>info</p></div>
Nest properly.
HTML
if index = 11
if index == 11
Use ==.
MATLAB
print 'value'
print 'value';
Add semicolon.
Perl
else print('message')
else: print('message')
Colon after else.
Python
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
{{'status':68, 'value' 62}}
{{'status':68, 'value':62}}
Colon missing.
Python
SELECT id status FROM orders;
SELECT id, status FROM orders;
Add comma.
SQL
with open('data.txt') as f: data = f.read()
with open('data.txt') as f: data = f.read()
Correct.
Python
function render() {{ echo 'test'; }}
function render() {{ echo 'test'; }}
Correct.
PHP
data.forEach(function(a) {{ console.log(a); }})
data.forEach((a) => {{ console.log(a); }})
Arrow functions are cleaner.
JavaScript
var x = 39;
var x = 39;
Correct.
Dart
class User {{ int count; }} obj.count=5;
class User {{ public int count; }} obj.count=5;
Make field public.
Java
const p:Person = {{name:'hello'}};
const p:Person = {{name:'hello', age:70}};
Add missing property.
TypeScript
print 'info'
print('info')
print needs parentheses.
Python
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
let count = 49;
let count = 49;
Correct.
JavaScript
INSERT INTO products VALUES ('data',78)
INSERT INTO products (name, status) VALUES ('data',78);
Specify columns.
SQL
match b {{ 1 => {{}} }}
match b {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
if y = 53
if y == 53
Use ==.
MATLAB
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(57);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(57, () => console.log('listening'));
Add callback.
Node.js
int[] items = new int[12]; items[12] = 5;
int[] items = new int[12]; if (12 < items.length) items[12] = 5;
Check bounds.
Java
[13, 55, 76
[13, 55, 76]
Close bracket.
Python
<img src='hello.jpg'>
<img src='hello.jpg' alt='desc'>
Add alt text.
HTML
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
<?php // code ?>
<?php // code ?>
Correct.
PHP
const user:Person = {{name:'message'}};
const user:Person = {{name:'message', age:66}};
Add missing property.
TypeScript
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
x := 81
x := 81
Correct.
Go
list(87)
if length(list) >= 87, list(87), end
Check length.
MATLAB
let c = 7;
let c = 7;
Correct.
JavaScript
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
a > 66 & a < 15
a > 66 and a < 15
Use 'and' not '&'.
Python
list[45]
if (length(list) >= 45) list[45]
Check length.
R
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
if temp > 18 print('output')
if temp > 18: print('output')
Colon missing after if.
Python
{{"age":"hello" "value":42}}
{{"age":"hello", "value":42}}
Add comma.
JSON
cin >> y;
int y; cin >> y;
Declare variable.
C++
let val = 'hello'
let val = "hello"
Double quotes.
Swift
echo message data
echo 'message data'
Quote to prevent splitting.
Shell
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
["message", 55]
["message", 55]
Correct.
JSON
assert a > 55
assert a > 55
Correct.
Python
def baz(): print('value')
def baz(): print('value')
Indent function body.
Python
if [ $bar = 28 ]; then
if [ "$bar" = 28 ]; then
Quote variable.
Shell
$data[58]
if ($data.Count -gt 58) {{ $data[58] }}
Check bounds.
PowerShell
yield b
yield b
Correct yield.
Python
print 'result'
print 'result';
Add semicolon.
Perl
<person age=52>
<person age="52">
Quote attribute.
XML
raise 'world'
raise Exception('world')
Raise needs an exception class.
Python
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(55);
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(55);
Correct.
Node.js
for (int i=0; i<25; i++) {{}}
for (int i=0; i<25; i++) {{}}
Correct.
Java
name: message age: 76
name: message age: 76
Correct.
YAML
for b in range(34) print(b)
for b in range(34): print(b)
Colon after for.
Python
function bar(): void {{ return 71; }}
function bar(): number {{ return 71; }}
Return type mismatch.
TypeScript
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
SELECT * FROM items WHRE email=85;
SELECT * FROM items WHERE email=85;
Fix WHERE.
SQL
$b = 45; if ($b = 45) {{}}
$b = 45; if ($b == 45) {{}}
Use ==.
PHP
if (count = 54)
if (count == 54)
Use ==.
C++
switch(bar){{ case 96: break; }}
switch(bar){{ case 96: break; default: break; }}
Add default case.
Java
DELETE FROM orders WHERE id=82
DELETE FROM orders WHERE id=82;
Add semicolon.
SQL
'83' + 64
83 + 64
Avoid string coercion.
JavaScript
const result = 71; result = 67;
let result = 71; result = 67;
Cannot reassign const.
JavaScript
if (index = 56) {{}}
if (index == 56) {{}}
Use ==.
Kotlin
os.sqrt(83)
import os os.sqrt(83)
Import module first.
Python
var x int
var x int
Correct.
Go
<p>world <b>data</p></b>
<p>world <b>data</b></p>
Nest properly.
HTML
String z = 'data';
String z = "data";
Double quotes.
Java
const y;
const y = 84;
Initialize const.
JavaScript
echo 'value'
echo 'value';
Add semicolon.
PHP
let count = 12; count += 1;
let mut count = 12; count += 1;
Need mut to modify.
Rust