Skip to content

Commit e625531

Browse files
authored
Add JSDocs for exported GenerateOptions type (#299)
1 parent 17afec4 commit e625531

File tree

3 files changed

+54
-8
lines changed

3 files changed

+54
-8
lines changed

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -120,17 +120,17 @@ There's also an optional path argument if you need to point the CLI to an ESLint
120120

121121
| Name | Description |
122122
| :-- | :-- |
123-
| `--check` | Whether to check for and fail if there is a diff. No output will be written. Typically used during CI. |
123+
| `--check` | Whether to check for and fail if there is a diff. No output will be written. Typically used during CI. Default: `false`. |
124124
| `--config-emoji` | Custom emoji to use for a config. Format is `config-name,emoji`. Default emojis are provided for [common configs](./lib/emojis.ts). To remove a default emoji and rely on a [badge](#badge) instead, provide the config name without an emoji. Option can be repeated. |
125125
| `--ignore-config` | Config to ignore from being displayed. Often used for an `all` config. Option can be repeated. |
126-
| `--ignore-deprecated-rules` | Whether to ignore deprecated rules from being checked, displayed, or updated (default: `false`). |
127-
| `--init-rule-docs` | Whether to create rule doc files if they don't yet exist (default: `false`). |
128-
| `--path-rule-doc` | Path to markdown file for each rule doc. Use `{name}` placeholder for the rule name (default: `docs/rules/{name}.md`). |
126+
| `--ignore-deprecated-rules` | Whether to ignore deprecated rules from being checked, displayed, or updated. Default: `false`. |
127+
| `--init-rule-docs` | Whether to create rule doc files if they don't yet exist. Default: `false`. |
128+
| `--path-rule-doc` | Path to markdown file for each rule doc. Use `{name}` placeholder for the rule name. Default: `docs/rules/{name}.md`. |
129129
| `--path-rule-list` | Path to markdown file where the rules table list should live. Default: `README.md`. Option can be repeated. |
130130
| `--rule-doc-notices` | Ordered, comma-separated list of notices to display in rule doc. Non-applicable notices will be hidden. Choices: `configs`, `deprecated`, `fixable` (off by default), `fixableAndHasSuggestions`, `hasSuggestions` (off by default), `options` (off by default), `requiresTypeChecking`, `type` (off by default). Default: `deprecated,configs,fixableAndHasSuggestions,requiresTypeChecking`. |
131131
| `--rule-doc-section-exclude` | Disallowed section in each rule doc. Exit with failure if present. Option can be repeated. |
132132
| `--rule-doc-section-include` | Required section in each rule doc. Exit with failure if missing. Option can be repeated. |
133-
| `--rule-doc-section-options` | Whether to require an "Options" or "Config" rule doc section and mention of any named options for rules with options (default: `true`). |
133+
| `--rule-doc-section-options` | Whether to require an "Options" or "Config" rule doc section and mention of any named options for rules with options. Default: `true`. |
134134
| `--rule-doc-title-format` | The format to use for rule doc titles. Defaults to `desc-parens-prefix-name`. See choices in below [table](#--rule-doc-title-format). |
135135
| `--rule-list-columns` | Ordered, comma-separated list of columns to display in rule list. Empty columns will be hidden. Choices: `configsError`, `configsOff`, `configsWarn`, `deprecated`, `description`, `fixable`, `fixableAndHasSuggestions` (off by default), `hasSuggestions`, `name`, `options` (off by default), `requiresTypeChecking`, `type` (off by default). Default: `name,description,configsError,configsWarn,configsOff,fixable,hasSuggestions,requiresTypeChecking,deprecated`. |
136136
| `--split-by` | Rule property to split the rules list by. A separate list and header will be created for each value. Example: `meta.type`. |
@@ -156,9 +156,9 @@ There are a few ways to create a config file:
156156
- An object exported by `.eslint-doc-generatorrc.js`, `.eslint-doc-generatorrc.json`, or any other config file format/name supported by [cosmiconfig](https://github.com/davidtheclark/cosmiconfig#searchplaces)
157157
- An object under the `eslint-doc-generator` key in `package.json`
158158

159-
Config files support all the [CLI options](#configuration-options) but in camelCase. CLI options take precedence over config file options.
159+
Config files support all the [CLI options](#configuration-options) but in camelCase.
160160

161-
Using a JavaScript-based config also allows you to provide a `postprocess` function which gets called with the generated content and path to each file as they're processed, to make it easy to apply any custom transformations such as formatting - this is useful if you are using formatting tools such as [`prettier`](#prettier).
161+
Using a JavaScript-based config file also allows you to provide a `postprocess` function to be called with the generated content and file path for each processed file. Useful for applying custom transformations such as formatting with tools like [`prettier`](#prettier).
162162

163163
Example `.eslint-doc-generatorrc.js`:
164164

lib/cli.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ export async function run(
100100
) {
101101
const program = new Command();
102102

103+
// Documentation for options should be kept in sync with README.md and the JSDocs for the `GenerateOptions` type.
103104
await program
104105
.version(getCurrentPackageVersion())
105106
.addArgument(

lib/types.ts

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,26 +103,71 @@ export enum OPTION_TYPE {
103103
POSTPROCESS = 'postprocess',
104104
}
105105

106-
/** The type for the config file and internal generate() function. */
106+
// JSDocs for options should be kept in sync with README.md and the CLI runner in cli.ts.
107+
108+
/** The type for the config file (e.g. `.eslint-doc-generatorrc.js`) and internal `generate()` function. */
107109
export type GenerateOptions = {
110+
/** Whether to check for and fail if there is a diff. No output will be written. Typically used during CI. Default: `false`. */
108111
check?: boolean;
112+
/**
113+
* List of configs and their associated emojis.
114+
* Format is `config-name,emoji`.
115+
* Default emojis are provided for common configs.
116+
* To remove a default emoji and rely on a badge instead, provide the config name without an emoji.
117+
*/
109118
configEmoji?: string[];
119+
/** Configs to ignore from being displayed. Often used for an `all` config. */
110120
ignoreConfig?: string[];
121+
/** Whether to ignore deprecated rules from being checked, displayed, or updated. Default: `false`. */
111122
ignoreDeprecatedRules?: boolean;
123+
/** Whether to create rule doc files if they don't yet exist. Default: `false`. */
112124
initRuleDocs?: boolean;
125+
/** Path to markdown file for each rule doc. Use `{name}` placeholder for the rule name. Default: `docs/rules/{name}.md`. */
113126
pathRuleDoc?: string;
127+
/** Path to markdown file(s) where the rules table list should live. Default: `README.md`. */
114128
pathRuleList?: string | string[];
129+
/**
130+
* Function to be called with the generated content and file path for each processed file.
131+
* Useful for applying custom transformations such as formatting with tools like prettier.
132+
*/
115133
postprocess?: (
116134
content: string,
117135
pathToFile: string
118136
) => string | Promise<string>;
137+
/**
138+
* Ordered, comma-separated list of notices to display in rule doc.
139+
* Non-applicable notices will be hidden.
140+
* Choices: `configs`, `deprecated`, `fixable` (off by default), `fixableAndHasSuggestions`, `hasSuggestions` (off by default), `options` (off by default), `requiresTypeChecking`, `type` (off by default).
141+
* Default: `deprecated,configs,fixableAndHasSuggestions,requiresTypeChecking`.
142+
*/
119143
ruleDocNotices?: string;
144+
/** Disallowed sections in each rule doc. Exit with failure if present. */
120145
ruleDocSectionExclude?: string[];
146+
/** Required sections in each rule doc. Exit with failure if missing. */
121147
ruleDocSectionInclude?: string[];
148+
/** Whether to require an "Options" or "Config" rule doc section and mention of any named options for rules with options. Default: `true`. */
122149
ruleDocSectionOptions?: boolean;
150+
/** The format to use for rule doc titles. Default: `desc-parens-prefix-name`. */
123151
ruleDocTitleFormat?: RuleDocTitleFormat;
152+
/**
153+
* Ordered, comma-separated list of columns to display in rule list.
154+
* Empty columns will be hidden.
155+
* Choices: `configsError`, `configsOff`, `configsWarn`, `deprecated`, `description`, `fixable`, `fixableAndHasSuggestions` (off by default), `hasSuggestions`, `name`, `options` (off by default), `requiresTypeChecking`, `type` (off by default).
156+
* Default: `name,description,configsError,configsWarn,configsOff,fixable,hasSuggestions,requiresTypeChecking,deprecated`.
157+
*/
124158
ruleListColumns?: string;
159+
/**
160+
* Rule property to split the rules list by.
161+
* A separate list and header will be created for each value.
162+
* Example: `meta.type`.
163+
*/
125164
splitBy?: string;
165+
/** Link to documentation about the ESLint configurations exported by the plugin. */
126166
urlConfigs?: string;
167+
/**
168+
* Link to documentation for each rule.
169+
* Useful when it differs from the rule doc path on disk (e.g. custom documentation site in use).
170+
* Use `{name}` placeholder for the rule name.
171+
*/
127172
urlRuleDoc?: string;
128173
};

0 commit comments

Comments
 (0)