Skip to content

Commit a9ae8ee

Browse files
authored
test(docs): improve option filtering in specs (#42846)
chore: improve option filtering in specs Prior to this change, any time any option that had a defined `parents` property that also had root-level markdown documentation would require an update to the `getRequiredConfigSubOptions` and `getRequiredConfigSubOptions` functions in the `documentation.spec.ts`. After this change, that is no longer required as the functions now consider an option root-level when it does not have a `parents` property, `parents` is an empty array, or `parents` contains the root-level specifier (`.`). Originally surfaced from #42671, but extracted to its own PR.
1 parent f45d70b commit a9ae8ee

1 file changed

Lines changed: 35 additions & 25 deletions

File tree

test/docs/documentation.spec.ts

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,25 @@ describe('docs/documentation', () => {
5050
.map((match) =>
5151
match.substring(4, match.length - 1).replace(/^`|`$/g, ''),
5252
)
53-
.filter(
54-
(header) =>
55-
header !== 'managerFilePatterns' && header !== 'enabled',
56-
);
53+
.filter((header) => header !== 'managerFilePatterns');
5754
}
5855

5956
function getRequiredConfigOptions(): string[] {
60-
return options
61-
.filter((option) => !option.globalOnly)
62-
.filter((option) => !option.parents)
63-
.filter((option) => !option.autogenerated)
64-
.map((option) => option.name)
65-
.sort();
57+
return (
58+
options
59+
.filter((option) => !option.globalOnly)
60+
// Only include top-level options, which have no parents (implicit root) or explicitly define the
61+
// root ('.') as their parent.
62+
.filter(
63+
(option) =>
64+
!option.parents ||
65+
option.parents.length === 0 ||
66+
option.parents.includes('.'),
67+
)
68+
.filter((option) => !option.autogenerated)
69+
.map((option) => option.name)
70+
.sort()
71+
);
6672
}
6773

6874
it('has doc headers sorted alphabetically', async () => {
@@ -86,21 +92,25 @@ describe('docs/documentation', () => {
8692
}
8793

8894
function getRequiredConfigSubOptions(): string[] {
89-
return options
90-
.filter((option) => option.stage !== 'global')
91-
.filter((option) => !option.globalOnly)
92-
.filter((option) => option.parents)
93-
.filter(
94-
(option) =>
95-
option.name !== 'managerFilePatterns' &&
96-
option.name !== 'enabled',
97-
)
98-
.flatMap((option) =>
99-
(option.parents ?? [])
100-
.filter((parent) => parent !== '.')
101-
.map((parent) => `${parent}.${option.name}`),
102-
)
103-
.sort();
95+
return (
96+
options
97+
.filter((option) => option.stage !== 'global')
98+
.filter((option) => !option.globalOnly)
99+
// Only include true sub-options: options which have parents but none of those are explicitly the root ('.').
100+
.filter(
101+
(option) =>
102+
option.parents &&
103+
option.parents.length > 0 &&
104+
!option.parents.includes('.'),
105+
)
106+
.filter((option) => option.name !== 'managerFilePatterns')
107+
.flatMap((option) =>
108+
(option.parents ?? [])
109+
.filter((parent) => parent !== '.')
110+
.map((parent) => `${parent}.${option.name}`),
111+
)
112+
.sort()
113+
);
104114
}
105115

106116
function getParentNames(): Set<string> {

0 commit comments

Comments
 (0)