Skip to content
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

Code review for YG TECHNOLOGY INC #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Code review for YG TECHNOLOGY INC #1

wants to merge 1 commit into from

Conversation

alexburykin
Copy link

No description provided.

@automaze-review
Copy link

Failed

  • 93 New Issues (is greater than 0)
  • 0.00% Security Hotspots Reviewed on New Code (is less than 100.00%)

Analysis Details

111 Issues

  • Bug 1 Bug
  • Vulnerability 19 Vulnerabilities
  • Code Smell 91 Code Smells

Coverage and Duplications

  • Coverage No coverage information (0.00% Estimated after merge)
  • Duplications 1.79% Duplicated Code (1.80% Estimated after merge)

Project ID: automazeio_diffy-worker-review_27ac4111-009b-4b36-83d0-aa16b1dbde3c

View in SonarQube

Copy link
Collaborator

@JackHamish JackHamish left a comment

Choose a reason for hiding this comment

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

Move project to the TypeScript,
Remove unused dependencies and dependencies with doubling of functionality,
Use built in Node JS features,
Update JSDoc ,
Give understandable names to variables,
Replace let and var with const where necessary and also replace all var with let where it is not possible to use const,
Add formatter and linter and configs for them (we recommend using the 2 in 1 library “biome.js”),
Remove useless “Promise.resolve()”,
Prefer using “for...of” instead of “forEach”,
Reject promises when an error occurs and also add error handling, template literals are Preferred over string concatenation
Do not access Object.prototype method 'hasOwnProperty' from target object
Most checks in if blocks can be simplified to an optional chain.
Prefer using arrow functions

// Example to run
// node diffy-screenshots.js --url=https://diffy.website

const debug = false
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can be moved to the env


const debug = false

require('dotenv').config();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can be replaced with built in Node JS env

const jobs = new Jobs(logger)

const { Api } = require('./lib/api.js')
let api
Copy link
Collaborator

Choose a reason for hiding this comment

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

The variable declaration must be changed to const also it can be moved the initialization location.

await end()
});

(async () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

execSync blocks the main thread, so the execution does not take place in parallel, but sequentially, which is directly proportional to the number of tasks.
execSync can be replaced with execAsync and in general you can abandon the for cycle in favor of map and process all promises through Promise.all

// file-content -- if we pass job file as json as parameter
// output-filepath -- path to a file to save the results in json format. Used by wrapper.

require('dotenv').config();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can be replaced with built in Node JS env

Copy link
Collaborator

Choose a reason for hiding this comment

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

Do not access Object.prototype method 'hasOwnProperty' from target object
Most checks in if blocks can be simplified to an optional chainDo not access Object.prototype method
In many cases, the ternary operator can be replaced by "?? " operator that will reduce a large part of the verification code
Replace let and var with const where necessary and also replace all var with let where it is not possible to use const
Prefer to use the more modern "@aws-sdk/client-sqs" package, as "aws sdk v2" will soon lose support

Copy link
Collaborator

Choose a reason for hiding this comment

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

“imagemagick” can be replaced using exist library with more extended functionality “sharp”
Prefer to use arrow functions
Using "sharp", you can refuse callbacks and additional wrapping of promises

Copy link
Collaborator

Choose a reason for hiding this comment

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

“bluebird” can be replaced with native promises
Prefer to use the more modern "@aws-sdk/client-s3" package, as "aws sdk v2" will soon lose support
Replace let and var with const where necessary and also replace all var with let where it is not possible to use const
Template literals are preferred over string concatenation
You can get rid of the additional wrapping of promises by using more modern libraries such as "fs/promises" and "@aws-sdk/client-s3."
Prefer to use arrow functions

.then((fileData) => {
params.Body = fileData;
return Promise
.promisify(s3.putObject, {
Copy link
Collaborator

Choose a reason for hiding this comment

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

There is a better option for simultaneous recording and sending of a file, namely createReadStream

Copy link
Collaborator

Choose a reason for hiding this comment

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

aws-sdk: It is recommended to upgrade to version 3, as it offers improved performance and a reduced library size
bluebird: built-in promises are quite performant and feature-rich.
dotenv: built-in simillar feature
fs-extra: built-in fs has the same functionality
gm and imagemagick: the same functionality already present in sharp
iltorb: deprecated and can be replaced with any modern bundler
minimist and yargs: both libraries provide similar functionality, since you are already using minimist, you can remove yargs
request: deprecated , and no longer maintained. It is recommended to switch to modern alternatives such as axios or fetch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants