Skip to content

Commit 877e751

Browse files
authored
Merge pull request #104 from bmish/desc-title-format
2 parents f1b48c3 + 55ba1c3 commit 877e751

File tree

5 files changed

+57
-7
lines changed

5 files changed

+57
-7
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ If you have any custom configs (besides `all`, `recommended`), you'll need to de
124124
| `--ignore-deprecated-rules` | (optional) Whether to ignore deprecated rules from being checked, displayed, or updated (default: `false`). |
125125
| `--rule-doc-section-include` | (optional) Required section in each rule doc (option can be repeated). |
126126
| `--rule-doc-section-exclude` | (optional) Disallowed section in each rule doc (option can be repeated). |
127-
| `--rule-doc-title-format` | (optional) The format to use for rule doc titles. Choices: `desc-parens-prefix-name` (default), `desc-parens-name`, `prefix-name`, `name`. |
127+
| `--rule-doc-title-format` | (optional) The format to use for rule doc titles. Choices: `desc-parens-prefix-name` (default), `desc`, `desc-parens-name`, `name`, `prefix-name`. |
128128
| `--url-configs` | (optional) Link to documentation about the ESLint configurations exported by the plugin. |
129129

130130
## Upcoming features

lib/rule-doc-title-format.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
export const RULE_DOC_TITLE_FORMATS = [
2-
'desc-parens-prefix-name',
2+
'desc',
33
'desc-parens-name',
4-
'prefix-name',
4+
'desc-parens-prefix-name',
55
'name',
6+
'prefix-name',
67
] as const;
78

89
export type RuleDocTitleFormat = typeof RULE_DOC_TITLE_FORMATS[number];

lib/rule-notices.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -164,14 +164,16 @@ function makeTitle(
164164
}
165165

166166
switch (ruleDocTitleFormatWithFallback) {
167-
case 'desc-parens-prefix-name':
168-
return `# ${descriptionFormatted} (\`${pluginPrefix}/${name}\`)`;
167+
case 'desc':
168+
return `# ${descriptionFormatted}`;
169169
case 'desc-parens-name':
170170
return `# ${descriptionFormatted} (\`${name}\`)`;
171-
case 'prefix-name':
172-
return `# \`${pluginPrefix}/${name}\``;
171+
case 'desc-parens-prefix-name':
172+
return `# ${descriptionFormatted} (\`${pluginPrefix}/${name}\`)`;
173173
case 'name':
174174
return `# \`${name}\``;
175+
case 'prefix-name':
176+
return `# \`${pluginPrefix}/${name}\``;
175177
/* istanbul ignore next -- this shouldn't happen */
176178
default:
177179
throw new Error(

test/lib/__snapshots__/generator-test.ts.snap

+7
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,13 @@ details
548548
Long line that SHOULD NOT get wrapped by prettier since it's outside the header. Long line that SHOULD NOT get wrapped by prettier since it's outside the header."
549549
`;
550550

551+
exports[`generator #generate with \`--rule-doc-title-format\` option = desc uses the right rule doc title format 1`] = `
552+
"# Description for no-foo
553+
554+
<!-- end rule header -->
555+
"
556+
`;
557+
551558
exports[`generator #generate with \`--rule-doc-title-format\` option = desc-parens-name uses the right rule doc title format 1`] = `
552559
"# Description for no-foo (\`no-foo\`)
553560

test/lib/generator-test.ts

+40
Original file line numberDiff line numberDiff line change
@@ -1992,6 +1992,46 @@ describe('generator', function () {
19921992
});
19931993
});
19941994

1995+
describe('with `--rule-doc-title-format` option = desc', function () {
1996+
beforeEach(function () {
1997+
mockFs({
1998+
'package.json': JSON.stringify({
1999+
name: 'eslint-plugin-test',
2000+
main: 'index.js',
2001+
type: 'module',
2002+
}),
2003+
2004+
'index.js': `
2005+
export default {
2006+
rules: {
2007+
'no-foo': { meta: { docs: { description: 'Description for no-foo.'} }, create(context) {} },
2008+
},
2009+
};`,
2010+
2011+
'README.md': '## Rules\n',
2012+
2013+
'docs/rules/no-foo.md': '',
2014+
2015+
// Needed for some of the test infrastructure to work.
2016+
node_modules: mockFs.load(
2017+
resolve(__dirname, '..', '..', 'node_modules')
2018+
),
2019+
});
2020+
});
2021+
2022+
afterEach(function () {
2023+
mockFs.restore();
2024+
jest.resetModules();
2025+
});
2026+
2027+
it('uses the right rule doc title format', async function () {
2028+
await generate('.', {
2029+
ruleDocTitleFormat: 'desc',
2030+
});
2031+
expect(readFileSync('docs/rules/no-foo.md', 'utf8')).toMatchSnapshot();
2032+
});
2033+
});
2034+
19952035
describe('with `--rule-doc-title-format` option = prefix-name', function () {
19962036
beforeEach(function () {
19972037
mockFs({

0 commit comments

Comments
 (0)