Compare commits
4 Commits
bb5a0840fe
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 88313dbfe5 | |||
| ad22917268 | |||
|
|
af9e54deb6 | ||
|
|
5adb236aef |
16
error.js
16
error.js
@@ -1,34 +1,23 @@
|
|||||||
// Basic JS file with review issues
|
|
||||||
|
|
||||||
import React, { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
|
|
||||||
// 1. Component không dùng prop types
|
|
||||||
function Demo(props) {
|
function Demo(props) {
|
||||||
// 2. State không khởi tạo đúng kiểu
|
const [count, setCount] = useState('0');
|
||||||
const [count, setCount] = useState('0'); // Nên là số
|
|
||||||
|
|
||||||
// 3. Hàm không dùng
|
|
||||||
function unusedFunc() {
|
function unusedFunc() {
|
||||||
return 'unused';
|
return 'unused';
|
||||||
}
|
}
|
||||||
|
|
||||||
// 4. Truy cập props không tồn tại
|
|
||||||
const name = props.username;
|
const name = props.username;
|
||||||
|
|
||||||
// 5. Render mảng không có key
|
|
||||||
const arr = [1,2,3];
|
const arr = [1,2,3];
|
||||||
const list = arr.map(item => <li>{item}</li>);
|
const list = arr.map(item => <li>{item}</li>);
|
||||||
|
|
||||||
// 6. Inline style sai cú pháp
|
|
||||||
const style = { color: 'red', fontWeight: 500 };
|
const style = { color: 'red', fontWeight: 500 };
|
||||||
|
|
||||||
// 7. Sử dụng biến chưa khai báo
|
|
||||||
let result = value + 1;
|
let result = value + 1;
|
||||||
|
|
||||||
// 8. Sử dụng setState sai
|
|
||||||
setCount(count++);
|
setCount(count++);
|
||||||
|
|
||||||
// 9. Return nhiều phần tử không bọc Fragment
|
|
||||||
return (
|
return (
|
||||||
<div style={style}>
|
<div style={style}>
|
||||||
<span>Test</span>
|
<span>Test</span>
|
||||||
@@ -37,8 +26,7 @@ function Demo(props) {
|
|||||||
<p>{name}</p>
|
<p>{name}</p>
|
||||||
</div>
|
</div>
|
||||||
<h1>Unwrapped</h1>
|
<h1>Unwrapped</h1>
|
||||||
) // Không bọc Fragment
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 10. Export sai kiểu
|
|
||||||
export { Demo };
|
export { Demo };
|
||||||
|
|||||||
24
error.jsx
24
error.jsx
@@ -1,44 +1,34 @@
|
|||||||
// Basic JSX file with review issues
|
|
||||||
|
|
||||||
import React, { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
|
|
||||||
// 1. Component không dùng prop types
|
|
||||||
function MyComponent(props) {
|
function MyComponent(props) {
|
||||||
// 2. State không khởi tạo đúng kiểu
|
const [count, setCount] = useState('0');
|
||||||
const [count, setCount] = useState('0'); // Nên là số
|
|
||||||
|
|
||||||
// 3. Hàm không dùng
|
|
||||||
function unusedFunc() {
|
function unusedFunc() {
|
||||||
return 'unused';
|
return 'unused';
|
||||||
}
|
}
|
||||||
|
|
||||||
// 4. Truy cập props không tồn tại
|
|
||||||
const name = props.username;
|
|
||||||
|
|
||||||
// 5. Render mảng không có key
|
|
||||||
const arr = [1,2,3];
|
const arr = [1,2,3];
|
||||||
const list = arr.map(item => <li>{item}</li>);
|
const list = arr.map(item => <li>{item}</li>);
|
||||||
|
|
||||||
// 6. Inline style sai cú pháp
|
|
||||||
const style = { color: 'red', fontWeight: 500 };
|
const style = { color: 'red', fontWeight: 500 };
|
||||||
|
|
||||||
// 7. Sử dụng biến chưa khai báo
|
|
||||||
let result = value + 1;
|
let result = value + 1;
|
||||||
|
|
||||||
// 8. Sử dụng setState sai
|
const test = null;
|
||||||
|
if (test) {
|
||||||
|
console.log('This will never log');
|
||||||
|
}
|
||||||
|
|
||||||
setCount(count++);
|
setCount(count++);
|
||||||
|
|
||||||
// 9. Return nhiều phần tử không bọc Fragment
|
|
||||||
return (
|
return (
|
||||||
<div style={style}>
|
<div style={style}>
|
||||||
<span>Test</span>
|
<span>Test</span>
|
||||||
{list}
|
{list}
|
||||||
<button onClick={() => setCount('abc')}>Click</button>
|
<button onClick={() => setCount('abc')}>Click</button>
|
||||||
<p>{name}</p>
|
|
||||||
</div>
|
</div>
|
||||||
<h1>Unwrapped</h1>
|
<h1>Unwrapped</h1>
|
||||||
) // Không bọc Fragment
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 10. Export sai kiểu
|
|
||||||
export { MyComponent };
|
export { MyComponent };
|
||||||
|
|||||||
11
error.php
11
error.php
@@ -1,37 +1,26 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
// Sử dụng Yii với nhiều lỗi review
|
|
||||||
use yii\base\Controller;
|
use yii\base\Controller;
|
||||||
|
|
||||||
class SiteController extends Controller {
|
class SiteController extends Controller {
|
||||||
// 1. Hàm không có visibility
|
|
||||||
function actionIndex() {
|
function actionIndex() {
|
||||||
// 2. Truy cập biến chưa khai báo
|
|
||||||
echo $title;
|
echo $title;
|
||||||
|
|
||||||
// 3. SQL injection
|
|
||||||
$id = $_GET['id'];
|
$id = $_GET['id'];
|
||||||
$user = Yii::$app->db->createCommand("SELECT * FROM user WHERE id = $id")->queryOne();
|
$user = Yii::$app->db->createCommand("SELECT * FROM user WHERE id = $id")->queryOne();
|
||||||
|
|
||||||
// 4. Không kiểm tra null
|
|
||||||
echo $user['name'];
|
echo $user['name'];
|
||||||
|
|
||||||
// 5. Không dùng CSRF cho form
|
|
||||||
echo '<form method="post"><input name="test"></form>';
|
echo '<form method="post"><input name="test"></form>';
|
||||||
|
|
||||||
// 6. Không validate dữ liệu
|
|
||||||
$model = new \app\models\User();
|
$model = new \app\models\User();
|
||||||
$model->name = $_POST['name'];
|
$model->name = $_POST['name'];
|
||||||
$model->save();
|
$model->save();
|
||||||
|
|
||||||
// 7. Hardcode đường dẫn
|
|
||||||
require_once('/var/www/html/config.php');
|
require_once('/var/www/html/config.php');
|
||||||
|
|
||||||
// 8. Không đóng kết nối DB
|
|
||||||
// 9. Không xử lý exception
|
|
||||||
throw new Exception('Error!');
|
throw new Exception('Error!');
|
||||||
|
|
||||||
// 10. Hàm trả về giá trị không đúng
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
22
error.ts
22
error.ts
@@ -1,56 +1,44 @@
|
|||||||
// Basic TypeScript file with review issues
|
|
||||||
|
|
||||||
function add(a: number, b: number): number {
|
function add(a: number, b: number): number {
|
||||||
return a + b // Missing semicolon, no type safety for return
|
return a + b
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = add('1', 2); // Passing string instead of number
|
const result = add('1', 2);
|
||||||
console.log(result)
|
console.log(result)
|
||||||
|
|
||||||
// 1. Unused variable
|
|
||||||
let unusedVar: string;
|
let unusedVar: string;
|
||||||
|
|
||||||
// 2. Function with wrong return type
|
|
||||||
function getString(): number {
|
function getString(): number {
|
||||||
return "hello" // Should return number
|
return "hello"
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. Variable declared but never used
|
|
||||||
let neverUsed = 123;
|
let neverUsed = 123;
|
||||||
|
|
||||||
// 4. Type assertion error
|
|
||||||
let x: any = "abc";
|
let x: any = "abc";
|
||||||
let y: number = x as number; // Wrong assertion
|
let y: number = x as number;
|
||||||
|
|
||||||
// 5. Shadowed variable
|
|
||||||
let a = 5;
|
let a = 5;
|
||||||
function shadow() {
|
function shadow() {
|
||||||
let a = "shadowed";
|
let a = "shadowed";
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 6. Function missing return type
|
|
||||||
function noReturnType() {
|
function noReturnType() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 7. Incorrect interface usage
|
|
||||||
interface User {
|
interface User {
|
||||||
name: string;
|
name: string;
|
||||||
age: number;
|
age: number;
|
||||||
}
|
}
|
||||||
const user: User = { name: "A", age: "20" }; // age should be number
|
const user: User = { name: "A", age: "20" };
|
||||||
|
|
||||||
// 8. Array with mixed types
|
|
||||||
const arr: number[] = [1, "2", 3];
|
const arr: number[] = [1, "2", 3];
|
||||||
|
|
||||||
// 9. Unreachable code
|
|
||||||
function unreachable() {
|
function unreachable() {
|
||||||
return 1;
|
return 1;
|
||||||
console.log("This will never run");
|
console.log("This will never run");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 10. Using 'any' type unnecessarily
|
|
||||||
function useAny(a: any, b: any): any {
|
function useAny(a: any, b: any): any {
|
||||||
return a + b;
|
return a + b;
|
||||||
}
|
}
|
||||||
|
|||||||
17
error.tsx
17
error.tsx
@@ -1,35 +1,24 @@
|
|||||||
// Basic TSX file with review issues
|
|
||||||
|
|
||||||
import React, { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
|
|
||||||
// 1. Không dùng prop types hoặc interface cho props
|
|
||||||
type Props = { title?: string };
|
type Props = { title?: string };
|
||||||
function App(props: Props) {
|
function App(props: Props) {
|
||||||
// 2. State sai kiểu
|
const [count, setCount] = useState<string>(0);
|
||||||
const [count, setCount] = useState<string>(0); // Nên là number
|
|
||||||
|
|
||||||
// 3. Hàm không dùng
|
|
||||||
function unusedFunc(): string {
|
function unusedFunc(): string {
|
||||||
return 'unused';
|
return 'unused';
|
||||||
}
|
}
|
||||||
|
|
||||||
// 4. Truy cập props không tồn tại
|
|
||||||
const name = props.username;
|
const name = props.username;
|
||||||
|
|
||||||
// 5. Render mảng không có key
|
|
||||||
const arr = [1,2,3];
|
const arr = [1,2,3];
|
||||||
const list = arr.map(item => <li>{item}</li>);
|
const list = arr.map(item => <li>{item}</li>);
|
||||||
|
|
||||||
// 6. Inline style sai cú pháp
|
|
||||||
const style = { color: 'red', fontWeight: 500 };
|
const style = { color: 'red', fontWeight: 500 };
|
||||||
|
|
||||||
// 7. Sử dụng biến chưa khai báo
|
|
||||||
let result = value + 1;
|
let result = value + 1;
|
||||||
|
|
||||||
// 8. Sử dụng setState sai
|
|
||||||
setCount(count++);
|
setCount(count++);
|
||||||
|
|
||||||
// 9. Return nhiều phần tử không bọc Fragment
|
|
||||||
return (
|
return (
|
||||||
<div style={style}>
|
<div style={style}>
|
||||||
<span>Hello World</span>
|
<span>Hello World</span>
|
||||||
@@ -38,11 +27,9 @@ function App(props: Props) {
|
|||||||
<p>{name}</p>
|
<p>{name}</p>
|
||||||
</div>
|
</div>
|
||||||
<h1>Unwrapped</h1>
|
<h1>Unwrapped</h1>
|
||||||
) // Không bọc Fragment
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 10. Export sai kiểu
|
|
||||||
export { App };
|
export { App };
|
||||||
|
|
||||||
// 11. Unused variable
|
|
||||||
const unused = 123;
|
const unused = 123;
|
||||||
|
|||||||
Reference in New Issue
Block a user