Skip to content

Commit

Permalink
Add test that ensures each rule doc has Pass / Fail code sample s…
Browse files Browse the repository at this point in the history
…ections (#1610)
  • Loading branch information
bmish committed Nov 15, 2021
1 parent df4295b commit 426f01a
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions test/package.mjs
Expand Up @@ -66,6 +66,10 @@ const MESSAGES = {
hasSuggestions: '💡 *This rule provides [suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).*',
};

const RULES_WITHOUT_PASS_FAIL_SECTIONS = new Set([
'filename-case', // Doesn't show code samples since it's just focused on filenames.
]);

test('Every rule is defined in index file in alphabetical order', t => {
for (const file of ruleFiles) {
const name = path.basename(file, '.js');
Expand Down Expand Up @@ -195,6 +199,12 @@ test('Every rule has a doc with the appropriate content', t => {
const expectedTitle = `# ${ruleDescriptionToDocumentTitle(rule.meta.docs.description)}`;
t.is(documentLines[0], expectedTitle, `${ruleName} includes the rule description in title`);

// Check for examples.
if (!RULES_WITHOUT_PASS_FAIL_SECTIONS.has(ruleName)) {
t.true(documentContents.includes('## Pass'), `${ruleName} includes '## Pass' examples section`);
t.true(documentContents.includes('## Fail'), `${ruleName} includes '## Fail' examples section`);
}

// Check if the rule has configuration options.
if (
(Array.isArray(rule.meta.schema) && rule.meta.schema.length > 0)
Expand Down

0 comments on commit 426f01a

Please sign in to comment.