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

Improve and modernize obs_rsync.js #5068

Merged
merged 7 commits into from
Apr 4, 2023
Merged

Conversation

Lokeshsri11
Copy link
Contributor

There are a few bugs that I can identify.
First, the controlToShow parameter is not passed correctly to the error callback function of the fetchValue function. It should be passed as a separate parameter instead of being included in the callback function's parameter list.

Second, the postAndRedrawElement function doesn't handle the case where the btn.dataset.geturl value is not defined. It should check if the value exists before calling the fetchValue function.

Third, the postAndRedirect function doesn't check if the redir parameter is defined before redirecting to the URL.

And here also the way to optimize our code :
1.Use let and const instead of var to declare variables. let and const provide block-level scoping, which can help avoid variable hoisting and improve code readability.

2.Use arrow functions instead of anonymous functions to improve code readability and reduce typing.

3.Use object destructuring to simplify the code when accessing object properties.

4.Use const instead of var when declaring constant values.

5.Use template literals to concatenate strings instead of using the + operator.

6.Use default function parameters to simplify function calls and provide default values for parameter

Copy link
Contributor

@Martchus Martchus left a comment

Choose a reason for hiding this comment

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

Not sure whether it is required, but also make sure you run make tidy-js. Otherwise the CI checks might complain.

I personally also usually use let and const and the other JavaScript features you've mentioned and gladly accept the PR. However, we usually don't enforce using these for contributions so that's why our JavaScript code which has been touched by many different people is at it is. This is likely not going to change any time soon unless one is willing to modernize it and enforce the style. (Some of our code also simply predates the introduction of certain modern JavaScript features.)

assets/javascripts/obs_rsync.js Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Apr 3, 2023

Codecov Report

Merging #5068 (12066ae) into master (78c4788) will increase coverage by 0.00%.
The diff coverage is n/a.

@@           Coverage Diff           @@
##           master    #5068   +/-   ##
=======================================
  Coverage   98.25%   98.25%           
=======================================
  Files         383      383           
  Lines       36026    36026           
=======================================
+ Hits        35396    35398    +2     
+ Misses        630      628    -2     

see 1 file with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@Martchus
Copy link
Contributor

Martchus commented Apr 3, 2023

You have to run make tidy-js as the JavaScript style-check fails.

@Lokeshsri11
Copy link
Contributor Author

Lokeshsri11 commented Apr 3, 2023

Wait @Martchus i'll update my code and try to make it in tidy-js format

@Martchus
Copy link
Contributor

Martchus commented Apr 3, 2023

I'm adding the "not-ready" label only to prevent mergify from merging automatically as we should squash those commits.

@Lokeshsri11
Copy link
Contributor Author

Okay @Martchus, but I think there are no remaining issues since it passed all test cases :)

@Martchus
Copy link
Contributor

Martchus commented Apr 3, 2023

Yes, we only need to wait for one more approval from the team. Then I'd merge your changes squashing them into one commit.

Copy link
Member

@kalikiana kalikiana left a comment

Choose a reason for hiding this comment

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

Nice tweaks!

@Lokeshsri11
Copy link
Contributor Author

Thank you @Martchus @kalikiana for this PR review and I will continue to try and contribute more to this project.

@Martchus Martchus merged commit 5fdb6a4 into os-autoinst:master Apr 4, 2023
@Martchus
Copy link
Contributor

Martchus commented Apr 4, 2023

We have to thank you!

Note that having multiple commits with generic messages is not ideal. We normally wouldn't merge a PR in that state. Here I've been using GitHub's feature to squash the commits and I gave the resulting commit a more specific message based on the PR description. Checkout 5fdb6a4 for how the commit looks now.

It would be great if you'd follow https://cbea.ms/git-commit next time when committing changes. Then I don't have to squash them. Note that having multiple, smaller commits on your PR branch is totally fine as long as the commit messages are meaningful.

@Martchus Martchus changed the title Update obs_rsync.js Improve and modernize obs_rsync.js Apr 4, 2023
@Lokeshsri11
Copy link
Contributor Author

Okay @Martchus , I will pay attention to all these things from now on :)

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

Successfully merging this pull request may close these issues.

3 participants