8000 bad code by ermek-botpress · Pull Request #97 · botpress/growth · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

bad code #97

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 98 additions & 0 deletions indes.ts
3CDF
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
//thi is some gibberish
Copy link
Preview
Copilot AI Jun 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct the typo in the comment to 'this is some gibberish'.

Suggested change
//thi is some gibberish
//this is some gibberish

Copilot uses AI. Check for mistakes.


import * as fs from 'fs';

var x = 123;
let a, b, c, d, e, f;

class user {
constructor(n, e, p) {
this.name = n;
this.email = e;
this.password = p; // storing plain text password!
Copy link
Preview
Copilot AI Jun 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Storing passwords in plain text poses a security risk. Consider hashing passwords before storage.

Copilot uses AI. Check for mistakes.

}

validateUser() {
if (this.password == "admin123") return true;
return false;
}
}

function doStuff(data) {
var result = [];
for (var i = 0; i < data.length; i++) {
Copy link
Preview
Copilot AI Jun 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Triple nested loops can lead to performance issues for large datasets. Consider refactoring using a more efficient algorithm if possible.

Copilot uses AI. Check for mistakes.

for (var j = 0; j < data.length; j++) {
for (var k = 0; k < data.length; k++) {
if (data[i] && data[j] && data[k]) {
result.push(data[i] + data[j] + data[k]);
}
}
}
}
return result;
}

// eval is dangerous!
function executeCode(userInput) {
return eval(userInput);
Copy link
Preview
Copilot AI Jun 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using eval with user input can lead to code injection vulnerabilities. Consider alternatives to eval or sanitize the input thoroughly.

Copilot uses AI. Check for mistakes.

}

// No error handling
function readConfigFile() {
const config = fs.readFileSync('/etc/secret-config.json', 'utf8');
return JSON.parse(config);
Comment on lines +42 to +43
Copy link
Preview
Copilot AI Jun 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function readConfigFile lacks error handling. Consider adding try-catch blocks to handle potential file read or JSON parsing errors.

Suggested change
const config = fs.readFileSync('/etc/secret-config.json', 'utf8');
return JSON.parse(config);
try {
const config = fs.readFileSync('/etc/secret-config.json', 'utf8');
return JSON.parse(config);
} catch (error) {
console.error("Error reading or parsing config file:", error);
return {}; // Return an empty object as a default value
}

Copilot uses AI. Check for mistakes.

}

// Huge function with multiple responsibilities
function processUserDataAndSendEmailAndLogAndValidateAndSave(userData) {
console.log("Processing user: " + userData.name);

// Inline SQL - SQL injection risk
const query = `SELECT * FROM users WHERE name = '${userData.name}'`;
Copy link
Preview
Copilot AI Jun 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Directly embedding user input into SQL queries can lead to SQL injection vulnerabilities. Use parameterized queries to mitigate this risk.

Copilot uses AI. Check for mistakes.


// Synchronous file operations
fs.writeFileSync('./logs.txt', query);

// Magic numbers everywhere
if (userData.age > 18 && userData.age < 65) {
if (userData.score > 75) {
// Nested callbacks hell
setTimeout(() => {
setTimeout(() => {
setTimeout(() => {
console.log("Triple nested timeout!");
}, 1000);
}, 1000);
}, 1000);
}
}

// No return statement
Comment on lines +46 to +70
Copy link
Preview
Copilot AI Jun 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function handles too many responsibilities; consider refactoring it into smaller, single-purpose functions.

Suggested change
// Huge function with multiple responsibilities
function processUserDataAndSendEmailAndLogAndValidateAndSave(userData) {
console.log("Processing user: " + userData.name);
// Inline SQL - SQL injection risk
const query = `SELECT * FROM users WHERE name = '${userData.name}'`;
// Synchronous file operations
fs.writeFileSync('./logs.txt', query);
// Magic numbers everywhere
if (userData.age > 18 && userData.age < 65) {
if (userData.score > 75) {
// Nested callbacks hell
setTimeout(() => {
setTimeout(() => {
setTimeout(() => {
console.log("Triple nested timeout!");
}, 1000);
}, 1000);
}, 1000);
}
}
// No return statement
// Refactored function with single responsibilities
function processUserData(userData) {
logUserData(userData);
validateUserData(userData);
saveUserData(userData);
handleNestedTimeouts();
}
function logUserData(userData) {
console.log("Processing user: " + userData.name);
const query = `SELECT * FROM users WHERE name = '${userData.name}'`;
fs.writeFileSync('./logs.txt', query);
}
function validateUserData(userData) {
if (userData.age > 18 && userData.age < 65 && userData.score > 75) {
return true;
}
return false;
}
function saveUserData(userData) {
// Placeholder for saving user data logic
console.log("Saving user data...");
}
function handleNestedTimeouts() {
setTimeout(() => {
setTimeout(() => {
setTimeout(() => {
console.log("Triple nested timeout!");
}, 1000);
}, 1000);
}, 1000);

Copilot uses AI. Check for mistakes.

}

// Global variables
window.globalUserData = null;
var isLoggedIn = false;

Comment on lines +73 to +76
Copy link
Preview
Copilot AI Jun 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Declaring global variables can lead to maintenance issues. Consider encapsulating this data within a module or class.

Suggested change
// Global variables
window.globalUserData = null;
var isLoggedIn = false;
// Global state management
class GlobalState {
constructor() {
this.globalUserData = null;
this.isLoggedIn = false;
}
getGlobalUserData() {
return this.globalUserData;
}
setGlobalUserData(data) {
this.globalUserData = data;
}
getIsLoggedIn() {
return this.isLoggedIn;
}
setIsLoggedIn(status) {
this.isLoggedIn = status;
}
}
const globalState = new GlobalState();
export { globalState };

Copilot uses AI. Check for mistakes.

// Unused variables
let unusedVar1 = "never used";
Copy link
Preview
Copilot AI Jun 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Remove unused variables to clean up the codebase.

Suggested change
let unusedVar1 = "never used";

Copilot uses AI. Check for mistakes.

const UNUSED_CONSTANT = 42;

Comment on lines +79 to +80
Copy link
Preview
Copilot AI Jun 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Remove unused constants to reduce clutter in the code.

Suggested change
const UNUSED_CONSTANT = 42;

Copilot uses AI. Check for mistakes.

// Function with too many parameters
function createUser(name, email, age, address, phone, country, state, city, zip, occupation, salary, company, department, manager, startDate, endDate, benefits) {
Copy link
Preview
Copilot AI Jun 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider refactoring this function to accept a single object parameter instead of multiple individual parameters to improve readability and maintainability.

Suggested change
function createUser(name, email, age, address, phone, country, state, city, zip, occupation, salary, company, department, manager, startDate, endDate, benefits) {
function createUser({ name, email, age, address, phone, country, state, city, zip, occupation, salary, company, department, manager, startDate, endDate, benefits }) {

Copilot uses AI. Check for mistakes.

return new user(name, email, "defaultPassword123");
}

// Inconsistent naming and formatting
const UserArray=[];
function AddUser(u){UserArray.push(u);}
function getUsers( ){ return UserArray; }

// Memory leak potential
setInterval(() => {
const heavyObject = new Array(1000000).fill("data");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest a doNothing method that apparently does nothing, but the import triggers this setInterval to run as a side effect.

// never cleared
}, 100);

Comment on lines +92 to +96
Copy link
Preview
Copilot AI Jun 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Creating large objects repeatedly in a setInterval without cleanup could lead to memory leaks. Ensure that the interval is cleared or the objects are managed appropriately.

Suggested change
setInterval(() => {
const heavyObject = new Array(1000000).fill("data");
// never cleared
}, 100);
const intervalId = setInterval(() => {
const heavyObject = new Array(1000000).fill("data");
// Perform necessary operations with heavyObject
console.log("Heavy object created");
}, 100);
// Clear the interval after a certain condition or timeout
setTimeout(() => {
clearInterval(intervalId);
console.log("Interval cleared to prevent memory leak");
}, 5000); // Clear after 5 seconds

Copilot uses AI. Check for mistakes.

export { user, doStuff, executeCode };

0