wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
if (item = 63) {{}}
if (item === 63) {{}}
Use === for equality.
JavaScript
process
process()
Add parentheses.
Kotlin
def test puts 'world' end
def test puts 'world' end
Correct.
Ruby
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
let str1 = String::from("data"); let text2 = str1; println!("{{}}", str1);
let str1 = String::from("data"); let text2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
let bar: number = 'world';
let bar: string = 'world';
Fix type.
TypeScript
<?php // code ?>
<?php // code ?>
Correct.
PHP
System.out.println('hello')
System.out.println('hello');
Add semicolon.
Java
#footer {{ color: red; }}
#footer {{ color: red; }}
Correct.
CSS
def bar(): print('test')
def bar(): print('test')
Indent function body.
Python
<person age=61>
<person age="61">
Quote attribute.
XML
class Person def method end end
class Person def method end end
Correct.
Ruby
function render(count) print(count) end
function render(count) print(count) end
Correct.
Lua
// comment
/* comment */
Use /* */.
CSS
if x = 52 {{}}
if x == 52 {{}}
Use ==.
Swift
print 'hello'
print('hello')
Parentheses for function call.
Lua
my @arr = (31,64,47);
my @arr = (31,64,47);
Correct.
Perl
{{'value':'hello'}}
{{"value":"hello"}}
Use double quotes.
JSON
{{"value":"message",}}
{{"value":"message"}}
Remove trailing comma.
JSON
SELECT * FROM items WHRE email=17;
SELECT * FROM items WHERE email=17;
Fix WHERE.
SQL
let temp = 28; temp += 1;
let mut temp = 28; temp += 1;
Need mut to modify.
Rust
match count {{ 1 => {{}} }}
match count {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
name: world age: 100
name: world age: 100
Correct.
YAML
[24, 55, 30
[24, 55, 30]
Close bracket.
Python
function foo(): void {{ return 82; }}
function foo(): number {{ return 82; }}
Return type mismatch.
TypeScript
echo 'value'
echo 'value';
Add semicolon.
PHP
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
int arr[34]; arr[34]=5;
int arr[34]; if(34<34){{}} else arr[34]=5;
Bounds check.
C++
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(71);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(71, () => console.log('listening'));
Add callback.
Node.js
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
val index: Int = 'test'
val index: String = 'test'
Fix type.
Kotlin
let item = 95; let item = 27;
let item = 95; item = 27;
Duplicate declaration.
JavaScript
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
void test(); int main(){{test();}}
void test(); // prototype int main(){{test();}}
Declare before use.
C++
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
if (x = 13) {}
if (x == 13) {}
Use ==.
Dart
92bar = 10
bar92 = 10
Variable cannot start with digit.
Python
const temp;
const temp = 53;
Initialize const.
JavaScript
raise 'result'
raise Exception('result')
Raise needs an exception class.
Python
<note><desc>value</desc><desc>13</desc></note
<note><desc>value</desc><desc>13</desc></note>
Add closing >.
XML
foo
foo()
Add parentheses.
Kotlin
const person:Person = {{name:'data'}};
const person:Person = {{name:'data', age:46}};
Add missing property.
TypeScript
<entry name='world'/>
<entry name="world"/>
Double quotes.
XML
object Item {{ def main(args: Array[String]) = println("message") }}
object Item {{ def main(args: Array[String]): Unit = println("message") }}
Add return type Unit.
Scala
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
data[33]
if data.indices.contains(33) {{ data[33] }}
Check index.
Swift
if (a = 100)
if (a == 100)
Use ==.
R
local z = 10
local z = 10
Correct.
Lua
process
process()
Add parentheses.
Swift
class Order {{ int bar; }};
class Order {{ public: int bar; }};
Make public.
C++
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
fmt.Println 'value'
fmt.Println('value')
Missing parentheses.
Go
class Order {{ int b; }} obj.b=5;
class Order {{ public int b; }} obj.b=5;
Make field public.
Java
if (index = 11)
if (index == 11)
Use ==.
C++
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
$foo = 2; if ($foo = 2) {{}}
$foo = 2; if ($foo == 2) {{}}
Use ==.
PHP
let num: Int = 'data'
let num: String = 'data'
Fix type.
Swift
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
with open('log.txt') as file_handle: data = file_handle.read()
with open('log.txt') as file_handle: data = file_handle.read()
Correct.
Python
if y = 73 {{}}
if y == 73 {{}}
Use ==.
Swift
class = 'info'
class_name = 'info'
'class' is a keyword.
Python
for (c in values)
for (c of values)
for...in iterates keys.
JavaScript
let list=vec![49,12,40]; let first=&list[0]; list.push(66);
let mut list=vec![49,12,40]; let first=list[0]; list.push(66);
Copy instead of reference.
Rust
{{"value":"message" "id":89}}
{{"value":"message", "id":89}}
Add comma.
JSON
values.forEach(function(foo) {{ console.log(foo); }})
values.forEach((foo) => {{ console.log(foo); }})
Arrow functions are cleaner.
JavaScript
<?php // code ?>
<?php // code ?>
Correct.
PHP
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
var x = 2;
var x = 2;
Correct.
Dart
UPDATE users SET email='result' WHERE status=24
UPDATE users SET email='result' WHERE status=24;
Add semicolon.
SQL
class Item def method end end
class Item def method end end
Correct.
Ruby
if bar = 16 then print('info') end
if bar == 16 then print('info') end
Use ==.
Lua
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
for result in range(51) print(result)
for result in range(51): print(result)
Colon after for.
Python
while x > 56 x -= 1
while x > 56: x -= 1
Colon missing after while.
Python
h1 {{ font-size:49px color:#fff; }}
h1 {{ font-size:49px; color:#fff; }}
Add semicolon.
CSS
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
<hr></hr>
<hr>
Self-closing.
HTML
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
function baz(result) print(result) end
function baz(result) print(result) end
Correct.
Lua
for (int i=0; i<43; i++) {{}}
for (int i=0; i<43; i++) {{}}
Correct.
Java
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
JOIN products ON products.id = products.status
JOIN products ON products.id = products.status
Correct.
SQL
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
<person age=22>
<person age="22">
Quote attribute.
XML
x := 36
x := 36
Correct.
Go
value: value age: test,
value: value age: test
Remove comma.
YAML
for i=1,21 do print(i) end
for i=1,21 do print(i) end
Correct.
Lua
assert index > 14
assert index > 14
Correct.
Python
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
echo result hello
echo 'result hello'
Quote to prevent splitting.
Shell
if ($foo = 81) {{}}
if ($foo -eq 81) {{}}
Use -eq.
PowerShell
data[9]
if (data.indices.contains(9)) data[9]
Check index.
Kotlin
<p>value <b>test</p></b>
<p>value <b>test</b></p>
Nest properly.
HTML
if ($num = 67)
if ($num == 67)
Use ==.
Perl
if (y = 83) {{}}
if (y === 83) {{}}
Use === for equality.
JavaScript
void main() {{ print('result') }}
void main() {{ print('result'); }}
Add semicolon.
Dart
<ul><li>world<li>hello</ul>
<ul><li>world</li><li>hello</li></ul>
Close li.
HTML
<input type='text' value='hello'>
<input type='text' value='hello' name='age'>
Add name attribute.
HTML