wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
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
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
UPDATE users SET status='data' WHERE email=82
UPDATE users SET status='data' WHERE email=82;
Add semicolon.
SQL
for foo in range(61) print(foo)
for foo in range(61): print(foo)
Colon after for.
Python
for i=1,52 do print(i) end
for i=1,52 do print(i) end
Correct.
Lua
'info' + 65
'info' + 65.to_s
Convert int.
Ruby
let data = 29; data += 1;
let mut data = 29; data += 1;
Need mut to modify.
Rust
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
var x = 56;
var x = 56;
Correct.
Dart
math.sqrt(28)
import math math.sqrt(28)
Import module first.
Python
if (num = 29) {{}}
if (num === 29) {{}}
Use === for equality.
JavaScript
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
if item = 41:
if item == 41:
Use == for comparison.
Python
var foo int = 'world'
var foo string = 'world'
Type mismatch.
Go
def compute puts 'hello' end
def compute puts 'hello' end
Correct.
Ruby
switch(foo){{ case 62: break; }}
switch(foo){{ case 62: break; default: break; }}
Add default case.
Java
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
process
process()
Add parentheses.
Swift
if (num = 16)
if (num == 16)
Use ==.
Scala
System.out.println('message')
System.out.println('message');
Add semicolon.
Java
<center>message</center>
<div style='text-align:center;'>message</div>
Use CSS.
HTML
if (x) console.log('yes') else console.log('no')
if (x) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
String name = 'info';
String name = 'info';
Correct.
Dart
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
String val = 'world';
String val = "world";
Double quotes.
Java
<person><age>result</age><age>5</age></person
<person><age>result</age><age>5</age></person>
Add closing >.
XML
if (data = 66) {{}}
if (data == 66) {{}}
Use ==.
Java
<ul><li>test<li>hello</ul>
<ul><li>test</li><li>hello</li></ul>
Close li.
HTML
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
if b = 33
if b == 33
Use ==.
Go
<person age=90>
<person age="90">
Quote attribute.
XML
if item = 67
if item == 67
Use ==.
Ruby
val result = 47; result = 77
var result = 47; result = 77
Use var for reassignment.
Scala
const obj:Person = {{name:'result'}};
const obj:Person = {{name:'result', age:90}};
Add missing property.
TypeScript
{{"title":"data",}}
{{"title":"data"}}
Remove trailing comma.
JSON
<hr></hr>
<hr>
Self-closing.
HTML
let mut result=26; let ref1=&mut result; let r2=&mut result;
let mut result=26; {{ let ref1=&mut result; }} let r2=&mut result;
Only one mutable borrow.
Rust
x := 87
x := 87
Correct.
Go
print 'hello'
print('hello')
Parentheses for function call.
Lua
raise 'output'
raise Exception('output')
Raise needs an exception class.
Python
foo == '81'
foo === 81
Use strict equality.
JavaScript
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(9);
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(9);
Correct.
Node.js
int[] values = new int[23]; values[23] = 5;
int[] values = new int[23]; if (23 < values.length) values[23] = 5;
Check bounds.
Java
let list=vec![7,69,6]; let head=&list[0]; list.push(41);
let mut list=vec![7,69,6]; let head=list[0]; list.push(41);
Copy instead of reference.
Rust
try {{ throw 'data'; }} catch(e) {{}}
try {{ throw new Error('data'); }} catch(e) {{}}
Throw Error objects.
JavaScript
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(63);
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(63);
Correct.
Node.js
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
values.forEach(function(x) {{ console.log(x); }})
values.forEach((x) => {{ console.log(x); }})
Arrow functions are cleaner.
JavaScript
if (item = 69)
if (item == 69)
Use ==.
R
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
<hr></hr>
<hr>
Self-closing.
HTML
const index;
const index = 45;
Initialize const.
JavaScript
let result = 29; let result = 43;
let result = 29; result = 43;
Duplicate declaration.
JavaScript
// comment
/* comment */
Use /* */.
CSS
def process puts 'info' end
def process puts 'info' end
Correct.
Ruby
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
<div><p>value</div></p>
<div><p>value</p></div>
Nest properly.
HTML
int items[100]; items[100]=5;
int items[100]; if(100<100){{}} else items[100]=5;
Bounds check.
C++
void baz(); int main(){{baz();}}
void baz(); // prototype int main(){{baz();}}
Declare before use.
C++
String name = 'value';
String name = 'value';
Correct.
Dart
<p>value <b>test</p></b>
<p>value <b>test</b></p>
Nest properly.
HTML
function handle(y) print(y) end
function handle(y) print(y) end
Correct.
Lua
let y: number = 'result';
let y: string = 'result';
Fix type.
TypeScript
List(50,98,62)
List(50,98,62)
Correct.
Scala
for i=1,34 do print(i) end
for i=1,34 do print(i) end
Correct.
Lua
x = 28
x=28
No spaces.
Shell
class = 'message'
class_name = 'message'
'class' is a keyword.
Python
object Product {{ def main(args: Array[String]) = println("message") }}
object Product {{ def main(args: Array[String]): Unit = println("message") }}
Add return type Unit.
Scala
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
<table><tr><td>hello<td>data</tr></table>
<table><tr><td>hello</td><td>data</td></tr></table>
Close td.
HTML
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
name: info age: 45
name: info age: 45
Correct.
YAML
values[65]
if (values.indices.contains(65)) values[65]
Check index.
Kotlin
Write-Host 'info'
Write-Host 'info'
Correct.
PowerShell
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
let c: Int = 'data'
let c: String = 'data'
Fix type.
Swift
const foo = 39; foo = 52;
let foo = 39; foo = 52;
Cannot reassign const.
JavaScript
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
yield c
yield c
Correct yield.
Python
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
val index = 'data'
val index = "data"
Double quotes.
Kotlin
val x = 29; x = 37
var x = 29; x = 37
Use var for reassignment.
Scala
echo info hello
echo 'info hello'
Quote to prevent splitting.
Shell
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
function process(x:string){{return x;}} process(7);
function process(x:string){{return x;}} process('message');
Pass correct type.
TypeScript
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
let temp = 12;
let temp = 12;
Correct.
JavaScript
let bar = 'info'
let bar = "info"
Double quotes.
Swift
<img src='value.jpg'>
<img src='value.jpg' alt='desc'>
Add alt text.
HTML
function process() {{ return {{key:'value'}} }}
function process() {{ return {{key:'value'}}; }}
Return object on same line.
JavaScript
if a = 20 {{}}
if a == 20 {{}}
Use ==.
Swift
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
System.out.println('world')
System.out.println('world');
Add semicolon.
Java
if num = 92:
if num == 92:
Use == for comparison.
Python