Skip to content

Commit 310c029

Browse files
authored
Don't exit with failure about missing mention of rule option when rule option list was just generated (#484)
1 parent 7c07cae commit 310c029

File tree

3 files changed

+30
-10
lines changed

3 files changed

+30
-10
lines changed

lib/generator.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -179,24 +179,28 @@ export async function generate(path: string, options?: GenerateOptions) {
179179
urlRuleDoc
180180
);
181181

182-
const contents = readFileSync(pathToDoc).toString();
182+
const contentsOld = readFileSync(pathToDoc).toString();
183183
const contentsNew = await postprocess(
184184
updateRuleOptionsList(
185-
replaceOrCreateHeader(contents, newHeaderLines, END_RULE_HEADER_MARKER),
185+
replaceOrCreateHeader(
186+
contentsOld,
187+
newHeaderLines,
188+
END_RULE_HEADER_MARKER
189+
),
186190
rule
187191
),
188192
resolve(pathToDoc)
189193
);
190194

191195
if (check) {
192-
if (contentsNew !== contents) {
196+
if (contentsNew !== contentsOld) {
193197
console.error(
194198
`Please run eslint-doc-generator. A rule doc is out-of-date: ${relative(
195199
getPluginRoot(path),
196200
pathToDoc
197201
)}`
198202
);
199-
console.error(diff(contentsNew, contents, { expand: false }));
203+
console.error(diff(contentsNew, contentsOld, { expand: false }));
200204
process.exitCode = 1;
201205
}
202206
} else {
@@ -209,7 +213,7 @@ export async function generate(path: string, options?: GenerateOptions) {
209213
for (const section of ruleDocSectionInclude) {
210214
expectSectionHeaderOrFail(
211215
`\`${name}\` rule doc`,
212-
contents,
216+
contentsNew,
213217
[section],
214218
true
215219
);
@@ -219,7 +223,7 @@ export async function generate(path: string, options?: GenerateOptions) {
219223
for (const section of ruleDocSectionExclude) {
220224
expectSectionHeaderOrFail(
221225
`\`${name}\` rule doc`,
222-
contents,
226+
contentsNew,
223227
[section],
224228
false
225229
);
@@ -229,15 +233,15 @@ export async function generate(path: string, options?: GenerateOptions) {
229233
// Options section.
230234
expectSectionHeaderOrFail(
231235
`\`${name}\` rule doc`,
232-
contents,
236+
contentsNew,
233237
['Options', 'Config'],
234238
hasOptions(schema)
235239
);
236240
for (const { name: namedOption } of getAllNamedOptions(schema)) {
237241
expectContentOrFail(
238242
`\`${name}\` rule doc`,
239243
'rule option',
240-
contents,
244+
contentsNew,
241245
namedOption,
242246
true
243247
); // Each rule option is mentioned.

test/lib/generate/__snapshots__/rule-options-list-test.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ exports[`generate (rule options list) with no options generates the documentatio
4343
"# test/no-foo
4444
4545
<!-- end auto-generated rule header -->
46-
## Options
46+
4747
<!-- begin auto-generated rule options list -->
4848
4949

test/lib/generate/rule-options-list-test.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { dirname, resolve } from 'node:path';
44
import { fileURLToPath } from 'node:url';
55
import { readFileSync } from 'node:fs';
66
import { jest } from '@jest/globals';
7+
import * as sinon from 'sinon';
78

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

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

7677
it('generates the documentation', async function () {
78+
const consoleErrorStub = sinon.stub(console, 'error');
7779
await generate('.');
80+
expect(consoleErrorStub.callCount).toBe(0);
81+
consoleErrorStub.restore();
7882
expect(readFileSync('docs/rules/no-foo.md', 'utf8')).toMatchSnapshot();
7983
});
8084
});
@@ -126,7 +130,10 @@ describe('generate (rule options list)', function () {
126130
});
127131

128132
it('generates the documentation', async function () {
133+
const consoleErrorStub = sinon.stub(console, 'error');
129134
await generate('.');
135+
expect(consoleErrorStub.callCount).toBe(0);
136+
consoleErrorStub.restore();
130137
expect(readFileSync('docs/rules/no-foo.md', 'utf8')).toMatchSnapshot();
131138
});
132139
});
@@ -155,7 +162,7 @@ describe('generate (rule options list)', function () {
155162

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

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

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

172179
it('generates the documentation', async function () {
180+
const consoleErrorStub = sinon.stub(console, 'error');
173181
await generate('.');
182+
expect(consoleErrorStub.callCount).toBe(0);
183+
consoleErrorStub.restore();
174184
expect(readFileSync('docs/rules/no-foo.md', 'utf8')).toMatchSnapshot();
175185
});
176186
});
@@ -211,7 +221,10 @@ describe('generate (rule options list)', function () {
211221
});
212222

213223
it('generates the documentation', async function () {
224+
const consoleErrorStub = sinon.stub(console, 'error');
214225
await generate('.');
226+
expect(consoleErrorStub.callCount).toBe(0);
227+
consoleErrorStub.restore();
215228
expect(readFileSync('docs/rules/no-foo.md', 'utf8')).toMatchSnapshot();
216229
});
217230
});
@@ -255,7 +268,10 @@ describe('generate (rule options list)', function () {
255268
});
256269

257270
it('generates the documentation', async function () {
271+
const consoleErrorStub = sinon.stub(console, 'error');
258272
await generate('.');
273+
expect(consoleErrorStub.callCount).toBe(0);
274+
consoleErrorStub.restore();
259275
expect(readFileSync('docs/rules/no-foo.md', 'utf8')).toMatchSnapshot();
260276
});
261277
});

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy