eslint-doc-generator
Advanced tools
Comparing version 0.28.0 to 0.28.1
@@ -9,2 +9,2 @@ import { Command } from 'commander'; | ||
*/ | ||
export declare function run(argv: string[], cb: (path: string, options: GenerateOptions) => Promise<void>): Promise<Command>; | ||
export declare function run(argv: readonly string[], cb: (path: string, options: GenerateOptions) => Promise<void>): Promise<Command>; |
@@ -103,6 +103,11 @@ import { Command, Argument, Option } from 'commander'; | ||
} | ||
if (explorerResults.config.postprocess && | ||
typeof explorerResults.config.postprocess !== 'function') { | ||
const config = explorerResults.config; | ||
// Additional validation that couldn't be handled by ajv. | ||
if (config.postprocess && typeof config.postprocess !== 'function') { | ||
throw new Error('postprocess must be a function'); | ||
} | ||
// Perform any normalization. | ||
if (typeof config.pathRuleList === 'string') { | ||
config.pathRuleList = [config.pathRuleList]; | ||
} | ||
return explorerResults.config; | ||
@@ -146,6 +151,2 @@ } | ||
const configFileOptions = await loadConfigFileOptions(); | ||
// Perform any normalization needed ahead of merging. | ||
if (typeof configFileOptions.pathRuleList === 'string') { | ||
configFileOptions.pathRuleList = [configFileOptions.pathRuleList]; | ||
} | ||
const generateOptions = merge(configFileOptions, options); // Recursive merge. | ||
@@ -152,0 +153,0 @@ // Invoke callback. |
@@ -111,3 +111,4 @@ import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'; | ||
// Filter out deprecated rules from being checked, displayed, or updated if the option is set. | ||
(details) => !ignoreDeprecatedRules || !details.deprecated); | ||
(details) => !ignoreDeprecatedRules || !details.deprecated) | ||
.sort(({ name: a }, { name: b }) => a.toLowerCase().localeCompare(b.toLowerCase())); | ||
// Update rule doc for each rule. | ||
@@ -114,0 +115,0 @@ let initializedRuleDoc = false; |
@@ -6,10 +6,10 @@ import { COLUMN_TYPE, NOTICE_TYPE } from './types.js'; | ||
*/ | ||
export declare function parseConfigEmojiOptions(plugin: Plugin, configEmoji?: string[][]): ConfigEmojis; | ||
export declare function parseConfigEmojiOptions(plugin: Plugin, configEmoji?: readonly string[][]): ConfigEmojis; | ||
/** | ||
* Parse the option, check for errors, and set defaults. | ||
*/ | ||
export declare function parseRuleListColumnsOption(ruleListColumns: string[] | undefined): COLUMN_TYPE[]; | ||
export declare function parseRuleListColumnsOption(ruleListColumns: readonly string[] | undefined): readonly COLUMN_TYPE[]; | ||
/** | ||
* Parse the option, check for errors, and set defaults. | ||
*/ | ||
export declare function parseRuleDocNoticesOption(ruleDocNotices: string[] | undefined): NOTICE_TYPE[]; | ||
export declare function parseRuleDocNoticesOption(ruleDocNotices: readonly string[] | undefined): readonly NOTICE_TYPE[]; |
@@ -51,3 +51,3 @@ import { COLUMN_TYPE_DEFAULT_PRESENCE_AND_ORDERING, NOTICE_TYPE_DEFAULT_PRESENCE_AND_ORDERING, } from './options.js'; | ||
export function parseRuleListColumnsOption(ruleListColumns) { | ||
const values = ruleListColumns ?? []; | ||
const values = [...(ruleListColumns ?? [])]; | ||
const VALUES_OF_TYPE = new Set(Object.values(COLUMN_TYPE).map(String)); | ||
@@ -74,3 +74,3 @@ // Check for invalid. | ||
export function parseRuleDocNoticesOption(ruleDocNotices) { | ||
const values = ruleDocNotices ?? []; | ||
const values = [...(ruleDocNotices ?? [])]; | ||
const VALUES_OF_TYPE = new Set(Object.values(NOTICE_TYPE).map(String)); | ||
@@ -77,0 +77,0 @@ // Check for invalid. |
@@ -37,9 +37,3 @@ import { join, resolve, basename, dirname, isAbsolute } from 'node:path'; | ||
// https://nodejs.org/api/packages.html#conditional-exports | ||
const propertiesToCheck = [ | ||
'.', | ||
'node', | ||
'import', | ||
'require', | ||
'default', | ||
]; | ||
const propertiesToCheck = ['.', 'node', 'import', 'require', 'default']; | ||
for (const prop of propertiesToCheck) { | ||
@@ -46,0 +40,0 @@ // @ts-expect-error -- The union type for the object is causing trouble. |
import type { Plugin, ConfigsToRules, ConfigEmojis, SEVERITY_TYPE } from './types.js'; | ||
export declare function getConfigsThatSetARule(plugin: Plugin, configsToRules: ConfigsToRules, pluginPrefix: string, ignoreConfig: string[], severityType?: SEVERITY_TYPE): string[]; | ||
export declare function getConfigsThatSetARule(plugin: Plugin, configsToRules: ConfigsToRules, pluginPrefix: string, ignoreConfig: readonly string[], severityType?: SEVERITY_TYPE): string[]; | ||
/** | ||
@@ -4,0 +4,0 @@ * Get config names that a given rule belongs to. |
@@ -7,2 +7,2 @@ import { Plugin, ConfigsToRules, ConfigEmojis, NOTICE_TYPE } from './types.js'; | ||
*/ | ||
export declare function generateRuleHeaderLines(description: string | undefined, name: string, plugin: Plugin, configsToRules: ConfigsToRules, pluginPrefix: string, pathPlugin: string, pathRuleDoc: string, configEmojis: ConfigEmojis, ignoreConfig: string[], ruleDocNotices: NOTICE_TYPE[], ruleDocTitleFormat: RuleDocTitleFormat, urlConfigs?: string, urlRuleDoc?: string): string; | ||
export declare function generateRuleHeaderLines(description: string | undefined, name: string, plugin: Plugin, configsToRules: ConfigsToRules, pluginPrefix: string, pathPlugin: string, pathRuleDoc: string, configEmojis: ConfigEmojis, ignoreConfig: readonly string[], ruleDocNotices: readonly NOTICE_TYPE[], ruleDocTitleFormat: RuleDocTitleFormat, urlConfigs?: string, urlRuleDoc?: string): string; |
@@ -8,3 +8,3 @@ import { COLUMN_TYPE } from './types.js'; | ||
[key in COLUMN_TYPE]: string | ((data: { | ||
details: RuleDetails[]; | ||
details: readonly RuleDetails[]; | ||
}) => string); | ||
@@ -16,2 +16,2 @@ }; | ||
*/ | ||
export declare function getColumns(plugin: Plugin, details: RuleDetails[], configsToRules: ConfigsToRules, ruleListColumns: COLUMN_TYPE[], pluginPrefix: string, ignoreConfig: string[]): Record<COLUMN_TYPE, boolean>; | ||
export declare function getColumns(plugin: Plugin, details: readonly RuleDetails[], configsToRules: ConfigsToRules, ruleListColumns: readonly COLUMN_TYPE[], pluginPrefix: string, ignoreConfig: readonly string[]): Record<COLUMN_TYPE, boolean>; |
@@ -5,2 +5,2 @@ import { COLUMN_TYPE, ConfigEmojis, Plugin, ConfigsToRules, SEVERITY_TYPE } from './types.js'; | ||
}; | ||
export declare function generateLegend(columns: Record<COLUMN_TYPE, boolean>, plugin: Plugin, configsToRules: ConfigsToRules, configEmojis: ConfigEmojis, pluginPrefix: string, ignoreConfig: string[], urlConfigs?: string): string; | ||
export declare function generateLegend(columns: Record<COLUMN_TYPE, boolean>, plugin: Plugin, configsToRules: ConfigsToRules, configEmojis: ConfigEmojis, pluginPrefix: string, ignoreConfig: readonly string[], urlConfigs?: string): string; |
import { COLUMN_TYPE } from './types.js'; | ||
import type { Plugin, RuleDetails, ConfigsToRules, ConfigEmojis } from './types.js'; | ||
export declare function updateRulesList(details: RuleDetails[], markdown: string, plugin: Plugin, configsToRules: ConfigsToRules, pluginPrefix: string, pathRuleDoc: string, pathRuleList: string, pathPlugin: string, configEmojis: ConfigEmojis, ignoreConfig: string[], ruleListColumns: COLUMN_TYPE[], ruleListSplit?: string, urlConfigs?: string, urlRuleDoc?: string): string; | ||
export declare function updateRulesList(details: readonly RuleDetails[], markdown: string, plugin: Plugin, configsToRules: ConfigsToRules, pluginPrefix: string, pathRuleDoc: string, pathRuleList: string, pathPlugin: string, configEmojis: ConfigEmojis, ignoreConfig: readonly string[], ruleListColumns: readonly COLUMN_TYPE[], ruleListSplit?: string, urlConfigs?: string, urlRuleDoc?: string): string; |
@@ -86,5 +86,5 @@ import { BEGIN_RULE_LIST_MARKER, END_RULE_LIST_MARKER, } from './comment-markers.js'; | ||
listHeaderRow, | ||
...details | ||
.sort(({ name: a }, { name: b }) => a.toLowerCase().localeCompare(b.toLowerCase())) | ||
.map((rule) => buildRuleRow(columns, rule, configsToRules, pluginPrefix, pathPlugin, pathRuleDoc, pathRuleList, configEmojis, ignoreConfig, urlRuleDoc)), | ||
...details.map((rule) => [ | ||
...buildRuleRow(columns, rule, configsToRules, pluginPrefix, pathPlugin, pathRuleDoc, pathRuleList, configEmojis, ignoreConfig, urlRuleDoc), | ||
]), | ||
], { align: 'l' } // Left-align headers. | ||
@@ -91,0 +91,0 @@ ); |
@@ -7,3 +7,3 @@ import type { JSONSchema } from '@typescript-eslint/utils'; | ||
*/ | ||
export declare function getAllNamedOptions(jsonSchema: JSONSchema.JSONSchema4): string[]; | ||
export declare function getAllNamedOptions(jsonSchema: JSONSchema.JSONSchema4): readonly string[]; | ||
/** | ||
@@ -10,0 +10,0 @@ * Check if a rule schema is non-blank/empty and thus has actual options. |
import type { RuleDocTitleFormat } from './rule-doc-title-format.js'; | ||
import type { TSESLint, JSONSchema } from '@typescript-eslint/utils'; | ||
export type RuleModule = TSESLint.RuleModule<string, unknown[]>; | ||
export type RuleModule = TSESLint.RuleModule<string, readonly unknown[]>; | ||
export type Rules = TSESLint.Linter.RulesRecord; | ||
@@ -33,3 +33,3 @@ export type RuleSeverity = TSESLint.Linter.RuleLevel; | ||
*/ | ||
export type ConfigEmojis = { | ||
export type ConfigEmojis = readonly { | ||
config: string; | ||
@@ -90,3 +90,3 @@ emoji: string; | ||
/** Whether to check for and fail if there is a diff. No output will be written. Typically used during CI. Default: `false`. */ | ||
check?: boolean; | ||
readonly check?: boolean; | ||
/** | ||
@@ -98,13 +98,13 @@ * List of configs and their associated emojis. | ||
*/ | ||
configEmoji?: string[][]; | ||
readonly configEmoji?: readonly string[][]; | ||
/** Configs to ignore from being displayed. Often used for an `all` config. */ | ||
ignoreConfig?: string[]; | ||
readonly ignoreConfig?: readonly string[]; | ||
/** Whether to ignore deprecated rules from being checked, displayed, or updated. Default: `false`. */ | ||
ignoreDeprecatedRules?: boolean; | ||
readonly ignoreDeprecatedRules?: boolean; | ||
/** Whether to create rule doc files if they don't yet exist. Default: `false`. */ | ||
initRuleDocs?: boolean; | ||
readonly initRuleDocs?: boolean; | ||
/** Path to markdown file for each rule doc. Use `{name}` placeholder for the rule name. Default: `docs/rules/{name}.md`. */ | ||
pathRuleDoc?: string; | ||
readonly pathRuleDoc?: string; | ||
/** Path to markdown file(s) where the rules table list should live. Default: `README.md`. */ | ||
pathRuleList?: string | string[]; | ||
readonly pathRuleList?: string | readonly string[]; | ||
/** | ||
@@ -114,3 +114,3 @@ * Function to be called with the generated content and file path for each processed file. | ||
*/ | ||
postprocess?: (content: string, pathToFile: string) => string | Promise<string>; | ||
readonly postprocess?: (content: string, pathToFile: string) => string | Promise<string>; | ||
/** | ||
@@ -122,11 +122,11 @@ * Ordered list of notices to display in rule doc. | ||
*/ | ||
ruleDocNotices?: NOTICE_TYPE[]; | ||
readonly ruleDocNotices?: readonly NOTICE_TYPE[]; | ||
/** Disallowed sections in each rule doc. Exit with failure if present. */ | ||
ruleDocSectionExclude?: string[]; | ||
readonly ruleDocSectionExclude?: readonly string[]; | ||
/** Required sections in each rule doc. Exit with failure if missing. */ | ||
ruleDocSectionInclude?: string[]; | ||
readonly ruleDocSectionInclude?: readonly string[]; | ||
/** Whether to require an "Options" or "Config" rule doc section and mention of any named options for rules with options. Default: `true`. */ | ||
ruleDocSectionOptions?: boolean; | ||
readonly ruleDocSectionOptions?: boolean; | ||
/** The format to use for rule doc titles. Default: `desc-parens-prefix-name`. */ | ||
ruleDocTitleFormat?: RuleDocTitleFormat; | ||
readonly ruleDocTitleFormat?: RuleDocTitleFormat; | ||
/** | ||
@@ -138,3 +138,3 @@ * Ordered list of columns to display in rule list. | ||
*/ | ||
ruleListColumns?: COLUMN_TYPE[]; | ||
readonly ruleListColumns?: readonly COLUMN_TYPE[]; | ||
/** | ||
@@ -145,5 +145,5 @@ * Rule property to split the rules list by. | ||
*/ | ||
ruleListSplit?: string; | ||
readonly ruleListSplit?: string; | ||
/** Link to documentation about the ESLint configurations exported by the plugin. */ | ||
urlConfigs?: string; | ||
readonly urlConfigs?: string; | ||
/** | ||
@@ -154,3 +154,3 @@ * Link to documentation for each rule. | ||
*/ | ||
urlRuleDoc?: string; | ||
readonly urlRuleDoc?: string; | ||
}; |
{ | ||
"name": "eslint-doc-generator", | ||
"version": "0.28.0", | ||
"version": "0.28.1", | ||
"description": "Automatic documentation generator for ESLint plugins and rules.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -49,3 +49,3 @@ # eslint-doc-generator | ||
- Both a lint script to ensure everything is up-to-date in CI and an update script for contributors to run locally | ||
- Add any [config options](#configuration-options) in the `update:eslint-docs` script only | ||
- Add any [config options](#configuration-options) in the `update:eslint-docs` script only (or use a [config file](#configuration-file)) | ||
- Alternative scripts may be needed with [build tools](#build-tools) or [prettier](#prettier) | ||
@@ -58,3 +58,3 @@ | ||
"lint:docs": "markdownlint \"**/*.md\"", | ||
"lint:eslint-docs": "npm-run-all \"update:eslint-docs -- --check\"", | ||
"lint:eslint-docs": "npm run update:eslint-docs -- --check", | ||
"lint:js": "eslint .", | ||
@@ -73,3 +73,3 @@ "update:eslint-docs": "eslint-doc-generator" | ||
Delete any old recommended/fixable/etc. notices from your rule docs. A new title and notices will be automatically added to the top of each rule doc (along with a marker comment if it doesn't exist yet). | ||
Delete any old recommended/fixable/etc. notices from your rule docs. A new title and notices will be automatically added to the top of each rule doc (along with a marker comment if it doesn't already exist). | ||
@@ -122,4 +122,6 @@ ```md | ||
There's also an optional path argument if you need to point the CLI to an ESLint plugin directory that isn't just the current directory. | ||
The CLI has an optional path argument if you need to point the CLI to an ESLint plugin directory that isn't just the current directory. | ||
There's also a `postprocess` option that's only available via a [config file](#configuration-file). | ||
| Name | Description | | ||
@@ -158,3 +160,3 @@ | :-- | :-- | | ||
There are a few ways to create a config file: | ||
There are a few ways to create a config file (as an alternative to passing the options via CLI): | ||
@@ -166,3 +168,3 @@ - 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) | ||
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). | ||
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. This is useful for applying custom transformations such as formatting with tools like prettier (see [prettier example](#prettier)). | ||
@@ -184,3 +186,3 @@ Example `.eslint-doc-generatorrc.js`: | ||
If you have a build step for your code like [Babel](https://babeljs.io/) or [TypeScript](https://www.typescriptlang.org/), you may need to adjust your scripts to run your build before this tool: | ||
If you have a build step for your code like [Babel](https://babeljs.io/) or [TypeScript](https://www.typescriptlang.org/), you may need to adjust your scripts to run your build before this tool to ensure the documentation is generated from the latest plugin information: | ||
@@ -204,3 +206,3 @@ ```json | ||
const config = { | ||
postprocess: content => | ||
postprocess: (content, path) => | ||
prettier.format(content, { ...prettierRC, parser: 'markdown' }), | ||
@@ -207,0 +209,0 @@ }; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
114065
223
2036