@soujvnunes/eslint-config 0.7.0 → 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/dist/index.js +37 -27
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -30,16 +30,31 @@ var isBare = (comment) => comment.type === "Line" && comment.value.trim() === ""
|
|
|
30
30
|
var collapse = (text) => text.replace(/\s+/gu, " ").trim();
|
|
31
31
|
var asLine = (body) => body ? `// ${body}` : null;
|
|
32
32
|
var followedOnLine = (comment, after) => !!after?.loc && !!comment.loc && after.loc.start.line === comment.loc.end.line;
|
|
33
|
-
var
|
|
34
|
-
|
|
33
|
+
var blockLines = (comment) => comment.value.replace(/^!/u, "").split(/\r\n|[\r\n\u2028\u2029]/u).map(
|
|
34
|
+
(line) => line.trim().replace(/^\*(?= |$)/u, "").trim()
|
|
35
35
|
);
|
|
36
|
+
var blockBody = (lines) => collapse(lines.filter(Boolean).join(" "));
|
|
37
|
+
var proseParagraphs = (lines, skipTags) => {
|
|
38
|
+
let count = 0;
|
|
39
|
+
let inSegment = false;
|
|
40
|
+
for (const line of lines) {
|
|
41
|
+
if (line === "") {
|
|
42
|
+
inSegment = false;
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
if (inSegment) continue;
|
|
46
|
+
inSegment = true;
|
|
47
|
+
if (!(skipTags && line.startsWith("@"))) count += 1;
|
|
48
|
+
}
|
|
49
|
+
return count;
|
|
50
|
+
};
|
|
36
51
|
var opener = (comment) => {
|
|
37
52
|
if (isDocShaped(comment)) return "/**";
|
|
38
53
|
return isBanner(comment) ? "/*!" : "/*";
|
|
39
54
|
};
|
|
40
|
-
var collapsedBlock = (comment) => {
|
|
55
|
+
var collapsedBlock = (comment, lines) => {
|
|
41
56
|
const open = opener(comment);
|
|
42
|
-
const body = blockBody(
|
|
57
|
+
const body = blockBody(lines);
|
|
43
58
|
const text = body ? `${open} ${body} */` : `${open} */`;
|
|
44
59
|
return text.indexOf("*/") === text.length - 2 ? text : null;
|
|
45
60
|
};
|
|
@@ -58,7 +73,7 @@ var oneLineComments = {
|
|
|
58
73
|
schema: [],
|
|
59
74
|
messages: {
|
|
60
75
|
adjacent: "Two comment lines are touching. A comment is one line, however long it runs: join them, or write one line per fact beside the code it describes.",
|
|
61
|
-
paragraphs: "A bare `//` between comment lines
|
|
76
|
+
paragraphs: "A paragraph break inside a comment, a bare `//` between comment lines or an empty line inside a block, makes it a set of comments rather than one wrapped line, and joining it would bury every fact but the first. Write one line per fact beside the code it describes, or move the rationale to the README or the project MANIFEST.",
|
|
62
77
|
block: "This block comment spans lines. A comment is one line, however long it runs: collapse it to one `//` line, or to one `/** \u2026 */` line when it is JSDoc, or move the rationale to the README or the project MANIFEST.",
|
|
63
78
|
notDoc: "A block comment is for JSDoc and JSX only. Write this one as `//`, on its own line or at the end of one, or delete it if it is empty.",
|
|
64
79
|
orphanDoc: "`/**` is JSDoc, and JSDoc sits directly above the code it documents. Move it there, join it with the doc under it, or write it as `//`."
|
|
@@ -93,13 +108,17 @@ var oneLineComments = {
|
|
|
93
108
|
const before = sourceCode.getTokenBefore(comment, { includeComments: true });
|
|
94
109
|
return !!before?.loc && before.loc.end.line === comment.loc?.start.line && followedOnLine(comment, after);
|
|
95
110
|
};
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
|
|
111
|
+
const blockVerdict = (comment, after) => {
|
|
112
|
+
const lines = blockLines(comment);
|
|
113
|
+
const keepBlock = insideJsx(comment) || isDocShaped(comment) || isBanner(comment);
|
|
114
|
+
const messageId = spansLines(comment) ? "block" : "notDoc";
|
|
115
|
+
if (!insideJsx(comment) && !isBanner(comment) && proseParagraphs(lines, isDocShaped(comment)) > 1) {
|
|
116
|
+
return { messageId: "paragraphs", text: null };
|
|
99
117
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
118
|
+
if (keepBlock) return { messageId, text: collapsedBlock(comment, lines) };
|
|
119
|
+
const body = blockBody(lines);
|
|
120
|
+
const text = followedOnLine(comment, after) || isDirectiveText(body) ? null : asLine(body);
|
|
121
|
+
return { messageId, text };
|
|
103
122
|
};
|
|
104
123
|
return {
|
|
105
124
|
"Program:exit"() {
|
|
@@ -108,10 +127,10 @@ var oneLineComments = {
|
|
|
108
127
|
if (comment.type !== "Block" || isDirective(comment)) continue;
|
|
109
128
|
const after = sourceCode.getTokenAfter(comment, { includeComments: true });
|
|
110
129
|
if (spansLines(comment)) {
|
|
111
|
-
const text2 =
|
|
130
|
+
const { messageId: messageId2, text: text2 } = blockVerdict(comment, after);
|
|
112
131
|
context.report({
|
|
113
132
|
loc: comment.loc,
|
|
114
|
-
messageId:
|
|
133
|
+
messageId: messageId2,
|
|
115
134
|
fix: text2 && !breaksSemicolonInsertion(comment, after) ? (fixer) => fixer.replaceText(comment, text2) : null
|
|
116
135
|
});
|
|
117
136
|
continue;
|
|
@@ -122,10 +141,10 @@ var oneLineComments = {
|
|
|
122
141
|
else context.report({ loc: comment.loc, messageId: "orphanDoc" });
|
|
123
142
|
continue;
|
|
124
143
|
}
|
|
125
|
-
const text =
|
|
144
|
+
const { messageId, text } = blockVerdict(comment, after);
|
|
126
145
|
context.report({
|
|
127
146
|
loc: comment.loc,
|
|
128
|
-
messageId
|
|
147
|
+
messageId,
|
|
129
148
|
fix: text ? (fixer) => fixer.replaceText(comment, text) : null
|
|
130
149
|
});
|
|
131
150
|
}
|
|
@@ -141,18 +160,9 @@ var oneLineComments = {
|
|
|
141
160
|
const last = current[current.length - 1];
|
|
142
161
|
if (!first?.loc || !last?.loc) return;
|
|
143
162
|
const block = current.some((comment) => comment.type === "Block");
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
if (isBare(comment)) inText = false;
|
|
148
|
-
else if (!inText) {
|
|
149
|
-
inText = true;
|
|
150
|
-
segments += 1;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
const paragraphs = segments > 1;
|
|
154
|
-
const body = collapse(current.map((comment) => comment.value.trim()).join(" "));
|
|
155
|
-
const text = asLine(body);
|
|
163
|
+
const texts = current.map((comment) => isBare(comment) ? "" : comment.value.trim() || " ");
|
|
164
|
+
const paragraphs = proseParagraphs(texts, false) > 1;
|
|
165
|
+
const text = asLine(collapse(texts.join(" ")));
|
|
156
166
|
context.report({
|
|
157
167
|
loc: { start: first.loc.start, end: last.loc.end },
|
|
158
168
|
messageId: paragraphs ? "paragraphs" : "adjacent",
|