eslint-plugin-crisp 1.0.102 → 1.0.103
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 +1 -1
- package/rules/jsdoc-align-params.js +48 -5
package/package.json
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
|
-
const PARAM_REGEX = /^\s*\*\s*@param\s*\{\s*(.+?)\s*\}\s*(\S+)/;
|
|
2
|
-
const RETURN_REGEX = /^\s*\*\s*@return\s*\{\s*(.+?)\s*\}\s*(.*)/;
|
|
3
1
|
const SCOPE_REGEX = /^\s*\*\s*@(public|private|protected)/;
|
|
2
|
+
const GENERATOR_REGEX = /^\s*\*\s*@generator/;
|
|
4
3
|
const CLASS_REGEX = /^\s*\*\s*@class\b/;
|
|
5
4
|
const CLASSDESC_REGEX = /^\s*\*\s*@classdesc\s*(.*)/;
|
|
5
|
+
const PARAM_REGEX = /^\s*\*\s*@param\s*\{\s*(.+?)\s*\}\s*(\S+)/;
|
|
6
|
+
const RETURN_REGEX = /^\s*\*\s*@return\s*\{\s*(.+?)\s*\}\s*(.*)/;
|
|
7
|
+
const YIELD_REGEX = /^\s*\*\s*@yields\s*\{\s*(.+?)\s*\}\s*(.*)/;
|
|
6
8
|
|
|
7
9
|
function parseJSDoc(jsdoc) {
|
|
8
10
|
const lines = jsdoc.split('\n');
|
|
9
11
|
const params = [];
|
|
10
12
|
let returnLine = null;
|
|
13
|
+
let yieldLine = null;
|
|
11
14
|
let classAnnotation = false;
|
|
12
15
|
let classDescription = "";
|
|
13
16
|
let description = '';
|
|
14
17
|
let scope = '';
|
|
18
|
+
let generator = false;
|
|
15
19
|
|
|
16
20
|
for (let i = 1; i < lines.length; i++) {
|
|
17
21
|
const line = lines[i].trim();
|
|
@@ -27,7 +31,12 @@ function parseJSDoc(jsdoc) {
|
|
|
27
31
|
}
|
|
28
32
|
|
|
29
33
|
// If the line matches any of the other regexes, break out of the loop
|
|
30
|
-
if (
|
|
34
|
+
if (
|
|
35
|
+
line.match(SCOPE_REGEX) ||
|
|
36
|
+
line.match(PARAM_REGEX) ||
|
|
37
|
+
line.match(RETURN_REGEX) ||
|
|
38
|
+
line.match(YIELD_REGEX)
|
|
39
|
+
) {
|
|
31
40
|
break;
|
|
32
41
|
}
|
|
33
42
|
|
|
@@ -59,13 +68,33 @@ function parseJSDoc(jsdoc) {
|
|
|
59
68
|
returnLine = { type, description: desc.trim() };
|
|
60
69
|
}
|
|
61
70
|
|
|
71
|
+
const yieldMatch = line.match(YIELD_REGEX);
|
|
72
|
+
if (yieldMatch) {
|
|
73
|
+
let [, type, desc] = yieldMatch;
|
|
74
|
+
|
|
75
|
+
if (type && type[0] === "{" && desc[0] === "}") {
|
|
76
|
+
if (desc && desc[0] === "}") {
|
|
77
|
+
desc = desc.substring(1, desc.length);
|
|
78
|
+
|
|
79
|
+
type += " }";
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
yieldLine = { type, description: desc.trim() };
|
|
84
|
+
}
|
|
85
|
+
|
|
62
86
|
const scopeMatch = line.match(SCOPE_REGEX);
|
|
63
87
|
if (scopeMatch) {
|
|
64
88
|
scope = scopeMatch[1];
|
|
65
89
|
}
|
|
90
|
+
|
|
91
|
+
const generatorMatch = line.match(GENERATOR_REGEX);
|
|
92
|
+
if (generatorMatch) {
|
|
93
|
+
generator = true;
|
|
94
|
+
}
|
|
66
95
|
}
|
|
67
96
|
|
|
68
|
-
return { description, scope, params, returnLine };
|
|
97
|
+
return { description, scope, params, returnLine, yieldLine, generator };
|
|
69
98
|
}
|
|
70
99
|
|
|
71
100
|
function formatJSDoc(parsedJSDoc, indentation=0) {
|
|
@@ -79,9 +108,11 @@ function formatJSDoc(parsedJSDoc, indentation=0) {
|
|
|
79
108
|
}
|
|
80
109
|
}
|
|
81
110
|
|
|
82
|
-
// Check the return type length if it exists
|
|
111
|
+
// Check the return/yield type length if it exists
|
|
83
112
|
if (parsedJSDoc.returnLine && parsedJSDoc.returnLine && parsedJSDoc.returnLine.type.length > maxTypeLength && parsedJSDoc.returnLine.description) {
|
|
84
113
|
maxTypeLength = parsedJSDoc.returnLine.type.length;
|
|
114
|
+
} else if (parsedJSDoc.yieldLine && parsedJSDoc.yieldLine && parsedJSDoc.yieldLine.type.length > maxTypeLength && parsedJSDoc.yieldLine.description) {
|
|
115
|
+
maxTypeLength = parsedJSDoc.yieldLine.type.length;
|
|
85
116
|
}
|
|
86
117
|
|
|
87
118
|
let jsdoc = '/**\n'
|
|
@@ -92,6 +123,10 @@ function formatJSDoc(parsedJSDoc, indentation=0) {
|
|
|
92
123
|
jsdoc += indent + '* @' + parsedJSDoc.scope + '\n';
|
|
93
124
|
}
|
|
94
125
|
|
|
126
|
+
if (parsedJSDoc.generator) {
|
|
127
|
+
jsdoc += indent + '* @generator\n';
|
|
128
|
+
}
|
|
129
|
+
|
|
95
130
|
// Format params with padding based on maximum type length
|
|
96
131
|
for (const param of parsedJSDoc.params) {
|
|
97
132
|
const paddingType = ' '.repeat(Math.max(0, maxTypeLength - param.type.length));
|
|
@@ -106,6 +141,14 @@ function formatJSDoc(parsedJSDoc, indentation=0) {
|
|
|
106
141
|
jsdoc += indent + _return + "\n";
|
|
107
142
|
}
|
|
108
143
|
|
|
144
|
+
// Format yield with padding based on maximum type length
|
|
145
|
+
if (parsedJSDoc.yieldLine) {
|
|
146
|
+
const paddingType = ' '.repeat(Math.max(0, maxTypeLength - parsedJSDoc.yieldLine.type.length));
|
|
147
|
+
let _yield = `* @yields {${parsedJSDoc.yieldLine.type}}${paddingType} ${parsedJSDoc.yieldLine.description}`.trimEnd();
|
|
148
|
+
|
|
149
|
+
jsdoc += indent + _yield + "\n";
|
|
150
|
+
}
|
|
151
|
+
|
|
109
152
|
jsdoc += indent + '*/';
|
|
110
153
|
|
|
111
154
|
return jsdoc;
|