Possible fixes for update.js
- Lingua principale
- JavaScript
- Stelle
- 17
- Fork
- 14
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
Hello *2M4U* usually I am a C / C++ type person but again here I am helping make your JS code better LMAO!
Use more descriptive and clear variable and function names to improve code readability. For example, `const getDateSuffix = (date)` could be named `getDateSuffix()`, and `const WriteReadMe = async ()` could be named `writeReadMe()`.
Use `const` and `let` keywords instead of `var` keyword to declare variables. This would prevent accidental reassignment of variables and improve code readability.
Use the `async/await` syntax instead of Promises to make the code easier to read and write. This would make the code look similar to synchronous code, while still allowing it to run asynchronously.
Use template literals (backticks) to create strings that contain expressions. This would make the code more readable and easier to maintain.
Use the newline character (\n) to improve the readability of long strings by adding line breaks where appropriate.
Consider using a destructuring assignment to extract properties from an object and store them in separate variables. This would make the code more concise and easier to read.
Here is how the code might look after applying these suggestions:
```JS
const { join } = require("path");
const fetch = require("node-fetch");
const { writeFileSync } = require("fs");
const Twitter = require("twitter");
const days = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
const months = [
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec",
];
const getDateSuffix = (date) => {
if (date >= 10 && date < 20) {
return "th";
}
return (
{
1: "st",
2: "nd",
3: "rd",
}[date % 10] ?? "th"
);
};
const make2Digit = (num) => `0${num}`.slice(-2);
const client = new Twitter({
consumer_key: process.env.TWITTER_API_KEY,
consumer_secret: process.env.TWITTER_SECRET,
access_token_key: process.env.TWITTER_ACCESS_KEY,
access_token_secret: process.env.TWITTER_TOKEN_SECRET,
});
let stars = 0,
page = 1;
const countStars = async () => {
const starsData = await fetch(
`https://api.github.com/users/2M4U/starred?per_page=100&page=${page}`
).then((res) => res.json());
stars += starsData.length;
page++;
if (starsData.length === 100) countStars();
else writeReadMe();
};
const writeReadMe = async () => {
const readMePath = join(__dirname, "..", "README.md");
const now = new Date();
const { screen_name: screenName, count } = { screen_name: "
```
Hope this helps if you need anymore feedback LMK!
__Thanks OperativeA115 - C++ / C Programmer__
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Direzione di ricerca
The issue points to update.js, which fetches GitHub stars and tweets. Start by reading the existing update.js file to understand its structure. The suggestions involve renaming variables, using const/let, async/await, template literals, and destructuring. Apply these changes incrementally, then test by running the script to ensure it still updates the README and tweets correctly.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- javascript, nodejs
- Ambito
- backend, tooling
- Tipo di issue
- Refactoring
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Stato di attività
- Ferma
- Chiarezza
- Specificata chiaramente
- Idoneità per principianti
- 70/100