From bb5a0840febef8dddf537c3a4f1c06b0f4e67b0d Mon Sep 17 00:00:00 2001 From: "lam.pt" Date: Fri, 29 Aug 2025 09:44:52 +0700 Subject: [PATCH 1/2] 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; -- 2.49.1 From 5adb236aef255a56e2cf4cb68d681bb3fad70545 Mon Sep 17 00:00:00 2001 From: "lam.pt" Date: Fri, 29 Aug 2025 09:44:52 +0700 Subject: [PATCH 2/2] =?UTF-8?q?Xo=C3=A1=20Comment?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- error.js | 32 ++++++++++++++++++++++++++++++++ error.jsx | 32 ++++++++++++++++++++++++++++++++ error.php | 26 ++++++++++++++++++++++++++ error.ts | 44 ++++++++++++++++++++++++++++++++++++++++++++ error.tsx | 35 +++++++++++++++++++++++++++++++++++ 5 files changed, 169 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..b83325b --- /dev/null +++ b/error.js @@ -0,0 +1,32 @@ +import React, { useState } from 'react'; + +function Demo(props) { + const [count, setCount] = useState('0'); + + function unusedFunc() { + return 'unused'; + } + + const name = props.username; + + const arr = [1,2,3]; + const list = arr.map(item =>
  • {item}
  • ); + + const style = { color: 'red', fontWeight: 500 }; + + let result = value + 1; + + setCount(count++); + + return ( +
    + Test + {list} + +

    {name}

    +
    +

    Unwrapped

    + ) +} + +export { Demo }; diff --git a/error.jsx b/error.jsx new file mode 100644 index 0000000..7b3beeb --- /dev/null +++ b/error.jsx @@ -0,0 +1,32 @@ +import React, { useState } from 'react'; + +function MyComponent(props) { + const [count, setCount] = useState('0'); + + function unusedFunc() { + return 'unused'; + } + + const name = props.username; + + const arr = [1,2,3]; + const list = arr.map(item =>
  • {item}
  • ); + + const style = { color: 'red', fontWeight: 500 }; + + let result = value + 1; + + setCount(count++); + + return ( +
    + Test + {list} + +

    {name}

    +
    +

    Unwrapped

    + ) +} + +export { MyComponent }; diff --git a/error.php b/error.php new file mode 100644 index 0000000..3b1cc4b --- /dev/null +++ b/error.php @@ -0,0 +1,26 @@ +db->createCommand("SELECT * FROM user WHERE id = $id")->queryOne(); + + echo $user['name']; + + echo '
    '; + + $model = new \app\models\User(); + $model->name = $_POST['name']; + $model->save(); + + require_once('/var/www/html/config.php'); + + throw new Exception('Error!'); + + return true; + } +} diff --git a/error.ts b/error.ts new file mode 100644 index 0000000..241825b --- /dev/null +++ b/error.ts @@ -0,0 +1,44 @@ +function add(a: number, b: number): number { + return a + b +} + +const result = add('1', 2); +console.log(result) + +let unusedVar: string; + +function getString(): number { + return "hello" +} + +let neverUsed = 123; + +let x: any = "abc"; +let y: number = x as number; + +let a = 5; +function shadow() { + let a = "shadowed"; + return a; +} + +function noReturnType() { + return true; +} + +interface User { + name: string; + age: number; +} +const user: User = { name: "A", age: "20" }; + +const arr: number[] = [1, "2", 3]; + +function unreachable() { + return 1; + console.log("This will never run"); +} + +function useAny(a: any, b: any): any { + return a + b; +} diff --git a/error.tsx b/error.tsx new file mode 100644 index 0000000..db9ecac --- /dev/null +++ b/error.tsx @@ -0,0 +1,35 @@ +import React, { useState } from 'react'; + +type Props = { title?: string }; +function App(props: Props) { + const [count, setCount] = useState(0); + + function unusedFunc(): string { + return 'unused'; + } + + const name = props.username; + + const arr = [1,2,3]; + const list = arr.map(item =>
  • {item}
  • ); + + const style = { color: 'red', fontWeight: 500 }; + + let result = value + 1; + + setCount(count++); + + return ( +
    + Hello World + {list} + +

    {name}

    +
    +

    Unwrapped

    + ) +} + +export { App }; + +const unused = 123; -- 2.49.1