eslint-plugin-crisp 1.4.7 → 1.4.8
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/index.js +2 -0
- package/package.json +1 -1
- package/recommended-ts.js +3 -0
- package/rules/jsdoc-description-length.js +113 -0
package/index.js
CHANGED
|
@@ -19,6 +19,7 @@ import ruleJsdocCheckOptionalParams from "./rules/jsdoc-check-optional-params.js
|
|
|
19
19
|
import ruleJsdocEnforceAccess from "./rules/jsdoc-enforce-access.js";
|
|
20
20
|
import ruleJsdocEnforceClassdesc from "./rules/jsdoc-enforce-classdesc.js";
|
|
21
21
|
import ruleJsdocRequireDescriptionUppercase from "./rules/jsdoc-require-description-uppercase.js";
|
|
22
|
+
import ruleJsdocDescriptionLength from "./rules/jsdoc-description-length.js";
|
|
22
23
|
import ruleMethodsNaming from "./rules/methods-naming.js";
|
|
23
24
|
import ruleMethodsOrdering from "./rules/methods-ordering.js";
|
|
24
25
|
import ruleMultilineCommentEndBackslash from "./rules/multiline-comment-end-backslash.js";
|
|
@@ -81,6 +82,7 @@ const plugin = {
|
|
|
81
82
|
"jsdoc-enforce-access": ruleJsdocEnforceAccess,
|
|
82
83
|
"jsdoc-enforce-classdesc": ruleJsdocEnforceClassdesc,
|
|
83
84
|
"jsdoc-require-description-uppercase": ruleJsdocRequireDescriptionUppercase,
|
|
85
|
+
"jsdoc-description-length": ruleJsdocDescriptionLength,
|
|
84
86
|
"methods-naming": ruleMethodsNaming,
|
|
85
87
|
"methods-ordering": ruleMethodsOrdering,
|
|
86
88
|
"multiline-comment-end-backslash": ruleMultilineCommentEndBackslash,
|
package/package.json
CHANGED
package/recommended-ts.js
CHANGED
|
@@ -181,6 +181,9 @@ export default function configRecommendedTS(pluginCrisp) {
|
|
|
181
181
|
"crisp/regex-in-constructor": "error",
|
|
182
182
|
"crisp/ternary-parenthesis": "error",
|
|
183
183
|
|
|
184
|
+
// Crisp JSDoc rules
|
|
185
|
+
"crisp/jsdoc-description-length": "error",
|
|
186
|
+
|
|
184
187
|
// General JSDoc rules
|
|
185
188
|
"jsdoc/require-description": "error",
|
|
186
189
|
"jsdoc/require-param": "off",
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
meta: {
|
|
3
|
+
type: "suggestion",
|
|
4
|
+
docs: {
|
|
5
|
+
description:
|
|
6
|
+
"Enforce JSDoc description line limits and continuation format.",
|
|
7
|
+
},
|
|
8
|
+
schema: [
|
|
9
|
+
{
|
|
10
|
+
type: "object",
|
|
11
|
+
properties: {
|
|
12
|
+
maxLines: {
|
|
13
|
+
type: "integer",
|
|
14
|
+
minimum: 1,
|
|
15
|
+
default: 2,
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
additionalProperties: false,
|
|
19
|
+
},
|
|
20
|
+
],
|
|
21
|
+
},
|
|
22
|
+
|
|
23
|
+
create(context) {
|
|
24
|
+
const options = context.options[0] || {};
|
|
25
|
+
const maxLines = options.maxLines || 2;
|
|
26
|
+
const sourceCode = context.sourceCode || context.getSourceCode();
|
|
27
|
+
|
|
28
|
+
function checkComment(comment) {
|
|
29
|
+
if (comment.type !== "Block" || !comment.value.startsWith("*")) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Skip section headers (lines full of asterisks)
|
|
34
|
+
if (/\*{10,}/.test(comment.value)) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const rawLines = comment.value.split("\n").slice(1);
|
|
39
|
+
|
|
40
|
+
// Extract description lines (before any @tag)
|
|
41
|
+
const descLines = [];
|
|
42
|
+
|
|
43
|
+
for (const line of rawLines) {
|
|
44
|
+
const content = line.replace(/^\s*\*\s?/, "");
|
|
45
|
+
|
|
46
|
+
if (content.trimStart().startsWith("@")) {
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (content.trim().length > 0) {
|
|
51
|
+
descLines.push({ raw: line, content: content });
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (descLines.length <= 1) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (descLines.length > maxLines) {
|
|
60
|
+
context.report({
|
|
61
|
+
loc: comment.loc,
|
|
62
|
+
message:
|
|
63
|
+
"JSDoc description must not exceed {{ maxLines }} line(s).",
|
|
64
|
+
data: { maxLines: String(maxLines) },
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Multi-line is allowed, check continuation format
|
|
71
|
+
for (let i = 0; i < descLines.length - 1; i++) {
|
|
72
|
+
const trimmed = descLines[i].content.trimEnd();
|
|
73
|
+
|
|
74
|
+
if (!trimmed.endsWith("\\")) {
|
|
75
|
+
context.report({
|
|
76
|
+
loc: comment.loc,
|
|
77
|
+
message:
|
|
78
|
+
"Multi-line JSDoc description must end with '\\' before " +
|
|
79
|
+
"each continuation.",
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Check indentation on continuation lines (3 spaces after *)
|
|
87
|
+
for (let i = 1; i < descLines.length; i++) {
|
|
88
|
+
const match = descLines[i].raw.match(/^\s*\*( *)/);
|
|
89
|
+
|
|
90
|
+
if (!match || match[1].length !== 3) {
|
|
91
|
+
context.report({
|
|
92
|
+
loc: comment.loc,
|
|
93
|
+
message:
|
|
94
|
+
"Continuation lines in JSDoc description must be indented " +
|
|
95
|
+
"with 3 spaces after '*'.",
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return {
|
|
104
|
+
"Program:exit"() {
|
|
105
|
+
const comments = sourceCode.getAllComments();
|
|
106
|
+
|
|
107
|
+
for (const comment of comments) {
|
|
108
|
+
checkComment(comment);
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
};
|
|
112
|
+
},
|
|
113
|
+
};
|