eslint-docgen 0.6.2 → 0.7.0
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/package.json +4 -4
- package/src/build-docs-from-tests.js +8 -8
- package/src/fix.js +26 -19
- package/src/write-docs-from-tests.js +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-docgen",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Automatically generate ESLint plugin documentation from rule metadata and test cases.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"chalk": "^4.1.2",
|
|
27
27
|
"ejs": "^3.1.6",
|
|
28
|
-
"eslint": ">=
|
|
28
|
+
"eslint": ">=8.0.0",
|
|
29
29
|
"import-fresh": "^3.3.0",
|
|
30
30
|
"jsonschema": "^1.4.0",
|
|
31
31
|
"merge-options": "^3.0.4",
|
|
@@ -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, isValid, showFixes ) {
|
|
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
|
}
|
|
@@ -215,7 +215,7 @@ function buildDocsFromTests(
|
|
|
215
215
|
if ( config.fixCodeExamples ) {
|
|
216
216
|
const fix = require( './fix' );
|
|
217
217
|
// Fixes whitespace in block comment. Too expensive for such a small fix?
|
|
218
|
-
comments = fix.batchLintFix( comments, testerConfig );
|
|
218
|
+
comments = await fix.batchLintFix( comments, testerConfig );
|
|
219
219
|
}
|
|
220
220
|
}
|
|
221
221
|
|
|
@@ -268,8 +268,8 @@ function buildDocsFromTests(
|
|
|
268
268
|
} );
|
|
269
269
|
}
|
|
270
270
|
|
|
271
|
-
const invalid = buildRuleDetails( tests.invalid, false );
|
|
272
|
-
const valid = buildRuleDetails( tests.valid, true );
|
|
271
|
+
const invalid = await buildRuleDetails( tests.invalid, false );
|
|
272
|
+
const valid = await buildRuleDetails( tests.valid, true );
|
|
273
273
|
|
|
274
274
|
const validInvalid = invalid.concat( valid ).sort( ( a, b ) => {
|
|
275
275
|
return a.key === b.key ?
|
|
@@ -279,7 +279,7 @@ function buildDocsFromTests(
|
|
|
279
279
|
|
|
280
280
|
let fixed = [];
|
|
281
281
|
if ( ruleMeta.fixable && config.showFixExamples ) {
|
|
282
|
-
fixed = buildRuleDetails(
|
|
282
|
+
fixed = await buildRuleDetails(
|
|
283
283
|
tests.invalid.filter( ( test ) => !!test.output ),
|
|
284
284
|
false,
|
|
285
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,8 +32,8 @@ 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
|
|
@@ -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 = {
|
|
@@ -35,7 +35,7 @@ if ( config.globalTemplatePath ) {
|
|
|
35
35
|
}
|
|
36
36
|
const { globalTemplates, loadRuleTemplate } = loadTemplates( templatePaths );
|
|
37
37
|
|
|
38
|
-
function writeDocsFromTests( name, rule, tests, testerConfig, done ) {
|
|
38
|
+
async function writeDocsFromTests( name, rule, tests, testerConfig, done ) {
|
|
39
39
|
// If the tests have a `docgenConfig` property, this overrides the global configuration
|
|
40
40
|
let configForRule = config;
|
|
41
41
|
if ( tests.docgenConfig !== undefined ) {
|
|
@@ -51,7 +51,7 @@ function writeDocsFromTests( name, rule, tests, testerConfig, done ) {
|
|
|
51
51
|
const configMap = rulesWithConfig.get( name ).configMap;
|
|
52
52
|
let output, messages;
|
|
53
53
|
try {
|
|
54
|
-
( { output, messages } = buildDocsFromTests(
|
|
54
|
+
( { output, messages } = await buildDocsFromTests(
|
|
55
55
|
name, rule.meta, tests, configMap, configForRule,
|
|
56
56
|
globalTemplates, loadRuleTemplate, testerConfig
|
|
57
57
|
) );
|