Skip to content

chore(website): fix Options heading level for no-empty-interface docs #5870

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/eslint-plugin/docs/rules/no-empty-interface.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ interface Baz extends Foo, Bar {}

<!--/tabs-->

### Options
## Options

This rule accepts a single object option with the following default configuration:

Expand Down
29 changes: 25 additions & 4 deletions packages/eslint-plugin/tests/docs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,15 @@ function tokenIs<Type extends TokenType>(
return token.type === type;
}

function tokenIsH2(token: marked.Token): token is marked.Tokens.Heading {
function tokenIsHeading(token: marked.Token): token is marked.Tokens.Heading {
return tokenIs(token, 'heading');
}

function tokenIsH2(
token: marked.Token,
): token is marked.Tokens.Heading & { depth: 2 } {
return (
tokenIs(token, 'heading') &&
token.depth === 2 &&
!/[a-z]+: /.test(token.text)
tokenIsHeading(token) && token.depth === 2 && !/[a-z]+: /.test(token.text)
);
}

Expand Down Expand Up @@ -93,6 +97,23 @@ describe('Validating rule docs', () => {
expect(header.text).toBe(titleCase(header.text)),
);
});

const importantHeadings = new Set([
'How to Use',
'Options',
'Related To',
'When Not To Use It',
]);

test('important headings must be h2s', () => {
const headers = tokens.filter(tokenIsHeading);

for (const header of headers) {
if (importantHeadings.has(header.raw.replace(/#/g, '').trim())) {
expect(header.depth).toBe(2);
}
}
});
});
}
});
Expand Down