Skip to content

Show rule option list "Default" column even with only a falsy value #483

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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