From bb5a0840febef8dddf537c3a4f1c06b0f4e67b0d Mon Sep 17 00:00:00 2001 From: "lam.pt" Date: Fri, 29 Aug 2025 09:44:52 +0700 Subject: [PATCH] Add file --- error.js | 44 +++++++++++++++++++++++++++++++++++++++++++ error.jsx | 44 +++++++++++++++++++++++++++++++++++++++++++ error.php | 37 ++++++++++++++++++++++++++++++++++++ error.ts | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ error.tsx | 48 +++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 229 insertions(+) create mode 100644 error.js create mode 100644 error.jsx create mode 100644 error.php create mode 100644 error.ts create mode 100644 error.tsx diff --git a/error.js b/error.js new file mode 100644 index 0000000..b8db645 --- /dev/null +++ b/error.js @@ -0,0 +1,44 @@ +// Basic JS file with review issues + +import React, { useState } from 'react'; + +// 1. Component không dùng prop types +function Demo(props) { + // 2. State không khởi tạo đúng kiểu + const [count, setCount] = useState('0'); // Nên là số + + // 3. Hàm không dùng + function unusedFunc() { + 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 list = arr.map(item =>
  • {item}
  • ); + + // 6. Inline style sai cú pháp + const style = { color: 'red', fontWeight: 500 }; + + // 7. Sử dụng biến chưa khai báo + let result = value + 1; + + // 8. Sử dụng setState sai + setCount(count++); + + // 9. Return nhiều phần tử không bọc Fragment + return ( +
    + Test + {list} + +

    {name}

    +
    +

    Unwrapped

    + ) // Không bọc Fragment +} + +// 10. Export sai kiểu +export { Demo }; diff --git a/error.jsx b/error.jsx new file mode 100644 index 0000000..ea26867 --- /dev/null +++ b/error.jsx @@ -0,0 +1,44 @@ +// Basic JSX file with review issues + +import React, { useState } from 'react'; + +// 1. Component không dùng prop types +function MyComponent(props) { + // 2. State không khởi tạo đúng kiểu + const [count, setCount] = useState('0'); // Nên là số + + // 3. Hàm không dùng + function unusedFunc() { + 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 list = arr.map(item =>
  • {item}
  • ); + + // 6. Inline style sai cú pháp + const style = { color: 'red', fontWeight: 500 }; + + // 7. Sử dụng biến chưa khai báo + let result = value + 1; + + // 8. Sử dụng setState sai + setCount(count++); + + // 9. Return nhiều phần tử không bọc Fragment + return ( +
    + Test + {list} + +

    {name}

    +
    +

    Unwrapped

    + ) // Không bọc Fragment +} + +// 10. Export sai kiểu +export { MyComponent }; diff --git a/error.php b/error.php new file mode 100644 index 0000000..8592bf9 --- /dev/null +++ b/error.php @@ -0,0 +1,37 @@ +db->createCommand("SELECT * FROM user WHERE id = $id")->queryOne(); + + // 4. Không kiểm tra null + echo $user['name']; + + // 5. Không dùng CSRF cho form + echo '
    '; + + // 6. Không validate dữ liệu + $model = new \app\models\User(); + $model->name = $_POST['name']; + $model->save(); + + // 7. Hardcode đường dẫn + 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!'); + + // 10. Hàm trả về giá trị không đúng + return true; + } +} diff --git a/error.ts b/error.ts new file mode 100644 index 0000000..5ac9ee2 --- /dev/null +++ b/error.ts @@ -0,0 +1,56 @@ +// Basic TypeScript file with review issues + +function add(a: number, b: number): number { + return a + b // Missing semicolon, no type safety for return +} + +const result = add('1', 2); // Passing string instead of number +console.log(result) + +// 1. Unused variable +let unusedVar: string; + +// 2. Function with wrong return type +function getString(): number { + return "hello" // Should return number +} + +// 3. Variable declared but never used +let neverUsed = 123; + +// 4. Type assertion error +let x: any = "abc"; +let y: number = x as number; // Wrong assertion + +// 5. Shadowed variable +let a = 5; +function shadow() { + let a = "shadowed"; + return a; +} + +// 6. Function missing return type +function noReturnType() { + return true; +} + +// 7. Incorrect interface usage +interface User { + name: string; + age: number; +} +const user: User = { name: "A", age: "20" }; // age should be number + +// 8. Array with mixed types +const arr: number[] = [1, "2", 3]; + +// 9. Unreachable code +function unreachable() { + return 1; + console.log("This will never run"); +} + +// 10. Using 'any' type unnecessarily +function useAny(a: any, b: any): any { + return a + b; +} diff --git a/error.tsx b/error.tsx new file mode 100644 index 0000000..d303a26 --- /dev/null +++ b/error.tsx @@ -0,0 +1,48 @@ +// Basic TSX file with review issues + +import React, { useState } from 'react'; + +// 1. Không dùng prop types hoặc interface cho props +type Props = { title?: string }; +function App(props: Props) { + // 2. State sai kiểu + const [count, setCount] = useState(0); // Nên là number + + // 3. Hàm không dùng + function unusedFunc(): string { + 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 list = arr.map(item =>
  • {item}
  • ); + + // 6. Inline style sai cú pháp + const style = { color: 'red', fontWeight: 500 }; + + // 7. Sử dụng biến chưa khai báo + let result = value + 1; + + // 8. Sử dụng setState sai + setCount(count++); + + // 9. Return nhiều phần tử không bọc Fragment + return ( +
    + Hello World + {list} + +

    {name}

    +
    +

    Unwrapped

    + ) // Không bọc Fragment +} + +// 10. Export sai kiểu +export { App }; + +// 11. Unused variable +const unused = 123;