Skip to content

Commit

Permalink
fix: don't exit with failure about missing rule option when rule opti…
Browse files Browse the repository at this point in the history
…on list was just generated
  • Loading branch information
bmish committed Oct 13, 2023
1 parent 7c07cae commit 9e11c72
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
8 changes: 4 additions & 4 deletions lib/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ export async function generate(path: string, options?: GenerateOptions) {
for (const section of ruleDocSectionInclude) {
expectSectionHeaderOrFail(
`\`${name}\` rule doc`,
contents,
contentsNew,
[section],
true
);
Expand All @@ -219,7 +219,7 @@ export async function generate(path: string, options?: GenerateOptions) {
for (const section of ruleDocSectionExclude) {
expectSectionHeaderOrFail(
`\`${name}\` rule doc`,
contents,
contentsNew,
[section],
false
);
Expand All @@ -229,15 +229,15 @@ export async function generate(path: string, options?: GenerateOptions) {
// Options section.
expectSectionHeaderOrFail(
`\`${name}\` rule doc`,
contents,
contentsNew,
['Options', 'Config'],
hasOptions(schema)
);
for (const { name: namedOption } of getAllNamedOptions(schema)) {
expectContentOrFail(
`\`${name}\` rule doc`,
'rule option',
contents,
contentsNew,
namedOption,
true
); // Each rule option is mentioned.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ exports[`generate (rule options list) with no options generates the documentatio
"# test/no-foo
<!-- end auto-generated rule header -->
## Options
<!-- begin auto-generated rule options list -->
Expand Down
18 changes: 17 additions & 1 deletion test/lib/generate/rule-options-list-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { dirname, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
import { readFileSync } from 'node:fs';
import { jest } from '@jest/globals';
import * as sinon from 'sinon';

const __dirname = dirname(fileURLToPath(import.meta.url));

Expand Down Expand Up @@ -74,7 +75,10 @@ describe('generate (rule options list)', function () {
});

it('generates the documentation', async function () {
const consoleErrorStub = sinon.stub(console, 'error');
await generate('.');
expect(consoleErrorStub.callCount).toBe(0);
consoleErrorStub.restore();
expect(readFileSync('docs/rules/no-foo.md', 'utf8')).toMatchSnapshot();
});
});
Expand Down Expand Up @@ -126,7 +130,10 @@ describe('generate (rule options list)', function () {
});

it('generates the documentation', async function () {
const consoleErrorStub = sinon.stub(console, 'error');
await generate('.');
expect(consoleErrorStub.callCount).toBe(0);
consoleErrorStub.restore();
expect(readFileSync('docs/rules/no-foo.md', 'utf8')).toMatchSnapshot();
});
});
Expand Down Expand Up @@ -155,7 +162,7 @@ describe('generate (rule options list)', function () {

'README.md': '## Rules\n',

'docs/rules/no-foo.md': `## Options
'docs/rules/no-foo.md': `
<!-- begin auto-generated rule options list -->
<!-- end auto-generated rule options list -->`,

Expand All @@ -170,7 +177,10 @@ describe('generate (rule options list)', function () {
});

it('generates the documentation', async function () {
const consoleErrorStub = sinon.stub(console, 'error');
await generate('.');
expect(consoleErrorStub.callCount).toBe(0);
consoleErrorStub.restore();
expect(readFileSync('docs/rules/no-foo.md', 'utf8')).toMatchSnapshot();
});
});
Expand Down Expand Up @@ -211,7 +221,10 @@ describe('generate (rule options list)', function () {
});

it('generates the documentation', async function () {
const consoleErrorStub = sinon.stub(console, 'error');
await generate('.');
expect(consoleErrorStub.callCount).toBe(0);
consoleErrorStub.restore();
expect(readFileSync('docs/rules/no-foo.md', 'utf8')).toMatchSnapshot();
});
});
Expand Down Expand Up @@ -255,7 +268,10 @@ describe('generate (rule options list)', function () {
});

it('generates the documentation', async function () {
const consoleErrorStub = sinon.stub(console, 'error');
await generate('.');
expect(consoleErrorStub.callCount).toBe(0);
consoleErrorStub.restore();
expect(readFileSync('docs/rules/no-foo.md', 'utf8')).toMatchSnapshot();
});
});
Expand Down

0 comments on commit 9e11c72

Please sign in to comment.