Skip to content

Commit

Permalink
Show rule option list "Default" column even with only a falsy value (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
bmish authored Oct 13, 2023
1 parent 02bac96 commit 7c07cae
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/rule-options-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ function ruleOptionsToColumnsToDisplay(ruleOptions: readonly RuleOption[]): {
[key in COLUMN_TYPE]: boolean;
} = {
// Alphabetical order.
[COLUMN_TYPE.DEFAULT]: ruleOptions.some((ruleOption) => ruleOption.default),
[COLUMN_TYPE.DEFAULT]: ruleOptions.some(
(ruleOption) => ruleOption.default !== undefined
),
[COLUMN_TYPE.DEPRECATED]: ruleOptions.some(
(ruleOption) => ruleOption.deprecated
),
Expand Down
14 changes: 14 additions & 0 deletions test/lib/generate/__snapshots__/rule-options-list-test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,20 @@ exports[`generate (rule options list) basic generates the documentation 1`] = `
<!-- end auto-generated rule options list -->"
`;

exports[`generate (rule options list) displays default column even when only falsy value, hiding deprecated/required cols with only falsy value generates the documentation 1`] = `
"# test/no-foo
<!-- end auto-generated rule header -->
## Options
<!-- begin auto-generated rule options list -->
| Name | Default |
| :---- | :------ |
| \`foo\` | \`false\` |
<!-- end auto-generated rule options list -->"
`;

exports[`generate (rule options list) with no marker comments generates the documentation 1`] = `
"# test/no-foo
Expand Down
52 changes: 52 additions & 0 deletions test/lib/generate/rule-options-list-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,58 @@ describe('generate (rule options list)', function () {
});
});

describe('displays default column even when only falsy value, hiding deprecated/required cols with only falsy value', function () {
beforeEach(function () {
mockFs({
'package.json': JSON.stringify({
name: 'eslint-plugin-test',
exports: 'index.js',
type: 'module',
}),

'index.js': `
export default {
rules: {
'no-foo': {
meta: {
schema: [{
type: "object",
properties: {
foo: {
default: false,
required: false,
deprecated: false,
},
},
}],
},
create(context) {}
},
},
};`,

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

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

// Needed for some of the test infrastructure to work.
node_modules: mockFs.load(PATH_NODE_MODULES),
});
});

afterEach(function () {
mockFs.restore();
jest.resetModules();
});

it('generates the documentation', async function () {
await generate('.');
expect(readFileSync('docs/rules/no-foo.md', 'utf8')).toMatchSnapshot();
});
});

describe('with no options', function () {
beforeEach(function () {
mockFs({
Expand Down

0 comments on commit 7c07cae

Please sign in to comment.