-
-
Notifications
You must be signed in to change notification settings - Fork 621
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
feat: add the fixer
function to eslint/rules/vars-order
#3224
Conversation
lib/node_modules/@stdlib/_tools/eslint/rules/vars-order/lib/main.js
Outdated
Show resolved
Hide resolved
Signed-off-by: Muhammad Haris <[email protected]>
@Planeshifter @kgryte I would like your reviews on this. I got the fixer function working independently .i.e. outside stdlib. But in this branch it doesn't work. I guess there is a step to The rule falls in the |
@headlessNode Yes, you are correct: one currently needs to run Please update the test fixtures of this package though to verify that the new lint rule works. See e.g. https://github.com/stdlib-js/stdlib/blob/develop/lib/node_modules/%40stdlib/_tools/eslint/rules/require-spaces/test/fixtures/invalid.js for how to specify expected output. |
@Planeshifter I've updated the test fixtures. The last case fails and that is because of the fixer function's logic. The fixer function currently swaps the two variables where the error arises. For the case like so:
The function first swaps The reason behind the swapping logic is that this solution seem more "elegant" to me and it is also more efficient than replacing the whole block. What are your thoughts on this? |
While recursive linting may work, I am curious what is the relative performance cost? Linting can already take a long time for a single file, especially for devs running VMs. If recursive linting is significantly more costly, I'd be a bit leery about favoring that approach over single-pass ordering of all variables. |
@kgryte Worst case scenario with recursive is definitely more resource intensive. For using the single-pass do we have a sorting function in stdlib? |
@headlessNode If you are working with normal arrays, just use the built-in |
You will need a custom callback, however, in order to order by length, rather than lexicographically. |
@kgryte @Planeshifter The PR now looks promising. I had introduced a few bugs due to experimenting but now they are addressed. I also add test cases for testing the order of variables in nested functions and they are passing 🥳. But the nested case fails when the outer functions' variables are also not ordered correctly. The error statement is something like |
lib/node_modules/@stdlib/_tools/eslint/rules/vars-order/lib/main.js
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 2 out of 2 changed files in this pull request and generated no suggestions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR looks good, thanks for your work @headlessNode.
With respect to the test failure when both inner and outer function's variable declarations were in the wrong order, we just had to list two elements in the errors
array because now there are two lint failure instances in the code; see the commit I pushed to the branch.
I will go ahead and merge your PR shortly.
PR Commit Message
Please review the above commit message and make any necessary adjustments. |
@Planeshifter Yep, makes sense. Thanks! |
Resolves #3222.
Description
This pull request:
fixer
function toeslint/rules/vars-order
to allow auto-formatting during code review.Related Issues
This pull request:
fixer
function to the ESLint rulevars-order
#3222Questions
No.
Other
No.
Checklist
@stdlib-js/reviewers