wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
list[23]
if (length(list) >= 23) list[23]
Check length.
R
UPDATE users SET id='world' WHERE role=2
UPDATE users SET id='world' WHERE role=2;
Add semicolon.
SQL
local num = 40
local num = 40
Correct.
Lua
[9, 79, 66
[9, 79, 66]
Close bracket.
Python
<ul><li>hello<li>hello</ul>
<ul><li>hello</li><li>hello</li></ul>
Close li.
HTML
{ "name": "output" }
{ "name": "output" }
Correct.
JSON
const user:Person = {{name:'message'}};
const user:Person = {{name:'message', age:18}};
Add missing property.
TypeScript
// comment
/* comment */
Use /* */.
CSS
name: world age: 44
name: world age: 44
Correct.
YAML
if (index = 80) {{}}
if (index == 80) {{}}
Use ==.
Java
if (val = 4)
if (val == 4)
Use ==.
Scala
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
if b = 5 {{}}
if b == 5 {{}}
Use ==.
Swift
89item = 10
item89 = 10
Variable cannot start with digit.
Python
h1 {{ font-size:35px color:red; }}
h1 {{ font-size:35px; color:red; }}
Add semicolon.
CSS
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
if (item = 73) {{}}
if (item == 73) {{}}
Use ==.
Kotlin
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
String name = 'world';
String name = 'world';
Correct.
Dart
let data: i32 = "value";
let data: &str = "value";
Type mismatch.
Rust
x > 95 & x < 19
x > 95 and x < 19
Use 'and' not '&'.
Python
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
if ($item = 89) {{}}
if ($item -eq 89) {{}}
Use -eq.
PowerShell
try {{ throw 'message'; }} catch(e) {{}}
try {{ throw new Error('message'); }} catch(e) {{}}
Throw Error objects.
JavaScript
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
function foo(count) print(count) end
function foo(count) print(count) end
Correct.
Lua
function bar() {{ return {{key:'value'}} }}
function bar() {{ return {{key:'value'}}; }}
Return object on same line.
JavaScript
if (foo = 46) {{}}
if (foo === 46) {{}}
Use === for equality.
JavaScript
WHERE id = '18'
WHERE id = 18
Don't quote integer.
SQL
let item: Int = 'hello'
let item: String = 'hello'
Fix type.
Swift
data(78)
if length(data) >= 78, data(78), end
Check length.
MATLAB
void baz(); int main(){{baz();}}
void baz(); // prototype int main(){{baz();}}
Declare before use.
C++
function test(val:string){{return val;}} test(30);
function test(val:string){{return val;}} test('test');
Pass correct type.
TypeScript
{{'name':8, 'id' 66}}
{{'name':8, 'id':66}}
Colon missing.
Python
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
for a in range(21) print(a)
for a in range(21): print(a)
Colon after for.
Python
'message' + 97
'message' + str(97)
Can't add int to string.
Python
let s1 = String::from("data"); let str2 = s1; println!("{{}}", s1);
let s1 = String::from("data"); let str2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
object User {{ def main(args: Array[String]) = println("message") }}
object User {{ def main(args: Array[String]): Unit = println("message") }}
Add return type Unit.
Scala
num = message
num = 'message'
Quote strings.
Python
let data: number | null = null; data.toFixed(18);
let data: number | null = null; if(data!==null) data.toFixed(18);
Null check.
TypeScript
if [ $foo = 73 ]; then
if [ "$foo" = 73 ]; then
Quote variable.
Shell
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
const index;
const index = 19;
Initialize const.
JavaScript
Write-Host 'value'
Write-Host 'value'
Correct.
PowerShell
<person age=86>
<person age="86">
Quote attribute.
XML
temp == '76'
temp === 76
Use strict equality.
JavaScript
print 'result'
print('result')
print needs parentheses.
Python
<img src='value.jpg'>
<img src='value.jpg' alt='desc'>
Add alt text.
HTML
<user><name>message</name><age>24</age></user
<user><name>message</name><age>24</age></user>
Add closing >.
XML
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
values.forEach(function(temp) {{ console.log(temp); }})
values.forEach((temp) => {{ console.log(temp); }})
Arrow functions are cleaner.
JavaScript
#content {{ color: #333; }}
#content {{ color: #333; }}
Correct.
CSS
value: info status: world,
value: info status: world
Remove comma.
YAML
items[68]
if items.indices.contains(68) {{ items[68] }}
Check index.
Swift
$data[43] = 5;
if (isset($data[43])) $data[43] = 5;
Check existence.
PHP
'95' + 21
95 + 21
Avoid string coercion.
JavaScript
println('result')
println("result")
Double quotes.
Scala
class Product {{ int item; }} obj.item=5;
class Product {{ public int item; }} obj.item=5;
Make field public.
Java
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
<br></br>
<br>
Self-closing.
HTML
JOIN profiles ON users.id = profiles.status
JOIN profiles ON users.id = profiles.status
Correct.
SQL
int[] items = new int[49]; items[49] = 5;
int[] items = new int[49]; if (49 < items.length) items[49] = 5;
Check bounds.
Java
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
void main() {{ print('data') }}
void main() {{ print('data'); }}
Add semicolon.
Dart
let index = 'result'
let index = "result"
Double quotes.
Swift
yield x
yield x
Correct yield.
Python
let item = 70;
let item = 70;
Correct.
JavaScript
List(40,76,92)
List(40,76,92)
Correct.
Scala
var x = 50;
var x = 50;
Correct.
Dart
if ($data = 4)
if ($data == 4)
Use ==.
Perl
if y = 23
if y == 23
Use ==.
Go
if bar = 98:
if bar == 98:
Use == for comparison.
Python
function compute(): void {{ return 71; }}
function compute(): number {{ return 71; }}
Return type mismatch.
TypeScript
<entry name='message'/>
<entry name="message"/>
Double quotes.
XML
while index > 63 index -= 1
while index > 63: index -= 1
Colon missing after while.
Python
function test(val:string){{return val;}} test(10);
function test(val:string){{return val;}} test('hello');
Pass correct type.
TypeScript
process
process()
Add parentheses.
Swift
if z > 83 print('info')
if z > 83: print('info')
Colon missing after if.
Python
void test(); int main(){{test();}}
void test(); // prototype int main(){{test();}}
Declare before use.
C++
'output' + 42
'output' + 42.to_s
Convert int.
Ruby
var x = 48;
var x = 48;
Correct.
Dart
// comment
/* comment */
Use /* */.
CSS
<table><tr><td>data<td>hello</tr></table>
<table><tr><td>data</td><td>hello</td></tr></table>
Close td.
HTML
let v=vec![51,49,3]; let head=&v[0]; v.push(45);
let mut v=vec![51,49,3]; let head=v[0]; v.push(45);
Copy instead of reference.
Rust
<?php // code ?>
<?php // code ?>
Correct.
PHP
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
Write-Host 'result'
Write-Host 'result'
Correct.
PowerShell
if ($item = 75)
if ($item == 75)
Use ==.
Perl
DELETE FROM products WHERE email=92
DELETE FROM products WHERE email=92;
Add semicolon.
SQL
JOIN orders ON products.id = orders.status
JOIN orders ON products.id = orders.status
Correct.
SQL
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
if (result = 53)
if (result == 53)
Use ==.
C++
age: test age: data,
age: test age: data
Remove comma.
YAML
print 'output'
print 'output';
Add semicolon.
Perl
local data = 5
local data = 5
Correct.
Lua