eslint-docgen 0.6.1 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -0
- package/package.json +6 -6
- package/src/build-docs-from-tests.js +10 -11
- package/src/fix.js +28 -21
- package/src/write-docs-from-tests.js +10 -23
- package/Changelog.md +0 -99
package/README.md
CHANGED
|
@@ -25,6 +25,18 @@ To build your documentation, run your rule tests with the `DOCGEN` environment v
|
|
|
25
25
|
DOCGEN=1 mocha tests/rules/
|
|
26
26
|
```
|
|
27
27
|
|
|
28
|
+
You could add this to your package.json to make it available as `npm run doc`, e.g.
|
|
29
|
+
```jsonc
|
|
30
|
+
{
|
|
31
|
+
//
|
|
32
|
+
"scripts": {
|
|
33
|
+
//
|
|
34
|
+
"doc": "rm -rf docs/rules && DOCGEN=1 mochan tests/rules/"
|
|
35
|
+
}
|
|
36
|
+
//
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
28
40
|
Documentation will be built using **rule metadata** and **test data** passed to `RuleTester`:
|
|
29
41
|
|
|
30
42
|
#### `rule.meta.docs.description`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-docgen",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.1",
|
|
4
4
|
"description": "Automatically generate ESLint plugin documentation from rule metadata and test cases.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -24,10 +24,10 @@
|
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"chalk": "^4.1.2",
|
|
27
|
-
"ejs": "^3.1.
|
|
28
|
-
"eslint": ">=
|
|
27
|
+
"ejs": "^3.1.8",
|
|
28
|
+
"eslint": ">=8.0.0",
|
|
29
29
|
"import-fresh": "^3.3.0",
|
|
30
|
-
"jsonschema": "^1.4.
|
|
30
|
+
"jsonschema": "^1.4.1",
|
|
31
31
|
"merge-options": "^3.0.4",
|
|
32
32
|
"mkdirp": "^1.0.4",
|
|
33
33
|
"pkg-dir": "^5.0.0",
|
|
@@ -36,9 +36,9 @@
|
|
|
36
36
|
"upath": "^2.0.1"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"eslint-config-wikimedia": "^0.
|
|
39
|
+
"eslint-config-wikimedia": "^0.22.1",
|
|
40
40
|
"eslint-plugin-node": "^11.1.0",
|
|
41
|
-
"mocha": "^9.
|
|
41
|
+
"mocha": "^9.2.0",
|
|
42
42
|
"nyc": "^15.1.0"
|
|
43
43
|
}
|
|
44
44
|
}
|
|
@@ -37,7 +37,7 @@ function mdLink( target, label ) {
|
|
|
37
37
|
return '[' + label + '](' + target + ')';
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
function buildDocsFromTests(
|
|
40
|
+
async function buildDocsFromTests(
|
|
41
41
|
name, ruleMeta, tests, configMap, config, globalTemplates, loadRuleTemplate, testerConfig
|
|
42
42
|
) {
|
|
43
43
|
|
|
@@ -78,7 +78,7 @@ function buildDocsFromTests(
|
|
|
78
78
|
return path.basename( test.filename );
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
-
function buildRuleDetails( testList,
|
|
81
|
+
async function buildRuleDetails( testList, isValid, showFixes ) {
|
|
82
82
|
testList = testList.filter( ( test ) =>
|
|
83
83
|
test.docgen === undefined ?
|
|
84
84
|
!config.excludeExamplesByDefault :
|
|
@@ -91,7 +91,7 @@ function buildDocsFromTests(
|
|
|
91
91
|
const codeList = testList.map( getCode );
|
|
92
92
|
if ( config.fixCodeExamples ) {
|
|
93
93
|
const fix = require( './fix' );
|
|
94
|
-
fixedCode = fix.batchLintFix( codeList, testerConfig );
|
|
94
|
+
fixedCode = await fix.batchLintFix( codeList, testerConfig );
|
|
95
95
|
} else {
|
|
96
96
|
fixedCode = codeList;
|
|
97
97
|
}
|
|
@@ -110,7 +110,7 @@ function buildDocsFromTests(
|
|
|
110
110
|
const outputList = testList.map( ( test ) => test.output );
|
|
111
111
|
if ( config.fixCodeExamples ) {
|
|
112
112
|
const fix = require( './fix' );
|
|
113
|
-
fixedOutput = fix.batchLintFix( outputList, testerConfig );
|
|
113
|
+
fixedOutput = await fix.batchLintFix( outputList, testerConfig );
|
|
114
114
|
} else {
|
|
115
115
|
fixedOutput = outputList;
|
|
116
116
|
}
|
|
@@ -176,9 +176,8 @@ function buildDocsFromTests(
|
|
|
176
176
|
};
|
|
177
177
|
|
|
178
178
|
if ( showFixes && test.output ) {
|
|
179
|
-
const output = fixedOutput[ i ];
|
|
180
179
|
const codeLines = code.split( '\n' );
|
|
181
|
-
const outputLines =
|
|
180
|
+
const outputLines = fixedOutput[ i ].split( '\n' );
|
|
182
181
|
const maxLines = Math.max( codeLines.length, outputLines.length );
|
|
183
182
|
const exampleLines = [];
|
|
184
183
|
for ( let l = 0; l < maxLines; l++ ) {
|
|
@@ -216,7 +215,7 @@ function buildDocsFromTests(
|
|
|
216
215
|
if ( config.fixCodeExamples ) {
|
|
217
216
|
const fix = require( './fix' );
|
|
218
217
|
// Fixes whitespace in block comment. Too expensive for such a small fix?
|
|
219
|
-
comments = fix.batchLintFix( comments, testerConfig );
|
|
218
|
+
comments = await fix.batchLintFix( comments, testerConfig );
|
|
220
219
|
}
|
|
221
220
|
}
|
|
222
221
|
|
|
@@ -237,7 +236,7 @@ function buildDocsFromTests(
|
|
|
237
236
|
|
|
238
237
|
return {
|
|
239
238
|
key: key,
|
|
240
|
-
valid:
|
|
239
|
+
valid: isValid,
|
|
241
240
|
options: options ? JSON.stringify( options ) : '',
|
|
242
241
|
settings: settings ? JSON.stringify( settings ) : '',
|
|
243
242
|
filename: filename || '',
|
|
@@ -269,8 +268,8 @@ function buildDocsFromTests(
|
|
|
269
268
|
} );
|
|
270
269
|
}
|
|
271
270
|
|
|
272
|
-
const invalid = buildRuleDetails( tests.invalid, false );
|
|
273
|
-
const valid = buildRuleDetails( tests.valid, true );
|
|
271
|
+
const invalid = await buildRuleDetails( tests.invalid, false );
|
|
272
|
+
const valid = await buildRuleDetails( tests.valid, true );
|
|
274
273
|
|
|
275
274
|
const validInvalid = invalid.concat( valid ).sort( ( a, b ) => {
|
|
276
275
|
return a.key === b.key ?
|
|
@@ -280,7 +279,7 @@ function buildDocsFromTests(
|
|
|
280
279
|
|
|
281
280
|
let fixed = [];
|
|
282
281
|
if ( ruleMeta.fixable && config.showFixExamples ) {
|
|
283
|
-
fixed = buildRuleDetails(
|
|
282
|
+
fixed = await buildRuleDetails(
|
|
284
283
|
tests.invalid.filter( ( test ) => !!test.output ),
|
|
285
284
|
false,
|
|
286
285
|
true
|
package/src/fix.js
CHANGED
|
@@ -1,23 +1,29 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
const linter = new
|
|
5
|
-
const
|
|
6
|
-
const config = cli.getConfigForFile( require( './main' ) );
|
|
7
|
-
const rules = cli.getRules();
|
|
3
|
+
const { Linter, ESLint } = require( 'eslint' );
|
|
4
|
+
const linter = new Linter();
|
|
5
|
+
const eslint = new ESLint();
|
|
8
6
|
const mergeOptions = require( 'merge-options' );
|
|
7
|
+
// eslint-disable-next-line node/no-missing-require
|
|
8
|
+
const { builtinRules } = require( 'eslint/use-at-your-own-risk' );
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
async function getConfig() {
|
|
11
|
+
const config = await eslint.calculateConfigForFile( require( './main' ) );
|
|
12
|
+
|
|
13
|
+
// Optimization: Only use fixable rules
|
|
14
|
+
const fixableRules = {};
|
|
15
|
+
Object.keys( config.rules ).forEach( function ( ruleName ) {
|
|
16
|
+
if ( builtinRules.has( ruleName ) ) {
|
|
17
|
+
const rule = builtinRules.get( ruleName );
|
|
18
|
+
if ( rule.meta.fixable ) {
|
|
19
|
+
fixableRules[ ruleName ] = config.rules[ ruleName ];
|
|
20
|
+
}
|
|
17
21
|
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
|
|
22
|
+
} );
|
|
23
|
+
config.rules = fixableRules;
|
|
24
|
+
|
|
25
|
+
return config;
|
|
26
|
+
}
|
|
21
27
|
|
|
22
28
|
/**
|
|
23
29
|
* Lint and fix some code
|
|
@@ -26,13 +32,13 @@ config.rules = fixableRules;
|
|
|
26
32
|
* @param {Object} testerConfig Config
|
|
27
33
|
* @return {string} Fixed code
|
|
28
34
|
*/
|
|
29
|
-
function lintFix( code, testerConfig ) {
|
|
30
|
-
const mergedConfig = mergeOptions(
|
|
35
|
+
async function lintFix( code, testerConfig ) {
|
|
36
|
+
const mergedConfig = mergeOptions( await getConfig(), testerConfig );
|
|
31
37
|
|
|
32
38
|
// TODO
|
|
33
39
|
// istanbul ignore next
|
|
34
|
-
if (
|
|
35
|
-
linter.defineParser(
|
|
40
|
+
if ( typeof mergedConfig.parser === 'string' ) {
|
|
41
|
+
linter.defineParser( mergedConfig.parser, require( mergedConfig.parser ) );
|
|
36
42
|
}
|
|
37
43
|
|
|
38
44
|
const result = linter.verifyAndFix( code, mergedConfig );
|
|
@@ -55,11 +61,12 @@ function lintFix( code, testerConfig ) {
|
|
|
55
61
|
* @param {Object} testerConfig Config
|
|
56
62
|
* @return {string[]} Fixed code list
|
|
57
63
|
*/
|
|
58
|
-
function batchLintFix( codeList, testerConfig ) {
|
|
64
|
+
async function batchLintFix( codeList, testerConfig ) {
|
|
59
65
|
const separator = '\n/* - */\n';
|
|
60
66
|
const codeBlock = codeList.join( ';' + separator );
|
|
61
67
|
// Add an extra semicolon to avoid syntax error
|
|
62
|
-
|
|
68
|
+
const fixed = await lintFix( codeBlock, testerConfig );
|
|
69
|
+
return fixed.split( separator ).map( ( code ) => code.trim() );
|
|
63
70
|
}
|
|
64
71
|
|
|
65
72
|
module.exports = {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
/* eslint-disable no-process-exit */
|
|
4
3
|
const fs = require( 'fs' );
|
|
5
4
|
const mkdirp = require( 'mkdirp' );
|
|
6
5
|
const path = require( 'upath' );
|
|
@@ -14,20 +13,14 @@ let config, configPath;
|
|
|
14
13
|
try {
|
|
15
14
|
( { config, configPath } = getConfig() );
|
|
16
15
|
} catch ( e ) {
|
|
17
|
-
|
|
18
|
-
console.log( formatter.error( e.message ) );
|
|
19
|
-
console.log();
|
|
20
|
-
process.exit( 1 );
|
|
16
|
+
throw new Error( [ formatter.heading( 'eslint-docgen' ), formatter.error( e.message ) ].join( '\n' ) );
|
|
21
17
|
}
|
|
22
18
|
|
|
23
19
|
const configValidator = require( './validate-config' );
|
|
24
20
|
function assertValidConfig( maybeValidConfig, configSource ) {
|
|
25
21
|
const configErrors = configValidator( maybeValidConfig );
|
|
26
22
|
if ( configErrors.length ) {
|
|
27
|
-
|
|
28
|
-
configErrors.forEach( ( error ) => console.log( formatter.error( error ) ) );
|
|
29
|
-
console.log();
|
|
30
|
-
process.exit( 1 );
|
|
23
|
+
throw new Error( [ formatter.heading( configSource ), ...configErrors.map( formatter.error ) ].join( '\n' ) );
|
|
31
24
|
}
|
|
32
25
|
}
|
|
33
26
|
|
|
@@ -42,7 +35,7 @@ if ( config.globalTemplatePath ) {
|
|
|
42
35
|
}
|
|
43
36
|
const { globalTemplates, loadRuleTemplate } = loadTemplates( templatePaths );
|
|
44
37
|
|
|
45
|
-
function writeDocsFromTests( name, rule, tests, testerConfig, done ) {
|
|
38
|
+
async function writeDocsFromTests( name, rule, tests, testerConfig, done ) {
|
|
46
39
|
// If the tests have a `docgenConfig` property, this overrides the global configuration
|
|
47
40
|
let configForRule = config;
|
|
48
41
|
if ( tests.docgenConfig !== undefined ) {
|
|
@@ -53,25 +46,17 @@ function writeDocsFromTests( name, rule, tests, testerConfig, done ) {
|
|
|
53
46
|
const outputPath = packagePath( configForRule.docPath.replace( '{name}', name ) );
|
|
54
47
|
const ruleWithConfig = rulesWithConfig.get( name );
|
|
55
48
|
if ( !ruleWithConfig ) {
|
|
56
|
-
|
|
57
|
-
console.log( formatter.heading( outputPath ) );
|
|
58
|
-
console.log( formatter.error( 'Rule not found.' ) );
|
|
59
|
-
console.log();
|
|
60
|
-
process.exit( 1 );
|
|
49
|
+
throw new Error( [ formatter.heading( outputPath ), formatter.error( 'Rule not found.' ) ].join( '\n' ) );
|
|
61
50
|
}
|
|
62
51
|
const configMap = rulesWithConfig.get( name ).configMap;
|
|
63
52
|
let output, messages;
|
|
64
53
|
try {
|
|
65
|
-
( { output, messages } = buildDocsFromTests(
|
|
54
|
+
( { output, messages } = await buildDocsFromTests(
|
|
66
55
|
name, rule.meta, tests, configMap, configForRule,
|
|
67
56
|
globalTemplates, loadRuleTemplate, testerConfig
|
|
68
57
|
) );
|
|
69
58
|
} catch ( e ) {
|
|
70
|
-
|
|
71
|
-
console.log( formatter.heading( outputPath ) );
|
|
72
|
-
console.log( formatter.error( e.message ) );
|
|
73
|
-
console.log();
|
|
74
|
-
process.exit( 1 );
|
|
59
|
+
throw new Error( [ formatter.heading( outputPath ), formatter.error( e.message ) ].join( '\n' ) );
|
|
75
60
|
}
|
|
76
61
|
|
|
77
62
|
const outputDir = path.dirname( outputPath );
|
|
@@ -92,8 +77,10 @@ function writeDocsFromTests( name, rule, tests, testerConfig, done ) {
|
|
|
92
77
|
console.log();
|
|
93
78
|
}
|
|
94
79
|
|
|
95
|
-
|
|
96
|
-
|
|
80
|
+
const errors = messages.filter( ( message ) => message.type === 'error' );
|
|
81
|
+
|
|
82
|
+
if ( errors.length ) {
|
|
83
|
+
throw new Error( errors.map( formatter.error ).join( '\n' ) );
|
|
97
84
|
}
|
|
98
85
|
|
|
99
86
|
done();
|
package/Changelog.md
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
# eslint-docgen release history
|
|
2
|
-
|
|
3
|
-
## v0.6.1
|
|
4
|
-
* Fix: Filter out docgen:false tests before parsing (#120)
|
|
5
|
-
|
|
6
|
-
## v0.6.0
|
|
7
|
-
* Breaking change: Drop deprecated 'noDoc' option and '--doc' CLI flag (#115)
|
|
8
|
-
* New: build-docs-from-tests: add Vue syntax highlighting (#105) (DannyS712)
|
|
9
|
-
* New: Add TypeScript syntax highlighting
|
|
10
|
-
* New: Add HTML syntax highlighting
|
|
11
|
-
* New: Separate syntax highlighting support from showFilenames (#114)
|
|
12
|
-
* Fix: Don't put an empty line before the first multi-line examples in a set (#117)
|
|
13
|
-
* Code: Cleanup code for detecting highlight language (#113)
|
|
14
|
-
|
|
15
|
-
## v0.5.1
|
|
16
|
-
* Breaking change: Change the default icon for rules which are included in a preset (#109)
|
|
17
|
-
* Breaking change: Add generated-file-warning comment to the top of MD files (#107)
|
|
18
|
-
* Breaking change: Drop support for Node 10 (#110)
|
|
19
|
-
* New: Add configuration to show file names for test cases (#101) (DannyS712)
|
|
20
|
-
* New: Add per-rule config overrides (DannyS7123)
|
|
21
|
-
* Docs: Various README fixes
|
|
22
|
-
* Code: Update dependencies
|
|
23
|
-
|
|
24
|
-
## v0.4.5
|
|
25
|
-
* Code: Update dependencies
|
|
26
|
-
|
|
27
|
-
## v0.4.4
|
|
28
|
-
|
|
29
|
-
* Code: Ensure config.docPath exists before writing output path. (Raine Revere)
|
|
30
|
-
* Code: Calculate outputDir from outputPath
|
|
31
|
-
* Code: Fix reporting of writeFile error messages
|
|
32
|
-
* Code: Output formatted error when rule not found (#92)
|
|
33
|
-
* Docs: Fix config param heading level in README (#91)
|
|
34
|
-
|
|
35
|
-
## v0.4.3
|
|
36
|
-
|
|
37
|
-
* Code: Run one test 'it' per rule
|
|
38
|
-
|
|
39
|
-
## v0.4.2
|
|
40
|
-
|
|
41
|
-
* New: Introduce excludeExamplesByDefault config
|
|
42
|
-
* Code: Remove some whitespace in config-schema
|
|
43
|
-
* Code: Add a 'report' script
|
|
44
|
-
|
|
45
|
-
## v0.4.1
|
|
46
|
-
|
|
47
|
-
* Code: Update mocha to 8.0.1
|
|
48
|
-
* Code: Replace path with upath for windows compatibility (#83)
|
|
49
|
-
* Code: Use DOCGEN environment variable instead of --doc flag
|
|
50
|
-
* Code: Add an editorconfig to make the tabs a reasonable width on GitHub (Jed Fox)
|
|
51
|
-
* Code: Allow package.main to be empty
|
|
52
|
-
* Code: Support scoped plugin names
|
|
53
|
-
* Docs: Add more method documentation
|
|
54
|
-
* Docs: Fix external links to examples
|
|
55
|
-
* Docs: Add Migration section to README and move some pieces around
|
|
56
|
-
|
|
57
|
-
## v0.4.0
|
|
58
|
-
|
|
59
|
-
* Breaking change: New: Add fix message to introduction (#49)
|
|
60
|
-
* Breaking change: New: Format long lists correctly ("a, b, and c")
|
|
61
|
-
* Breaking change: New: Sort examples by options *then* valid/invalid (#48)
|
|
62
|
-
* New: Refactor rulesData to rulesWithConfig and expose (#16)
|
|
63
|
-
* New: Add ruleTemplatePath config (#14)
|
|
64
|
-
* New: Add showFixExamples config (#49)
|
|
65
|
-
* Code: Update eslint-config-wikimedia to 0.16.1 and use /mocha
|
|
66
|
-
* Code: Use pkg-dir
|
|
67
|
-
* Code: Create a JSON-schema to validate configs (#63)
|
|
68
|
-
* Code: Update various dependencies
|
|
69
|
-
* Tests: Separate config tests into get/validate
|
|
70
|
-
* Tests: Increase timeout
|
|
71
|
-
* Tests: Separate buildDocsFromTests cases
|
|
72
|
-
* Docs: Fix example docpath
|
|
73
|
-
|
|
74
|
-
## v0.3.1
|
|
75
|
-
|
|
76
|
-
* Fix: Use plugin's version of ESLint
|
|
77
|
-
|
|
78
|
-
## v0.3.0
|
|
79
|
-
|
|
80
|
-
* Breaking change: New: Support multi-line test cases (#34)
|
|
81
|
-
* New: Support multiple lines in formatter
|
|
82
|
-
* New: Add min/maxExamples to config (#29)
|
|
83
|
-
* New: Use chalk to do pretty output of warnings/errors (#38)
|
|
84
|
-
* Code: Bump node dependency to 10 (#44)
|
|
85
|
-
* Code: Use strict mode
|
|
86
|
-
* Code: Use eslint-plugin-node/recommended
|
|
87
|
-
* Code: Removed fixed length truncation from rules-data.js
|
|
88
|
-
* Tests: Add tests for most utils (#39)
|
|
89
|
-
* Tests: Increase code coverage to 100%
|
|
90
|
-
* Docs: Add "plugin" to description
|
|
91
|
-
|
|
92
|
-
## v0.2.0
|
|
93
|
-
|
|
94
|
-
* Breaking change: Refactor templates. Users with existing template overrides will need to rewrite them.
|
|
95
|
-
* Release: Update ejs to 3.1.3
|
|
96
|
-
|
|
97
|
-
## v0.1.0
|
|
98
|
-
|
|
99
|
-
* Initial release.
|