diff --git a/packages/eslint-plugin/docs/rules/no-empty-interface.md b/packages/eslint-plugin/docs/rules/no-empty-interface.md index 194a6e6a654..699ebccb64a 100644 --- a/packages/eslint-plugin/docs/rules/no-empty-interface.md +++ b/packages/eslint-plugin/docs/rules/no-empty-interface.md @@ -48,7 +48,7 @@ interface Baz extends Foo, Bar {} -### Options +## Options This rule accepts a single object option with the following default configuration: diff --git a/packages/eslint-plugin/tests/docs.test.ts b/packages/eslint-plugin/tests/docs.test.ts index 9442ed366a3..e7872a962c9 100644 --- a/packages/eslint-plugin/tests/docs.test.ts +++ b/packages/eslint-plugin/tests/docs.test.ts @@ -26,11 +26,15 @@ function tokenIs( 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) ); } @@ -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); + } + } + }); }); } });