-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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
test: ensure that CLI options are alphabetical #55790
base: main
Are you sure you want to change the base?
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 |
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]); |
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.
const options = Array.from(filteredCLIText.matchAll(cliOptionPattern)).map((match) => match[1]); | |
const options = Array.from(filteredCLIText.matchAll(cliOptionPattern), (match) => match[1]); |
const sortedOptions = [...options].sort(); | ||
/* eslint-disable no-restricted-syntax */ | ||
assert.deepStrictEqual(options, sortedOptions, 'CLI options are not in alphabetical order'); |
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.
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()); |
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.
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
|
||
const start = /^## Options/m; | ||
const end = /^## Environment variables/m; | ||
const filteredCLIText = cliText.slice(cliText.search(start), cliText.search(end)).trim(); |
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.
The trimming is not useful, is it?
const filteredCLIText = cliText.slice(cliText.search(start), cliText.search(end)).trim(); | |
const filteredCLIText = cliText.slice(cliText.search(start), cliText.search(end)); |
|
||
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'); | ||
|
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.
IMO we also want env variables and V8 options to be sorted, it makes little sense to reduce it to our CLI options
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
Blocked by #55788This PR ensures that all options documented in CLI.md are in alphabetical order.