eslint-embedded-rules-docs
Get a local copy of the ESLint embedded rules documentation (fetched from https://github.com/eslint/eslint/tree/master/docs/rules).
Installation
Note: To use this library, you have to have installed Node.js and a console you can run commands into. The minimum required version of Node.js is: 8 - codename "Carbon".
In your console, run the following command:
$ npm install eslint-embedded-rules-docs
You can also use yarn
(like we do in this project):
$ yarn add eslint-embedded-rules-docs
Usage
const {getESLintRuleNames, getRuleDocumentation} = require('..');
async function main() {
const rules = getESLintRuleNames();
const rulesFetchPromises = rules.map(rule => getRuleDocumentation(rule));
const rulesDocs = await Promise.all(rulesFetchPromises);
// Prints in the console every rule's documentation
console.log(rulesDocs);
}
main().then().catch(console.error);
API
This library exports an object containing the following properties (more details below):
defaultOptions
fetchRuleDocumentation
getESLintRules
getESLintRuleNames
getRuleDocumentation
requiresDownload
You can find usage examples in the examples directory.
defaultOptions
Type: object
This immutable object contains the default options used in the library.
eslintVersion
Type: string
Default: '6.3.0'
(this module's eslint
dependency version)
ESLint version used to fetch rules from GitHub. This option changes the URL used by the module to download the markdown rule files.
targetDir
Type: string
Default: User data path for this application (ex. Windows: "%LOCAL_APP_DATA%\\eslint-embedded-rules-docs\\Data"
)
Target directory to save/get the rule files.
fetchRuleDocumentation(ruleName, options?)
Downloads the rule documentation from ESLint's GitHub repository and returns the final file path. This function throws by design in the following cases:
- if the rule name is
null
orundefined
; - if the rule name is not of type
string
; - if the rule name is empty or contains only white spaces;
- if the rule name is not included in the embedded ESLint rules set;
- if the eslintVersion specified in the options is not a valid version in the Semantic Versioning system.
getESLintRules()
Returns the Map
of the embedded ESLint rules (lazily).
Reminder: the key is the rule's name, while the value contains the rule metadata.
getESLintRuleNames()
Returns an array of the embedded ESLint rule names (string[]
).
getRuleDocumentation(ruleName, options?)
Returns the specified rule documentation in markdown syntax as a string
.
If the rule's markdown file has not yet been downloaded, this function also calls fetchRuleDocumentation with the same arguments.
requiresDownload(ruleName, options?)
Returns a boolean
indicating if the specified rule needs to be downloaded.
This function does not download the rule documentation.