eslint-plugin-crisp 1.0.33 → 1.0.35
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 +19 -5
package/package.json
CHANGED
|
@@ -1,24 +1,38 @@
|
|
|
1
1
|
const PARAM_REGEX = /^\s*\*\s*@param\s*\{\s*(.+?)\s*\}\s*(\S+)/;
|
|
2
2
|
const RETURN_REGEX = /^\s*\*\s*@return\s*\{\s*(.+?)\s*\}\s*(.*)/;
|
|
3
3
|
const SCOPE_REGEX = /^\s*\*\s*@(public|private|protected)/;
|
|
4
|
+
const CLASS_REGEX = /^\s*\*\s*@class\b/;
|
|
5
|
+
const CLASSDESC_REGEX = /^\s*\*\s*@classdesc\s*(.*)/;
|
|
4
6
|
|
|
5
7
|
function parseJSDoc(jsdoc) {
|
|
6
8
|
const lines = jsdoc.split('\n');
|
|
7
9
|
const params = [];
|
|
8
10
|
let returnLine = null;
|
|
11
|
+
let classAnnotation = false;
|
|
12
|
+
let classDescription = "";
|
|
9
13
|
let description = '';
|
|
10
14
|
let scope = '';
|
|
11
15
|
|
|
12
16
|
for (let i = 1; i < lines.length; i++) {
|
|
13
17
|
const line = lines[i].trim();
|
|
14
18
|
|
|
15
|
-
|
|
19
|
+
if (line.match(CLASS_REGEX)) {
|
|
20
|
+
classAnnotation = true;
|
|
21
|
+
continue; // Skip this line and continue with the next
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (line.match(CLASSDESC_REGEX)) {
|
|
25
|
+
classDescription = line.match(CLASSDESC_REGEX)[1];
|
|
26
|
+
continue; // Skip this line and continue with the next
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// If the line matches any of the other regexes, break out of the loop
|
|
16
30
|
if (line.match(PARAM_REGEX) || line.match(RETURN_REGEX) || line.match(SCOPE_REGEX)) {
|
|
17
31
|
break;
|
|
18
32
|
}
|
|
19
33
|
|
|
20
|
-
// Append each line to the description, removing leading " * " if present
|
|
21
|
-
description += line.replace(/^\s*\*/, '').trim() + '
|
|
34
|
+
// Append each line to the description, removing leading " * " if present, and adding a newline character
|
|
35
|
+
description += line.replace(/^\s*\*/, '').trim() + '\n';
|
|
22
36
|
}
|
|
23
37
|
|
|
24
38
|
description = description.trim();
|
|
@@ -63,7 +77,7 @@ function formatJSDoc(parsedJSDoc, indentation=0) {
|
|
|
63
77
|
|
|
64
78
|
let jsdoc = '/**\n'
|
|
65
79
|
|
|
66
|
-
jsdoc += indent + '* ' +
|
|
80
|
+
jsdoc += indent + '* ' +parsedJSDoc.description.replace("\n", "\n" + indent + "* ") + "\n";
|
|
67
81
|
|
|
68
82
|
if (parsedJSDoc.scope) {
|
|
69
83
|
jsdoc += indent + '* @' + parsedJSDoc.scope + '\n';
|
|
@@ -116,7 +130,7 @@ module.exports = {
|
|
|
116
130
|
|
|
117
131
|
if (jsdocString !== formattedJSDoc && parsedJSDoc.description && parsedJSDoc.scope) {
|
|
118
132
|
context.report({
|
|
119
|
-
node,
|
|
133
|
+
node: jsdocComment,
|
|
120
134
|
message: 'JSDoc alignment issue',
|
|
121
135
|
fix(fixer) {
|
|
122
136
|
return fixer.replaceText(jsdocComment, formattedJSDoc);
|