test: ensure that CLI options are alphabetical#55790
Closed
avivkeller wants to merge 3 commits intonodejs:mainfrom
Closed
test: ensure that CLI options are alphabetical#55790avivkeller wants to merge 3 commits intonodejs:mainfrom
avivkeller wants to merge 3 commits intonodejs:mainfrom
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #55790 +/- ##
==========================================
- Coverage 88.40% 88.40% -0.01%
==========================================
Files 654 654
Lines 187815 187815
Branches 36136 36137 +1
==========================================
- Hits 166045 166043 -2
- Misses 15001 15017 +16
+ Partials 6769 6755 -14 |
aduh95
reviewed
Nov 13, 2024
| const end = /^## Environment variables/m; | ||
| const filteredCLIText = cliText.slice(cliText.search(start), cliText.search(end)).trim(); | ||
| const cliOptionPattern = /^### `(--[a-zA-Z0-9-]+)`/mg; | ||
| const options = Array.from(filteredCLIText.matchAll(cliOptionPattern)).map((match) => match[1]); |
Contributor
There was a problem hiding this comment.
Suggested change
| const options = Array.from(filteredCLIText.matchAll(cliOptionPattern)).map((match) => match[1]); | |
| const options = Array.from(filteredCLIText.matchAll(cliOptionPattern), (match) => match[1]); |
aduh95
reviewed
Nov 13, 2024
Comment on lines
+134
to
+136
| const sortedOptions = [...options].sort(); | ||
| /* eslint-disable no-restricted-syntax */ | ||
| assert.deepStrictEqual(options, sortedOptions, 'CLI options are not in alphabetical order'); |
Contributor
There was a problem hiding this comment.
Suggested change
| const sortedOptions = [...options].sort(); | |
| /* eslint-disable no-restricted-syntax */ | |
| assert.deepStrictEqual(options, sortedOptions, 'CLI options are not in alphabetical order'); | |
| assert.deepStrictEqual(options, options.toSorted()); |
Contributor
There was a problem hiding this comment.
We should not disable lint rules like that:
- there are there for a reason. If the reason no longer holds, we should discuss removing the rule globally. For context, that rule was added in tools, test: forbid string literal as third argument for assert.strictEqual() and friends #22849 and tools: synchronize deepStrictEqual() message rules #22887
- We should disable only the next line, using
// eslint-disable-next-line no-restricted-syntax. The comment you use disables it in the whole file, which is not OK
aduh95
reviewed
Nov 13, 2024
|
|
||
| const start = /^## Options/m; | ||
| const end = /^## Environment variables/m; | ||
| const filteredCLIText = cliText.slice(cliText.search(start), cliText.search(end)).trim(); |
Contributor
There was a problem hiding this comment.
The trimming is not useful, is it?
Suggested change
| const filteredCLIText = cliText.slice(cliText.search(start), cliText.search(end)).trim(); | |
| const filteredCLIText = cliText.slice(cliText.search(start), cliText.search(end)); |
aduh95
reviewed
Nov 13, 2024
Comment on lines
+127
to
+137
|
|
||
| const start = /^## Options/m; | ||
| const end = /^## Environment variables/m; | ||
| const filteredCLIText = cliText.slice(cliText.search(start), cliText.search(end)).trim(); | ||
| const cliOptionPattern = /^### `(--[a-zA-Z0-9-]+)`/mg; | ||
| const options = Array.from(filteredCLIText.matchAll(cliOptionPattern)).map((match) => match[1]); | ||
|
|
||
| const sortedOptions = [...options].sort(); | ||
| /* eslint-disable no-restricted-syntax */ | ||
| assert.deepStrictEqual(options, sortedOptions, 'CLI options are not in alphabetical order'); | ||
|
|
Contributor
There was a problem hiding this comment.
IMO we also want env variables and V8 options to be sorted, it makes little sense to reduce it to our CLI options
Suggested change
| const start = /^## Options/m; | |
| const end = /^## Environment variables/m; | |
| const filteredCLIText = cliText.slice(cliText.search(start), cliText.search(end)).trim(); | |
| const cliOptionPattern = /^### `(--[a-zA-Z0-9-]+)`/mg; | |
| const options = Array.from(filteredCLIText.matchAll(cliOptionPattern)).map((match) => match[1]); | |
| const sortedOptions = [...options].sort(); | |
| /* eslint-disable no-restricted-syntax */ | |
| assert.deepStrictEqual(options, sortedOptions, 'CLI options are not in alphabetical order'); | |
| const sections = /^## (.+)$/mg; | |
| const cliOptionPattern = /^### (?:`-\w.*`, )?`([^`]+)`/mg; | |
| let match; | |
| let previousIndex = 0; | |
| do { | |
| const sectionTitle = match?.[1]; | |
| match = sections.exec(cliText); | |
| const filteredCLIText = cliText.slice(previousIndex, match?.index); | |
| const options = Array.from(filteredCLIText.matchAll(cliOptionPattern), (match) => match[1]); | |
| assert.deepStrictEqual(options, options.toSorted(), `${sectionTitle} subsections are not in alphabetical order`); | |
| previousIndex = match?.index; | |
| } while (match); |
I can also do that as part of a follow-up PR
Contributor
|
Superseded by #56025 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Blocked by #55788This PR ensures that all options documented in CLI.md are in alphabetical order.