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

tools: add sort-requires rule to enforce {a, b, c} = require() is in alphabetical order #44116

Closed
wants to merge 2 commits into from

Conversation

cola119
Copy link
Member

@cola119 cola119 commented Aug 3, 2022

Close #44153

This PR added new custom ESLint rule named sort-requires that verify all destructed members of {} = require() and {} = primordials are sorted alphabetically inspired by eslint/sort-imports

According to make lint-js, there are 221 problems with sort-requires.

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. tools Issues and PRs related to the tools directory. labels Aug 3, 2022
@cola119 cola119 changed the title tools: add require-order rule to enforce a convention in the order of require statement tools: add require-order rule to detect require statement with out of order VariableDeclarator Aug 3, 2022
@cola119 cola119 force-pushed the new-require-order-rule branch from cc98cfc to 80c4ae3 Compare August 3, 2022 15:36
Comment on lines 26 to 28
node &&
node.id &&
node.id.type === 'ObjectPattern'
Copy link

Choose a reason for hiding this comment

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

Suggested change
node &&
node.id &&
node.id.type === 'ObjectPattern'
node?.id?.type === 'ObjectPattern'

@cola119 cola119 changed the title tools: add require-order rule to detect require statement with out of order VariableDeclarator tools: add require-order rule to enforce {a, b, c} = require() is in alphabetical order Aug 6, 2022
@cola119 cola119 force-pushed the new-require-order-rule branch from 80c4ae3 to a4423eb Compare August 6, 2022 13:43
Copy link
Contributor

@LiviaMedeiros LiviaMedeiros left a comment

Choose a reason for hiding this comment

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

Might be a good idea to include a commit with this rule being applied to the codebase, so it would be easier to estimate the amount of code churn.

Shouldn't something like sort-imports go first?

Copy link
Contributor

@aduh95 aduh95 left a comment

Choose a reason for hiding this comment

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

Could this rule also enforce trailing commas for require/primordials destructuring?

tools/eslint-rules/require-order.js Outdated Show resolved Hide resolved
tools/eslint-rules/require-order.js Outdated Show resolved Hide resolved
@cola119 cola119 changed the title tools: add require-order rule to enforce {a, b, c} = require() is in alphabetical order tools: add sort-requires rule to enforce {a, b, c} = require() is in alphabetical order Aug 7, 2022
@cola119 cola119 force-pushed the new-require-order-rule branch from a4423eb to 37d47f0 Compare August 7, 2022 15:29
@cola119 cola119 force-pushed the new-require-order-rule branch from 37d47f0 to a4c2d41 Compare August 7, 2022 15:33
@cola119 cola119 marked this pull request as ready for review August 7, 2022 15:34
Copy link
Contributor

@aduh95 aduh95 left a comment

Choose a reason for hiding this comment

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

We'd need to split this into several commits to minimize the work of backporting. We'd also need to have this rule reject multi-line destructuring without trailing commas.

@cola119 cola119 marked this pull request as draft August 8, 2022 03:29
@cola119
Copy link
Member Author

cola119 commented Nov 1, 2022

Close on top of #41768

@cola119 cola119 closed this Nov 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-ci PRs that need a full CI run. tools Issues and PRs related to the tools directory.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add ESLint rule to enforce {a, b, c} = require() is in alphabetical order
5 participants