Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
eslint-doc-generator
Advanced tools
Automatic documentation generator for ESLint plugins and rules.
Generates the following documentation based on ESLint and top ESLint plugin conventions:
README.md
rules tableAlso performs some basic section consistency checks on rule docs:
## Options
/ ## Config
section and mentions each named option (for rules with options)This tool is used by popular ESLint plugins like:
Install it:
npm i --save-dev eslint-doc-generator
Add scripts to package.json
:
update:eslint-docs
script only{
"scripts": {
"lint": "npm-run-all \"lint:*\"",
"lint:docs": "markdownlint \"**/*.md\"",
"lint:eslint-docs": "npm-run-all \"update:eslint-docs -- --check\"",
"lint:js": "eslint .",
"update:eslint-docs": "eslint-doc-generator"
}
}
Delete any old rules list from your README.md
. A new one will be automatically added to your ## Rules
section (along with the following marker comments if they don't already exist):
<!-- begin auto-generated rules list -->
<!-- end auto-generated rules list -->
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).
<!-- end auto-generated rule header -->
And be sure to enable the recommended
rules from eslint-plugin-eslint-plugin as well as eslint-plugin/require-meta-docs-description to ensure your rules have consistent descriptions for use in the generated docs.
Run the script from package.json
to start out or any time you add a rule or update rule metadata in your plugin:
npm run update:eslint-docs
For examples, see our users or the in-house examples below. Note that the in-house examples intentionally show all possible columns and notices.
See the generated rules table and legend in our example README.md
.
See the generated rule doc title and notices in our example rule docs no-foo.md
, prefer-bar.md
, require-baz.md
.
While config emojis are the recommended representations of configs that a rule belongs to (see --config-emoji
), you can alternatively define badges for configs at the bottom of your README.md
.
Here's a badge for a custom fun
config that displays in blue:
[badge-fun]: https://img.shields.io/badge/-fun-blue.svg
And how it looks:
These can be provided as CLI options or as config file options. All options are optional.
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.
Name | Description |
---|---|
--check | Whether to check for and fail if there is a diff. No output will be written. Typically used during CI. Default: false . |
--config-emoji | Custom emoji to use for a config. Format is config-name,emoji . Default emojis are provided for common configs. To remove a default emoji and rely on a badge instead, provide the config name without an emoji. Option can be repeated. |
--ignore-config | Config to ignore from being displayed. Often used for an all config. Option can be repeated. |
--ignore-deprecated-rules | Whether to ignore deprecated rules from being checked, displayed, or updated. Default: false . |
--init-rule-docs | Whether to create rule doc files if they don't yet exist. Default: false . |
--path-rule-doc | Path to markdown file for each rule doc. Use {name} placeholder for the rule name. Default: docs/rules/{name}.md . |
--path-rule-list | Path to markdown file where the rules table list should live. Default: README.md . Option can be repeated. |
--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 . |
--rule-doc-section-exclude | Disallowed section in each rule doc. Exit with failure if present. Option can be repeated. |
--rule-doc-section-include | Required section in each rule doc. Exit with failure if missing. Option can be repeated. |
--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 . |
--rule-doc-title-format | The format to use for rule doc titles. Defaults to desc-parens-prefix-name . See choices in below table. |
--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 . |
--rule-list-split | Rule property to split the rules list by. A separate list and header will be created for each value. Example: meta.type . |
--url-configs | Link to documentation about the ESLint configurations exported by the plugin. |
--url-rule-doc | Link to documentation for each rule. Useful when it differs from the rule doc path on disk (e.g. custom documentation site in use). Use {name} placeholder for the rule name. |
--rule-doc-title-format
Where no-foo
is the rule name, Disallow use of foo
is the rule description, and eslint-plugin-test
is the plugin name.
Value | Example |
---|---|
desc | # Disallow use of foo |
desc-parens-name | # Disallow use of foo (no-foo) |
desc-parens-prefix-name (default) | # Disallow use of foo (test/no-foo) |
name | # no-foo |
prefix-name | # test/no-foo |
There are a few ways to create a config file:
.eslint-doc-generatorrc.js
, .eslint-doc-generatorrc.json
, or any other config file format/name supported by cosmiconfigeslint-doc-generator
key in package.json
Config files support all the CLI options but in camelCase.
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
.
Example .eslint-doc-generatorrc.js
:
/** @type {import('eslint-doc-generator').GenerateOptions} */
const config = {
ignoreConfig: ['all'],
};
module.exports = config;
If you have a build step for your code like Babel or TypeScript, you may need to adjust your scripts to run your build before this tool:
{
"build": "tsc",
"update:eslint-docs": "npm run build && eslint-doc-generator"
}
If you use prettier to format your markdown, you can provide a postprocess
function to ensure the documentation generated by this tool is formatted correctly:
const prettier = require('prettier');
const { prettier: prettierRC } = require('./package.json'); // or wherever your prettier config lies
/** @type {import('eslint-doc-generator').GenerateOptions} */
const config = {
postprocess: content =>
prettier.format(content, { ...prettierRC, parser: 'markdown' }),
};
module.exports = config;
Alternatively, you can configure your scripts to run prettier
after this tool:
{
"format": "prettier --write .",
"lint:eslint-docs": "npm run update:eslint-docs && git diff --exit-code",
"update:eslint-docs": "eslint-doc-generator && npm run format"
}
FAQs
Automatic documentation generator for ESLint plugins and rules.
The npm package eslint-doc-generator receives a total of 36,205 weekly downloads. As such, eslint-doc-generator popularity was classified as popular.
We found that eslint-doc-generator demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.