Skip to content

Commit

Permalink
Indicate type of array for array options in rule option lists (#496)
Browse files Browse the repository at this point in the history
  • Loading branch information
bmish committed Oct 31, 2023
1 parent 988e466 commit 7be50d8
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 7 deletions.
9 changes: 8 additions & 1 deletion lib/rule-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,14 @@ export function getAllNamedOptions(
options.push(
...Object.entries(js.properties).map(([key, value]) => ({
name: key,
type: value.type ? value.type.toString() : undefined,
type:
value.type === 'array' &&
!Array.isArray(value.items) &&
value.items?.type
? `${value.items.type.toString()}[]`
: value.type
? value.type.toString()
: undefined,
description: value.description,
default: value.default,
enum: value.enum,
Expand Down
14 changes: 8 additions & 6 deletions test/lib/generate/__snapshots__/rule-options-list-test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ exports[`generate (rule options list) basic generates the documentation 1`] = `
## Options
<!-- begin auto-generated rule options list -->
| Name | Description | Type | Choices | Default | Required | Deprecated |
| :---- | :---------------------------- | :------ | :---------------- | :------- | :------- | :--------- |
| \`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 | | | | |
| \`arr2\` | | 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
9 changes: 9 additions & 0 deletions test/lib/generate/rule-options-list-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ describe('generate (rule options list)', function () {
required: true,
},
biz: {},
arr1: {
type: "array",
},
arr2: {
type: "array",
items: {
type: "string"
}
},
},
required: ["bar"],
additionalProperties: false
Expand Down
12 changes: 12 additions & 0 deletions test/lib/rule-options-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,9 @@ describe('rule options', function () {
additionalProperties: false,
},
},
optionToDoSomething2: {
type: 'array',
},
},
additionalProperties: false,
},
Expand All @@ -252,6 +255,15 @@ describe('rule options', function () {
"enum": undefined,
"name": "optionToDoSomething1",
"required": false,
"type": "object[]",
},
{
"default": undefined,
"deprecated": undefined,
"description": undefined,
"enum": undefined,
"name": "optionToDoSomething2",
"required": false,
"type": "array",
},
{
Expand Down

0 comments on commit 7be50d8

Please sign in to comment.