Security News
pnpm 10.0.0 Blocks Lifecycle Scripts by Default
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
eslint-docgen
Advanced tools
Automatically generate ESLint plugin documentation from rule metadata and test cases.
Automatically generate ESLint plugin documentation from rule metadata and test cases.
npm install eslint-docgen --save-dev
Replace all uses of RuleTester
with the version from this package:
// Old:
const RuleTester = require( 'eslint' ).RuleTester;
// New:
const RuleTester = require( 'eslint-docgen' ).RuleTester;
Create a configuration file as described in Configuration, setting docPath
and preferably rulePath
and testPath
.
To build your documentation, run your rule tests with the DOCGEN
environment variable set in the command line, e.g.
DOCGEN=1 mocha tests/rules/
You could add this to your package.json to make it available as npm run doc
, e.g.
{
//
"scripts": {
//
"doc": "rm -rf docs/rules && DOCGEN=1 mochan tests/rules/"
}
//
}
Documentation will be built using rule metadata and test data passed to RuleTester
:
rule.meta.docs.description
Used as the description of the rule in the documentation.
rule.meta.docs.deprecated
/ rule.meta.docs.replacedBy
Used to show a deprecation warning in the documentation, optionally with links to replacement rule(s).
tests.valid
/tests.invalid
from RuleTester#run
Will generate code blocks showing examples of valid/invalid usage. Blocks will be grouped by unique options
/settings
configurations. Fixable rules with output
will generate a separate block showing the before and after.
By default all test cases will be included in the examples. To exclude specific test cases from these code blocks use the docgen: false
option:
{
code: 'App.method();',
docgen: false
}
If you have excludeExamplesByDefault
set to true
in your config, you can include specific test cases in these code blocks by using the docgen: true
option:
{
code: 'App.method();',
docgen: true
}
To migrate an existing plugin with manually built documentation you can use the following process:
docs/template/MYRULE.md
and in your .eslintdocgenrc
set ruleTemplatePath
to this new folder, e.g. "docs/template/{name}.md
". Optionally you can rename these files to .ejs
.index.ejs
.Configuration for all rules in a project is controlled by creating a JSON/JavaScript file called .eslintdocgenrc.json
/.eslintdocgenrc.js
in your project root:
{
"docPath": "docs/rules/{name}.md",
// ...
}
module.exports = {
docPath: 'docs/rules/{name}.md',
// ...
};
The project-wide rules configuration can be overridden for individual rules by adding a docgenConfig
property to the tests object passed to RuleTester.run(). All configuration options that are supported project-wide can be changed.
The following config options are available:
docPath
(required)The path to store rule documentation files, with {name}
as a placeholder for the rule name, e.g. "docs/rules/{name}.md"
or "rules/{name}/README.md"
.
rulePath
The path where the rule is defined, only required if ruleLink
is true
. Same format as docPath
.
testPath
The path where the rule's tests are defined, only required if testPath
is true
. Same format as docPath
.
ruleTemplatePath
When defined, will try to use a rule specific template instead of index.ejs
, e.g. "docs/templates/{name}.ejs"
. Same format as docPath
.
globalTemplatePath
When defined, templates in this path will override the global templates defined in src/templates
.
docLink
(default false
)Add a link to the documentation source in the "Resources" section.
ruleLink
(default true
)Add a link to the rule source in the "Resources" section. Requires rulePath
to be defined.
testLink
(default true
)Add a link to the rule's test source in the "Resources" section. Requires testPath
to be defined.
pluginName
(default from package name)The name of your plugin as used in directives, e.g. plugin:pluginName/rule
. Defaults to the name in package.json
with eslint-plugin-
stripped.
fixCodeExamples
(default true
)Fix code examples using the ESLint configuration used for your main
script.
showConfigComments
(default false
)Shows config comments at the top of code examples:
/* eslint myPlugin/rule: "error" */
// Test cases
showFixExamples
(default true
)Show examples of how code is fixed by the rule.
showFilenames
(default: false
)Show the relevant file name for test cases.
excludeExamplesByDefault
(default false
)Exclude tests from being used as examples by default. When this is true
users must set docgen: true
on any test they want to be included in examples.
minExamples
(default ['warn', 2]
)Minimum examples per rule. Tuple where first value is one of 'warn'
or 'error'
, and the second value is the minimum number of examples required. Use null
for no minimum.
maxExamples
(default ['warn', 50]
)Maximum examples per rule. Tuple where first value is one of 'warn'
or 'error'
, and the second value is the maximum number of examples allowed. Use null
for no maximum.
tabWidth
(default 4
)Number of spaces to convert tabs to in code examples. Tabs in examples are always converted to spaces so their widths can be determined reliably for alignment.
To assist with building an index of your rules, for example to put in a root README, this package exports rulesWithConfig
. The value is a Map much like the one returned by Linter#getRules but each rule has an additional configMap
property that describes which configs include the rule and the options used (null
if no options are used).
Note that the rule names do not include the plugin prefix.
Example:
require( 'eslint-docgen' ).rulesWithConfig.get( 'no-event-shorthand' );
// Outputs:
{
meta: [Object],
create: [Function],
configMap: Map {
'deprecated-3.5' => null,
'deprecated-3.3' => [ { allowAjaxEvents: true } ]
}
}
FAQs
Automatically generate ESLint plugin documentation from rule metadata and test cases.
The npm package eslint-docgen receives a total of 37 weekly downloads. As such, eslint-docgen popularity was classified as not popular.
We found that eslint-docgen demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers 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.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.