Skip to content

Commit

Permalink
fix: better display of rule array option defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
bmish committed Nov 16, 2023
1 parent 7cbab78 commit 55d415d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
6 changes: 6 additions & 0 deletions lib/rule-options-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ function ruleOptionToColumnValues(ruleOption: RuleOption): {
[COLUMN_TYPE.DEFAULT]:
ruleOption.default === undefined
? undefined
: Array.isArray(ruleOption.default)
? `${ruleOption.default.length === 0 ? '`' : ''}[${
ruleOption.default.length > 0 ? '`' : ''
}${ruleOption.default.join('`, `')}${
ruleOption.default.length > 0 ? '`' : ''
}]${ruleOption.default.length === 0 ? '`' : ''}`
: `\`${String(ruleOption.default)}\``,
[COLUMN_TYPE.DEPRECATED]: ruleOption.deprecated ? 'Yes' : undefined,
[COLUMN_TYPE.DESCRIPTION]: ruleOption.description,
Expand Down
24 changes: 13 additions & 11 deletions test/lib/generate/__snapshots__/rule-options-list-test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@ exports[`generate (rule options list) basic generates the documentation 1`] = `
## Options
<!-- begin auto-generated rule options list -->
| Name | Description | Type | Choices | Default | Required | Deprecated |
| :------------------------- | :---------------------------- | :------------------ | :---------------- | :------- | :------- | :--------- |
| \`arr1\` | | Array | | | | |
| \`arrWithArrType\` | | String, Boolean | | | | |
| \`arrWithArrTypeSingleItem\` | | String | | | | |
| \`arrWithItemsArrayType\` | | (String, Boolean)[] | | | | |
| \`arrWithItemsType\` | | String[] | | | | |
| \`bar\` | Choose how to use the rule. | String | \`always\`, \`never\` | \`always\` | Yes | |
| \`baz\` | | | | \`true\` | Yes | |
| \`biz\` | | | | | | |
| \`foo\` | Enable some kind of behavior. | Boolean | | \`false\` | | Yes |
| Name | Description | Type | Choices | Default | Required | Deprecated |
| :------------------------- | :---------------------------- | :------------------ | :---------------- | :------------------------------------- | :------- | :--------- |
| \`arr1\` | | Array | | | | |
| \`arrWithArrType\` | | String, Boolean | | | | |
| \`arrWithArrTypeSingleItem\` | | String | | | | |
| \`arrWithDefault\` | | Array | | [\`hello world\`, \`1\`, \`2\`, \`3\`, \`true\`] | | |
| \`arrWithDefaultEmpty\` | | Array | | \`[]\` | | |
| \`arrWithItemsArrayType\` | | (String, Boolean)[] | | | | |
| \`arrWithItemsType\` | | String[] | | | | |
| \`bar\` | Choose how to use the rule. | String | \`always\`, \`never\` | \`always\` | Yes | |
| \`baz\` | | | | \`true\` | Yes | |
| \`biz\` | | | | | | |
| \`foo\` | Enable some kind of behavior. | Boolean | | \`false\` | | Yes |
<!-- end auto-generated rule options list -->"
`;
Expand Down
8 changes: 8 additions & 0 deletions test/lib/generate/rule-options-list-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ describe('generate (rule options list)', function () {
type: ["string", "boolean"]
}
},
arrWithDefaultEmpty: {
type: "array",
default: [],
},
arrWithDefault: {
type: "array",
default: ['hello world', 1, 2, 3, true],
},
},
required: ["bar"],
additionalProperties: false
Expand Down

0 comments on commit 55d415d

Please sign in to comment.