pickier 0.1.37 → 0.1.38
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/bin/cli.js +654 -581
- package/dist/rules/node/prefer-global-buffer.d.ts +5 -3
- package/dist/rules/node/prefer-global-process.d.ts +5 -3
- package/dist/src/index.js +846 -773
- package/package.json +1 -1
package/dist/bin/cli.js
CHANGED
|
@@ -47,6 +47,287 @@ var __export = (target, all) => {
|
|
|
47
47
|
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
48
48
|
var __require = import.meta.require;
|
|
49
49
|
|
|
50
|
+
// src/rules/shell/_shared.ts
|
|
51
|
+
function maskShellStrings(line) {
|
|
52
|
+
const n = line.length;
|
|
53
|
+
const out = Array.from({ length: n }, (_, i2) => line[i2]);
|
|
54
|
+
let i = 0;
|
|
55
|
+
while (i < n) {
|
|
56
|
+
const ch = line[i];
|
|
57
|
+
if (ch === "#" && (i === 0 || /\s/.test(line[i - 1]))) {
|
|
58
|
+
while (i < n) {
|
|
59
|
+
out[i] = " ";
|
|
60
|
+
i++;
|
|
61
|
+
}
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
if (ch === "$" && line[i + 1] === "'") {
|
|
65
|
+
i += 2;
|
|
66
|
+
while (i < n) {
|
|
67
|
+
if (line[i] === "\\" && i + 1 < n) {
|
|
68
|
+
out[i] = " ";
|
|
69
|
+
out[i + 1] = " ";
|
|
70
|
+
i += 2;
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
if (line[i] === "'") {
|
|
74
|
+
i++;
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
out[i] = " ";
|
|
78
|
+
i++;
|
|
79
|
+
}
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
if (ch === "$" && line[i + 1] === '"') {
|
|
83
|
+
i++;
|
|
84
|
+
i = maskDoubleQuoted(line, i, out);
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
if (ch === "$" && line[i + 1] === "{") {
|
|
88
|
+
i += 2;
|
|
89
|
+
let depth = 1;
|
|
90
|
+
while (i < n && depth > 0) {
|
|
91
|
+
const c = line[i];
|
|
92
|
+
if (c === "\\" && i + 1 < n) {
|
|
93
|
+
out[i] = " ";
|
|
94
|
+
out[i + 1] = " ";
|
|
95
|
+
i += 2;
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
if (c === "'") {
|
|
99
|
+
i++;
|
|
100
|
+
while (i < n && line[i] !== "'") {
|
|
101
|
+
out[i] = " ";
|
|
102
|
+
i++;
|
|
103
|
+
}
|
|
104
|
+
if (i < n)
|
|
105
|
+
i++;
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
if (c === '"') {
|
|
109
|
+
i = maskDoubleQuoted(line, i, out);
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
if (c === "{") {
|
|
113
|
+
depth++;
|
|
114
|
+
i++;
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
if (c === "}") {
|
|
118
|
+
depth--;
|
|
119
|
+
i++;
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
out[i] = " ";
|
|
123
|
+
i++;
|
|
124
|
+
}
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
if (ch === "$" && line[i + 1] === "(" && line[i + 2] === "(") {
|
|
128
|
+
i += 3;
|
|
129
|
+
let depth = 2;
|
|
130
|
+
while (i < n && depth > 0) {
|
|
131
|
+
const c = line[i];
|
|
132
|
+
if (c === "(") {
|
|
133
|
+
depth++;
|
|
134
|
+
i++;
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
if (c === ")") {
|
|
138
|
+
depth--;
|
|
139
|
+
i++;
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
out[i] = " ";
|
|
143
|
+
i++;
|
|
144
|
+
}
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
if (ch === "$" && line[i + 1] === "(") {
|
|
148
|
+
i += 2;
|
|
149
|
+
let depth = 1;
|
|
150
|
+
while (i < n && depth > 0) {
|
|
151
|
+
const c = line[i];
|
|
152
|
+
if (c === "\\" && i + 1 < n) {
|
|
153
|
+
out[i] = " ";
|
|
154
|
+
out[i + 1] = " ";
|
|
155
|
+
i += 2;
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
if (c === "'") {
|
|
159
|
+
i++;
|
|
160
|
+
while (i < n && line[i] !== "'") {
|
|
161
|
+
out[i] = " ";
|
|
162
|
+
i++;
|
|
163
|
+
}
|
|
164
|
+
if (i < n)
|
|
165
|
+
i++;
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
if (c === '"') {
|
|
169
|
+
i = maskDoubleQuoted(line, i, out);
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
if (c === "(") {
|
|
173
|
+
depth++;
|
|
174
|
+
i++;
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
177
|
+
if (c === ")") {
|
|
178
|
+
depth--;
|
|
179
|
+
i++;
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
182
|
+
out[i] = " ";
|
|
183
|
+
i++;
|
|
184
|
+
}
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
if (ch === "'") {
|
|
188
|
+
i++;
|
|
189
|
+
while (i < n && line[i] !== "'") {
|
|
190
|
+
out[i] = " ";
|
|
191
|
+
i++;
|
|
192
|
+
}
|
|
193
|
+
if (i < n)
|
|
194
|
+
i++;
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
if (ch === '"') {
|
|
198
|
+
i = maskDoubleQuoted(line, i, out);
|
|
199
|
+
continue;
|
|
200
|
+
}
|
|
201
|
+
if (ch === "`") {
|
|
202
|
+
i++;
|
|
203
|
+
while (i < n && line[i] !== "`") {
|
|
204
|
+
if (line[i] === "\\" && i + 1 < n) {
|
|
205
|
+
out[i] = " ";
|
|
206
|
+
out[i + 1] = " ";
|
|
207
|
+
i += 2;
|
|
208
|
+
continue;
|
|
209
|
+
}
|
|
210
|
+
out[i] = " ";
|
|
211
|
+
i++;
|
|
212
|
+
}
|
|
213
|
+
if (i < n)
|
|
214
|
+
i++;
|
|
215
|
+
continue;
|
|
216
|
+
}
|
|
217
|
+
i++;
|
|
218
|
+
}
|
|
219
|
+
return out.join("");
|
|
220
|
+
}
|
|
221
|
+
function maskDoubleQuoted(line, start, out) {
|
|
222
|
+
const n = line.length;
|
|
223
|
+
let i = start + 1;
|
|
224
|
+
while (i < n) {
|
|
225
|
+
const c = line[i];
|
|
226
|
+
if (c === "\\" && i + 1 < n) {
|
|
227
|
+
out[i] = " ";
|
|
228
|
+
out[i + 1] = " ";
|
|
229
|
+
i += 2;
|
|
230
|
+
continue;
|
|
231
|
+
}
|
|
232
|
+
if (c === '"')
|
|
233
|
+
return i + 1;
|
|
234
|
+
if (c === "$" && line[i + 1] === "(" && line[i + 2] === "(") {
|
|
235
|
+
i += 3;
|
|
236
|
+
let depth = 2;
|
|
237
|
+
while (i < n && depth > 0) {
|
|
238
|
+
const x = line[i];
|
|
239
|
+
if (x === "(") {
|
|
240
|
+
depth++;
|
|
241
|
+
i++;
|
|
242
|
+
continue;
|
|
243
|
+
}
|
|
244
|
+
if (x === ")") {
|
|
245
|
+
depth--;
|
|
246
|
+
i++;
|
|
247
|
+
continue;
|
|
248
|
+
}
|
|
249
|
+
out[i] = " ";
|
|
250
|
+
i++;
|
|
251
|
+
}
|
|
252
|
+
continue;
|
|
253
|
+
}
|
|
254
|
+
if (c === "$" && line[i + 1] === "(") {
|
|
255
|
+
i += 2;
|
|
256
|
+
let depth = 1;
|
|
257
|
+
while (i < n && depth > 0) {
|
|
258
|
+
const x = line[i];
|
|
259
|
+
if (x === "\\" && i + 1 < n) {
|
|
260
|
+
out[i] = " ";
|
|
261
|
+
out[i + 1] = " ";
|
|
262
|
+
i += 2;
|
|
263
|
+
continue;
|
|
264
|
+
}
|
|
265
|
+
if (x === "'") {
|
|
266
|
+
i++;
|
|
267
|
+
while (i < n && line[i] !== "'") {
|
|
268
|
+
out[i] = " ";
|
|
269
|
+
i++;
|
|
270
|
+
}
|
|
271
|
+
if (i < n)
|
|
272
|
+
i++;
|
|
273
|
+
continue;
|
|
274
|
+
}
|
|
275
|
+
if (x === '"') {
|
|
276
|
+
i = maskDoubleQuoted(line, i, out);
|
|
277
|
+
continue;
|
|
278
|
+
}
|
|
279
|
+
if (x === "(") {
|
|
280
|
+
depth++;
|
|
281
|
+
i++;
|
|
282
|
+
continue;
|
|
283
|
+
}
|
|
284
|
+
if (x === ")") {
|
|
285
|
+
depth--;
|
|
286
|
+
i++;
|
|
287
|
+
continue;
|
|
288
|
+
}
|
|
289
|
+
out[i] = " ";
|
|
290
|
+
i++;
|
|
291
|
+
}
|
|
292
|
+
continue;
|
|
293
|
+
}
|
|
294
|
+
if (c === "$" && line[i + 1] === "{") {
|
|
295
|
+
i += 2;
|
|
296
|
+
let depth = 1;
|
|
297
|
+
while (i < n && depth > 0) {
|
|
298
|
+
const x = line[i];
|
|
299
|
+
if (x === "{") {
|
|
300
|
+
depth++;
|
|
301
|
+
i++;
|
|
302
|
+
continue;
|
|
303
|
+
}
|
|
304
|
+
if (x === "}") {
|
|
305
|
+
depth--;
|
|
306
|
+
i++;
|
|
307
|
+
continue;
|
|
308
|
+
}
|
|
309
|
+
out[i] = " ";
|
|
310
|
+
i++;
|
|
311
|
+
}
|
|
312
|
+
continue;
|
|
313
|
+
}
|
|
314
|
+
out[i] = " ";
|
|
315
|
+
i++;
|
|
316
|
+
}
|
|
317
|
+
return i;
|
|
318
|
+
}
|
|
319
|
+
function heredocDelimiter(line) {
|
|
320
|
+
const masked = maskShellStrings(line);
|
|
321
|
+
const m = masked.match(/<<-?/);
|
|
322
|
+
if (!m || m.index === undefined)
|
|
323
|
+
return null;
|
|
324
|
+
const after = line.slice(m.index + m[0].length);
|
|
325
|
+
const delim = after.match(/^\s*(['"]?)(\w+)\1/);
|
|
326
|
+
if (!delim)
|
|
327
|
+
return null;
|
|
328
|
+
return delim[2];
|
|
329
|
+
}
|
|
330
|
+
|
|
50
331
|
// src/format.ts
|
|
51
332
|
function isHangingControlLine(code) {
|
|
52
333
|
const m = RE_CONTROL_OPEN.exec(code);
|
|
@@ -124,10 +405,10 @@ function processShellLinesFused(content, cfg) {
|
|
|
124
405
|
}
|
|
125
406
|
continue;
|
|
126
407
|
}
|
|
127
|
-
const
|
|
128
|
-
if (
|
|
408
|
+
const delim = heredocDelimiter(line);
|
|
409
|
+
if (delim) {
|
|
129
410
|
inHeredoc = true;
|
|
130
|
-
heredocDelim =
|
|
411
|
+
heredocDelim = delim;
|
|
131
412
|
}
|
|
132
413
|
let wsEnd = 0;
|
|
133
414
|
while (wsEnd < line.length && (line.charCodeAt(wsEnd) === 32 || line.charCodeAt(wsEnd) === 9))
|
|
@@ -197,16 +478,25 @@ function makeIndent(visualLevels, cfg) {
|
|
|
197
478
|
}
|
|
198
479
|
function convertDoubleToSingle(str) {
|
|
199
480
|
const inner = str.slice(1, -1);
|
|
200
|
-
|
|
201
|
-
result = result.replace(/'/g, '"');
|
|
481
|
+
const result = inner.replace(/\\"/g, '"');
|
|
202
482
|
return `'${result}'`;
|
|
203
483
|
}
|
|
204
484
|
function convertSingleToDouble(str) {
|
|
205
485
|
const inner = str.slice(1, -1);
|
|
206
|
-
|
|
207
|
-
result = result.replace(/"/g, "'");
|
|
486
|
+
const result = inner.replace(/\\'/g, "'");
|
|
208
487
|
return `"${result}"`;
|
|
209
488
|
}
|
|
489
|
+
function hasUnescapedChar(content, ch) {
|
|
490
|
+
for (let i = 0;i < content.length; i++) {
|
|
491
|
+
if (content[i] === "\\") {
|
|
492
|
+
i++;
|
|
493
|
+
continue;
|
|
494
|
+
}
|
|
495
|
+
if (content[i] === ch)
|
|
496
|
+
return true;
|
|
497
|
+
}
|
|
498
|
+
return false;
|
|
499
|
+
}
|
|
210
500
|
function fixQuotes(content, preferred, filePath) {
|
|
211
501
|
if (!isCodeFileExt(filePath))
|
|
212
502
|
return content;
|
|
@@ -281,11 +571,12 @@ function fixQuotesLine(line, preferred) {
|
|
|
281
571
|
}
|
|
282
572
|
const closeChar = inString === 1 ? "'" : '"';
|
|
283
573
|
if (ch === closeChar) {
|
|
284
|
-
const
|
|
574
|
+
const stringContent = line.slice(stringStart + 1, i);
|
|
575
|
+
const targetQuote = wantSingle ? "'" : '"';
|
|
576
|
+
const needConvert = (inString === 2 && wantSingle || inString === 1 && !wantSingle) && !hasUnescapedChar(stringContent, targetQuote);
|
|
285
577
|
if (needConvert) {
|
|
286
578
|
if (stringStart > segStart)
|
|
287
579
|
parts.push(line.slice(segStart, stringStart));
|
|
288
|
-
const stringContent = line.slice(stringStart + 1, i);
|
|
289
580
|
if (inString === 2)
|
|
290
581
|
parts.push(convertDoubleToSingle(`"${stringContent}"`));
|
|
291
582
|
else
|
|
@@ -661,6 +952,20 @@ function formatCode(src, cfg, filePath) {
|
|
|
661
952
|
return `${joined}
|
|
662
953
|
`;
|
|
663
954
|
}
|
|
955
|
+
function quoteConvertible(line, openIdx, quote, target) {
|
|
956
|
+
for (let j = openIdx + 1;j < line.length; j++) {
|
|
957
|
+
const c = line[j];
|
|
958
|
+
if (c === "\\") {
|
|
959
|
+
j++;
|
|
960
|
+
continue;
|
|
961
|
+
}
|
|
962
|
+
if (c === quote)
|
|
963
|
+
return true;
|
|
964
|
+
if (c === target)
|
|
965
|
+
return false;
|
|
966
|
+
}
|
|
967
|
+
return true;
|
|
968
|
+
}
|
|
664
969
|
function detectQuoteIssues(line, preferred) {
|
|
665
970
|
if (/^\s*\/\/\/\s*<reference/.test(line)) {
|
|
666
971
|
return [];
|
|
@@ -679,21 +984,18 @@ function detectQuoteIssues(line, preferred) {
|
|
|
679
984
|
continue;
|
|
680
985
|
}
|
|
681
986
|
if (!inString) {
|
|
987
|
+
if (ch === "/" && line[i + 1] === "/") {
|
|
988
|
+
break;
|
|
989
|
+
}
|
|
682
990
|
if (ch === "'") {
|
|
683
|
-
if (preferred === "double") {
|
|
684
|
-
|
|
685
|
-
if (beforeSlash === -1 || beforeSlash > i) {
|
|
686
|
-
indices.push(i);
|
|
687
|
-
}
|
|
991
|
+
if (preferred === "double" && quoteConvertible(line, i, "'", '"')) {
|
|
992
|
+
indices.push(i);
|
|
688
993
|
}
|
|
689
994
|
inString = "single";
|
|
690
995
|
continue;
|
|
691
996
|
} else if (ch === '"') {
|
|
692
|
-
if (preferred === "single") {
|
|
693
|
-
|
|
694
|
-
if (beforeSlash === -1 || beforeSlash > i) {
|
|
695
|
-
indices.push(i);
|
|
696
|
-
}
|
|
997
|
+
if (preferred === "single" && quoteConvertible(line, i, '"', "'")) {
|
|
998
|
+
indices.push(i);
|
|
697
999
|
}
|
|
698
1000
|
inString = "double";
|
|
699
1001
|
continue;
|
|
@@ -783,16 +1085,20 @@ function isRegexStart(input, slashIdx) {
|
|
|
783
1085
|
function scanRegexEnd(input, start) {
|
|
784
1086
|
let i = start + 1;
|
|
785
1087
|
let inClass = false;
|
|
1088
|
+
let classStart = -1;
|
|
786
1089
|
while (i < input.length) {
|
|
787
1090
|
const c = input[i];
|
|
788
1091
|
if (c === "\\") {
|
|
789
1092
|
i += 2;
|
|
790
1093
|
continue;
|
|
791
1094
|
}
|
|
792
|
-
if (c === "[") {
|
|
1095
|
+
if (c === "[" && !inClass) {
|
|
793
1096
|
inClass = true;
|
|
794
|
-
|
|
795
|
-
|
|
1097
|
+
classStart = i;
|
|
1098
|
+
} else if (c === "]" && inClass) {
|
|
1099
|
+
const bodyStart = input[classStart + 1] === "^" ? classStart + 2 : classStart + 1;
|
|
1100
|
+
if (i !== bodyStart)
|
|
1101
|
+
inClass = false;
|
|
796
1102
|
} else if (c === "/" && !inClass) {
|
|
797
1103
|
i++;
|
|
798
1104
|
while (i < input.length && /[a-z]/i.test(input[i]))
|
|
@@ -10589,7 +10895,7 @@ function createIgnoreMatcher(ignoreGlobs, cwd = process19.cwd()) {
|
|
|
10589
10895
|
return (absPath) => {
|
|
10590
10896
|
const normalizedAbs = toPosixPath(absPath);
|
|
10591
10897
|
const normalizedCwd = toPosixPath(cwd).replace(/\/$/, "");
|
|
10592
|
-
const isOutsideProject = !normalizedAbs.startsWith(normalizedCwd);
|
|
10898
|
+
const isOutsideProject = normalizedAbs !== normalizedCwd && !normalizedAbs.startsWith(`${normalizedCwd}/`);
|
|
10593
10899
|
const rel = isOutsideProject ? normalizedAbs : normalizedAbs.slice(normalizedCwd.length);
|
|
10594
10900
|
for (const pattern of compiled) {
|
|
10595
10901
|
if (isOutsideProject && !universalRaw.has(pattern.raw))
|
|
@@ -19230,7 +19536,7 @@ var init_no_empty = __esm(() => {
|
|
|
19230
19536
|
const beforeBlock = line.substring(0, line.lastIndexOf("{")).trim();
|
|
19231
19537
|
const isStatementBlock = /(?:if|else|for|while|do|try|catch|finally|function|\})\s*$/.test(beforeBlock);
|
|
19232
19538
|
const isObjectLiteral = /[=:]$/.test(beforeBlock) || /return\s*$/.test(beforeBlock);
|
|
19233
|
-
if (isStatementBlock && !isObjectLiteral
|
|
19539
|
+
if (isStatementBlock && !isObjectLiteral) {
|
|
19234
19540
|
issues.push({
|
|
19235
19541
|
filePath: ctx.filePath,
|
|
19236
19542
|
line: i + 1,
|
|
@@ -22658,7 +22964,9 @@ var init_prefer_const = __esm(() => {
|
|
|
22658
22964
|
for (const { name, fixable } of decls) {
|
|
22659
22965
|
if (!fixable)
|
|
22660
22966
|
continue;
|
|
22661
|
-
|
|
22967
|
+
const wordIdx = line.search(new RegExp(`\\b${name.replace(/\$/g, "\\$")}\\b`));
|
|
22968
|
+
const nameIdx = wordIdx !== -1 ? wordIdx : line.indexOf(name);
|
|
22969
|
+
issues.push({ filePath: ctx.filePath, line: i + 1, column: Math.max(1, nameIdx + 1), ruleId: "prefer-const", message: `'${name}' is never reassigned. Use 'const' instead`, severity: "error", help: `Change 'let ${name}' to 'const ${name}' since the variable is never reassigned. This makes your code more predictable and prevents accidental mutations` });
|
|
22662
22970
|
}
|
|
22663
22971
|
}
|
|
22664
22972
|
return issues;
|
|
@@ -24159,6 +24467,33 @@ var init_code_block_style = __esm(() => {
|
|
|
24159
24467
|
});
|
|
24160
24468
|
|
|
24161
24469
|
// src/rules/markdown/code-fence-style.ts
|
|
24470
|
+
function fenceBoundaryLines(lines) {
|
|
24471
|
+
const out = new Set;
|
|
24472
|
+
let fenceChar = null;
|
|
24473
|
+
let fenceLen = 0;
|
|
24474
|
+
for (let i = 0;i < lines.length; i++) {
|
|
24475
|
+
const trimmed = lines[i].trim();
|
|
24476
|
+
if (fenceChar === null) {
|
|
24477
|
+
const open = trimmed.match(/^(`{3,}|~{3,})(.*)$/);
|
|
24478
|
+
if (open) {
|
|
24479
|
+
const ch = open[1][0];
|
|
24480
|
+
if (ch === "`" && open[2].includes("`"))
|
|
24481
|
+
continue;
|
|
24482
|
+
fenceChar = ch;
|
|
24483
|
+
fenceLen = open[1].length;
|
|
24484
|
+
out.add(i);
|
|
24485
|
+
}
|
|
24486
|
+
} else {
|
|
24487
|
+
const close = trimmed.match(/^(`{3,}|~{3,})\s*$/);
|
|
24488
|
+
if (close && close[1][0] === fenceChar && close[1].length >= fenceLen) {
|
|
24489
|
+
out.add(i);
|
|
24490
|
+
fenceChar = null;
|
|
24491
|
+
fenceLen = 0;
|
|
24492
|
+
}
|
|
24493
|
+
}
|
|
24494
|
+
}
|
|
24495
|
+
return out;
|
|
24496
|
+
}
|
|
24162
24497
|
var codeFenceStyleRule;
|
|
24163
24498
|
var init_code_fence_style = __esm(() => {
|
|
24164
24499
|
codeFenceStyleRule = {
|
|
@@ -24168,60 +24503,37 @@ var init_code_fence_style = __esm(() => {
|
|
|
24168
24503
|
check: (text, ctx) => {
|
|
24169
24504
|
const issues = [];
|
|
24170
24505
|
const lines = text.split(/\r?\n/);
|
|
24506
|
+
const boundaries = fenceBoundaryLines(lines);
|
|
24171
24507
|
const options = ctx.options || {};
|
|
24172
24508
|
const style = options.style || "consistent";
|
|
24173
24509
|
let detectedStyle = null;
|
|
24174
|
-
for (
|
|
24510
|
+
for (const i of boundaries) {
|
|
24175
24511
|
const line = lines[i];
|
|
24176
|
-
const isBacktick = /^`{3,}/.test(line);
|
|
24177
|
-
const
|
|
24178
|
-
if (
|
|
24179
|
-
if (
|
|
24512
|
+
const isBacktick = /^`{3,}/.test(line.trim());
|
|
24513
|
+
const fenceStyle = isBacktick ? "backtick" : "tilde";
|
|
24514
|
+
if (style === "backtick" || style === "tilde") {
|
|
24515
|
+
if (fenceStyle !== style) {
|
|
24180
24516
|
issues.push({
|
|
24181
24517
|
filePath: ctx.filePath,
|
|
24182
24518
|
line: i + 1,
|
|
24183
24519
|
column: 1,
|
|
24184
24520
|
ruleId: "markdown/code-fence-style",
|
|
24185
|
-
message: "Expected tilde (~~~) code fence",
|
|
24521
|
+
message: style === "tilde" ? "Expected tilde (~~~) code fence" : "Expected backtick (```) code fence",
|
|
24186
24522
|
severity: "error"
|
|
24187
24523
|
});
|
|
24188
|
-
} else if (style === "consistent") {
|
|
24189
|
-
if (detectedStyle === null) {
|
|
24190
|
-
detectedStyle = "backtick";
|
|
24191
|
-
} else if (detectedStyle === "tilde") {
|
|
24192
|
-
issues.push({
|
|
24193
|
-
filePath: ctx.filePath,
|
|
24194
|
-
line: i + 1,
|
|
24195
|
-
column: 1,
|
|
24196
|
-
ruleId: "markdown/code-fence-style",
|
|
24197
|
-
message: "Code fence style should be consistent throughout document",
|
|
24198
|
-
severity: "error"
|
|
24199
|
-
});
|
|
24200
|
-
}
|
|
24201
24524
|
}
|
|
24202
|
-
} else if (
|
|
24203
|
-
if (
|
|
24525
|
+
} else if (style === "consistent") {
|
|
24526
|
+
if (detectedStyle === null) {
|
|
24527
|
+
detectedStyle = fenceStyle;
|
|
24528
|
+
} else if (detectedStyle !== fenceStyle) {
|
|
24204
24529
|
issues.push({
|
|
24205
24530
|
filePath: ctx.filePath,
|
|
24206
24531
|
line: i + 1,
|
|
24207
24532
|
column: 1,
|
|
24208
24533
|
ruleId: "markdown/code-fence-style",
|
|
24209
|
-
message: "
|
|
24534
|
+
message: "Code fence style should be consistent throughout document",
|
|
24210
24535
|
severity: "error"
|
|
24211
24536
|
});
|
|
24212
|
-
} else if (style === "consistent") {
|
|
24213
|
-
if (detectedStyle === null) {
|
|
24214
|
-
detectedStyle = "tilde";
|
|
24215
|
-
} else if (detectedStyle === "backtick") {
|
|
24216
|
-
issues.push({
|
|
24217
|
-
filePath: ctx.filePath,
|
|
24218
|
-
line: i + 1,
|
|
24219
|
-
column: 1,
|
|
24220
|
-
ruleId: "markdown/code-fence-style",
|
|
24221
|
-
message: "Code fence style should be consistent throughout document",
|
|
24222
|
-
severity: "error"
|
|
24223
|
-
});
|
|
24224
|
-
}
|
|
24225
24537
|
}
|
|
24226
24538
|
}
|
|
24227
24539
|
}
|
|
@@ -24231,32 +24543,22 @@ var init_code_fence_style = __esm(() => {
|
|
|
24231
24543
|
const options = ctx.options || {};
|
|
24232
24544
|
const style = options.style || "consistent";
|
|
24233
24545
|
const lines = text.split(/\r?\n/);
|
|
24546
|
+
const boundaries = fenceBoundaryLines(lines);
|
|
24234
24547
|
let targetStyle = "backtick";
|
|
24235
|
-
if (style === "backtick") {
|
|
24236
|
-
targetStyle =
|
|
24237
|
-
} else
|
|
24238
|
-
|
|
24239
|
-
|
|
24240
|
-
|
|
24241
|
-
if (/^`{3,}/.test(line)) {
|
|
24242
|
-
targetStyle = "backtick";
|
|
24243
|
-
break;
|
|
24244
|
-
} else if (/^~{3,}/.test(line)) {
|
|
24245
|
-
targetStyle = "tilde";
|
|
24246
|
-
break;
|
|
24247
|
-
}
|
|
24548
|
+
if (style === "backtick" || style === "tilde") {
|
|
24549
|
+
targetStyle = style;
|
|
24550
|
+
} else {
|
|
24551
|
+
for (const i of boundaries) {
|
|
24552
|
+
targetStyle = /^`{3,}/.test(lines[i].trim()) ? "backtick" : "tilde";
|
|
24553
|
+
break;
|
|
24248
24554
|
}
|
|
24249
24555
|
}
|
|
24250
|
-
const
|
|
24251
|
-
|
|
24252
|
-
|
|
24253
|
-
|
|
24254
|
-
|
|
24255
|
-
|
|
24256
|
-
return line.replace(/^(`{3,})(.*)$/, (_match, _backticks, rest) => {
|
|
24257
|
-
return `~~~${rest}`;
|
|
24258
|
-
});
|
|
24259
|
-
}
|
|
24556
|
+
const targetChar = targetStyle === "backtick" ? "`" : "~";
|
|
24557
|
+
const sourceRun = targetStyle === "backtick" ? /^(\s*)(~{3,})(.*)$/ : /^(\s*)(`{3,})(.*)$/;
|
|
24558
|
+
const fixedLines = lines.map((line, i) => {
|
|
24559
|
+
if (!boundaries.has(i))
|
|
24560
|
+
return line;
|
|
24561
|
+
return line.replace(sourceRun, (_m, ws, run, rest) => `${ws}${targetChar.repeat(run.length)}${rest}`);
|
|
24260
24562
|
});
|
|
24261
24563
|
return fixedLines.join(`
|
|
24262
24564
|
`);
|
|
@@ -24374,16 +24676,12 @@ var init_emphasis_style = __esm(() => {
|
|
|
24374
24676
|
const options = ctx.options || {};
|
|
24375
24677
|
const style = options.style || "consistent";
|
|
24376
24678
|
let detectedStyle = null;
|
|
24377
|
-
|
|
24679
|
+
const inCode = getCodeBlockLines(lines);
|
|
24378
24680
|
for (let i = 0;i < lines.length; i++) {
|
|
24379
24681
|
const line = lines[i];
|
|
24380
|
-
if (
|
|
24381
|
-
inFence = !inFence;
|
|
24382
|
-
continue;
|
|
24383
|
-
}
|
|
24384
|
-
if (inFence)
|
|
24682
|
+
if (inCode.has(i))
|
|
24385
24683
|
continue;
|
|
24386
|
-
const stripped = line
|
|
24684
|
+
const stripped = maskInlineCode(line);
|
|
24387
24685
|
const asteriskMatches = stripped.matchAll(/(?<!\*)\*(?!\*)([^*]+)\*(?!\*)/g);
|
|
24388
24686
|
for (const match of asteriskMatches) {
|
|
24389
24687
|
if (style === "underscore") {
|
|
@@ -25359,15 +25657,11 @@ var init_no_bare_urls = __esm(() => {
|
|
|
25359
25657
|
check: (text, ctx) => {
|
|
25360
25658
|
const issues = [];
|
|
25361
25659
|
const lines = text.split(/\r?\n/);
|
|
25362
|
-
|
|
25660
|
+
const codeLines = getCodeBlockLines(lines);
|
|
25363
25661
|
let inHtmlComment = false;
|
|
25364
25662
|
for (let i = 0;i < lines.length; i++) {
|
|
25365
25663
|
const line = lines[i];
|
|
25366
|
-
if (
|
|
25367
|
-
inFence = !inFence;
|
|
25368
|
-
continue;
|
|
25369
|
-
}
|
|
25370
|
-
if (inFence)
|
|
25664
|
+
if (codeLines.has(i))
|
|
25371
25665
|
continue;
|
|
25372
25666
|
if (line.includes("<!--"))
|
|
25373
25667
|
inHtmlComment = true;
|
|
@@ -25397,14 +25691,10 @@ var init_no_bare_urls = __esm(() => {
|
|
|
25397
25691
|
},
|
|
25398
25692
|
fix: (text) => {
|
|
25399
25693
|
const lines = text.split(/\r?\n/);
|
|
25400
|
-
|
|
25694
|
+
const codeLines = getCodeBlockLines(lines);
|
|
25401
25695
|
let inHtmlComment = false;
|
|
25402
|
-
const fixedLines = lines.map((line) => {
|
|
25403
|
-
if (
|
|
25404
|
-
inFence = !inFence;
|
|
25405
|
-
return line;
|
|
25406
|
-
}
|
|
25407
|
-
if (inFence)
|
|
25696
|
+
const fixedLines = lines.map((line, i) => {
|
|
25697
|
+
if (codeLines.has(i))
|
|
25408
25698
|
return line;
|
|
25409
25699
|
if (line.includes("<!--"))
|
|
25410
25700
|
inHtmlComment = true;
|
|
@@ -25726,7 +26016,19 @@ var init_no_hard_tabs = __esm(() => {
|
|
|
25726
26016
|
return issues;
|
|
25727
26017
|
},
|
|
25728
26018
|
fix: (text) => {
|
|
25729
|
-
|
|
26019
|
+
const lines = text.split(/\r?\n/);
|
|
26020
|
+
let inFence = false;
|
|
26021
|
+
const fixed = lines.map((line) => {
|
|
26022
|
+
if (/^(?:`{3,}|~{3,})/.test(line.trim())) {
|
|
26023
|
+
inFence = !inFence;
|
|
26024
|
+
return line;
|
|
26025
|
+
}
|
|
26026
|
+
if (inFence)
|
|
26027
|
+
return line;
|
|
26028
|
+
return line.replace(/\t/g, " ");
|
|
26029
|
+
});
|
|
26030
|
+
return fixed.join(`
|
|
26031
|
+
`);
|
|
25730
26032
|
}
|
|
25731
26033
|
};
|
|
25732
26034
|
});
|
|
@@ -26101,14 +26403,10 @@ var init_no_space_in_code = __esm(() => {
|
|
|
26101
26403
|
check: (text, ctx) => {
|
|
26102
26404
|
const issues = [];
|
|
26103
26405
|
const lines = text.split(/\r?\n/);
|
|
26104
|
-
|
|
26406
|
+
const codeLines = getCodeBlockLines(lines);
|
|
26105
26407
|
for (let i = 0;i < lines.length; i++) {
|
|
26106
26408
|
const line = lines[i];
|
|
26107
|
-
if (
|
|
26108
|
-
inFence = !inFence;
|
|
26109
|
-
continue;
|
|
26110
|
-
}
|
|
26111
|
-
if (inFence)
|
|
26409
|
+
if (codeLines.has(i))
|
|
26112
26410
|
continue;
|
|
26113
26411
|
const codeSpanPattern = /(`+)([\s\S]*?)\1/g;
|
|
26114
26412
|
for (const match of line.matchAll(codeSpanPattern)) {
|
|
@@ -26129,15 +26427,11 @@ var init_no_space_in_code = __esm(() => {
|
|
|
26129
26427
|
},
|
|
26130
26428
|
fix: (text) => {
|
|
26131
26429
|
const lines = text.split(/\r?\n/);
|
|
26132
|
-
|
|
26430
|
+
const codeLines = getCodeBlockLines(lines);
|
|
26133
26431
|
const result = [];
|
|
26134
|
-
for (
|
|
26135
|
-
|
|
26136
|
-
|
|
26137
|
-
result.push(line);
|
|
26138
|
-
continue;
|
|
26139
|
-
}
|
|
26140
|
-
if (inFence) {
|
|
26432
|
+
for (let i = 0;i < lines.length; i++) {
|
|
26433
|
+
const line = lines[i];
|
|
26434
|
+
if (codeLines.has(i)) {
|
|
26141
26435
|
result.push(line);
|
|
26142
26436
|
continue;
|
|
26143
26437
|
}
|
|
@@ -26169,14 +26463,10 @@ var init_no_space_in_emphasis = __esm(() => {
|
|
|
26169
26463
|
check: (text, ctx) => {
|
|
26170
26464
|
const issues = [];
|
|
26171
26465
|
const lines = text.split(/\r?\n/);
|
|
26172
|
-
|
|
26466
|
+
const codeLines = getCodeBlockLines(lines);
|
|
26173
26467
|
for (let i = 0;i < lines.length; i++) {
|
|
26174
26468
|
const line = lines[i];
|
|
26175
|
-
if (
|
|
26176
|
-
inFence = !inFence;
|
|
26177
|
-
continue;
|
|
26178
|
-
}
|
|
26179
|
-
if (inFence)
|
|
26469
|
+
if (codeLines.has(i))
|
|
26180
26470
|
continue;
|
|
26181
26471
|
const stripped = line.replace(/`[^`]+`/g, (m) => "\x01".repeat(m.length));
|
|
26182
26472
|
for (const pattern of EMPHASIS_SPACE_PATTERNS) {
|
|
@@ -26196,15 +26486,11 @@ var init_no_space_in_emphasis = __esm(() => {
|
|
|
26196
26486
|
},
|
|
26197
26487
|
fix: (text) => {
|
|
26198
26488
|
const lines = text.split(/\r?\n/);
|
|
26199
|
-
|
|
26489
|
+
const codeLines = getCodeBlockLines(lines);
|
|
26200
26490
|
const result = [];
|
|
26201
|
-
for (
|
|
26202
|
-
|
|
26203
|
-
|
|
26204
|
-
result.push(line);
|
|
26205
|
-
continue;
|
|
26206
|
-
}
|
|
26207
|
-
if (inFence) {
|
|
26491
|
+
for (let i = 0;i < lines.length; i++) {
|
|
26492
|
+
const line = lines[i];
|
|
26493
|
+
if (codeLines.has(i)) {
|
|
26208
26494
|
result.push(line);
|
|
26209
26495
|
continue;
|
|
26210
26496
|
}
|
|
@@ -26319,7 +26605,14 @@ var init_no_trailing_punctuation = __esm(() => {
|
|
|
26319
26605
|
const punctuation = options.punctuation || ".,;:!?";
|
|
26320
26606
|
const punctRegex = new RegExp(`[${punctuation.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}]+$`);
|
|
26321
26607
|
const lines = text.split(/\r?\n/);
|
|
26608
|
+
let inFence = false;
|
|
26322
26609
|
const fixedLines = lines.map((line, i) => {
|
|
26610
|
+
if (/^(?:`{3,}|~{3,})/.test(line.trim())) {
|
|
26611
|
+
inFence = !inFence;
|
|
26612
|
+
return line;
|
|
26613
|
+
}
|
|
26614
|
+
if (inFence)
|
|
26615
|
+
return line;
|
|
26323
26616
|
const atxMatch = line.match(/^(#{1,6}\s+)(.+?)(\s*#+\s*)?$/);
|
|
26324
26617
|
if (atxMatch) {
|
|
26325
26618
|
const prefix = atxMatch[1];
|
|
@@ -27160,17 +27453,13 @@ var init_ul_style = __esm(() => {
|
|
|
27160
27453
|
check: (text, ctx) => {
|
|
27161
27454
|
const issues = [];
|
|
27162
27455
|
const lines = text.split(/\r?\n/);
|
|
27456
|
+
const codeLines = getCodeBlockLines(lines);
|
|
27163
27457
|
const options = ctx.options || {};
|
|
27164
27458
|
const style = options.style || "consistent";
|
|
27165
27459
|
let detectedStyle = null;
|
|
27166
|
-
let inFence = false;
|
|
27167
27460
|
for (let i = 0;i < lines.length; i++) {
|
|
27168
27461
|
const line = lines[i];
|
|
27169
|
-
if (
|
|
27170
|
-
inFence = !inFence;
|
|
27171
|
-
continue;
|
|
27172
|
-
}
|
|
27173
|
-
if (inFence)
|
|
27462
|
+
if (codeLines.has(i))
|
|
27174
27463
|
continue;
|
|
27175
27464
|
const match = line.match(/^(\s*)([*\-+])\s+/);
|
|
27176
27465
|
if (match) {
|
|
@@ -27224,6 +27513,7 @@ var init_ul_style = __esm(() => {
|
|
|
27224
27513
|
const options = ctx.options || {};
|
|
27225
27514
|
const style = options.style || "consistent";
|
|
27226
27515
|
const lines = text.split(/\r?\n/);
|
|
27516
|
+
const codeLines = getCodeBlockLines(lines);
|
|
27227
27517
|
let targetMarker = "*";
|
|
27228
27518
|
if (style === "asterisk") {
|
|
27229
27519
|
targetMarker = "*";
|
|
@@ -27232,21 +27522,18 @@ var init_ul_style = __esm(() => {
|
|
|
27232
27522
|
} else if (style === "plus") {
|
|
27233
27523
|
targetMarker = "+";
|
|
27234
27524
|
} else if (style === "consistent") {
|
|
27235
|
-
for (
|
|
27236
|
-
|
|
27525
|
+
for (let i = 0;i < lines.length; i++) {
|
|
27526
|
+
if (codeLines.has(i))
|
|
27527
|
+
continue;
|
|
27528
|
+
const match = lines[i].match(/^(\s*)([*\-+])\s+/);
|
|
27237
27529
|
if (match) {
|
|
27238
27530
|
targetMarker = match[2];
|
|
27239
27531
|
break;
|
|
27240
27532
|
}
|
|
27241
27533
|
}
|
|
27242
27534
|
}
|
|
27243
|
-
|
|
27244
|
-
|
|
27245
|
-
if (/^(?:`{3,}|~{3,})/.test(line.trim())) {
|
|
27246
|
-
inFence = !inFence;
|
|
27247
|
-
return line;
|
|
27248
|
-
}
|
|
27249
|
-
if (inFence)
|
|
27535
|
+
const fixedLines = lines.map((line, i) => {
|
|
27536
|
+
if (codeLines.has(i))
|
|
27250
27537
|
return line;
|
|
27251
27538
|
return line.replace(/^(\s*)([*\-+])(\s+)/, `$1${targetMarker}$3`);
|
|
27252
27539
|
});
|
|
@@ -27450,36 +27737,26 @@ var init_prefer_global_buffer = __esm(() => {
|
|
|
27450
27737
|
check(content, context) {
|
|
27451
27738
|
const issues = [];
|
|
27452
27739
|
const lines = content.split(/\r?\n/);
|
|
27453
|
-
const
|
|
27454
|
-
|
|
27455
|
-
|
|
27456
|
-
|
|
27457
|
-
|
|
27458
|
-
|
|
27459
|
-
|
|
27460
|
-
|
|
27461
|
-
|
|
27462
|
-
|
|
27463
|
-
|
|
27464
|
-
|
|
27465
|
-
|
|
27466
|
-
|
|
27467
|
-
|
|
27468
|
-
|
|
27469
|
-
|
|
27470
|
-
|
|
27471
|
-
|
|
27472
|
-
|
|
27473
|
-
line: i + 1,
|
|
27474
|
-
column,
|
|
27475
|
-
ruleId: "node/prefer-global/buffer",
|
|
27476
|
-
message: `Unexpected use of the global variable 'Buffer'. Use 'require("buffer").Buffer' instead`,
|
|
27477
|
-
severity: "error",
|
|
27478
|
-
help: 'Import Buffer explicitly: const { Buffer } = require("buffer")'
|
|
27479
|
-
});
|
|
27480
|
-
}
|
|
27481
|
-
}
|
|
27482
|
-
}
|
|
27740
|
+
const importRe = /(?:import\b[^;\n]*\bfrom\s*|require\s*\(\s*)['"](?:node:)?buffer['"]/;
|
|
27741
|
+
for (let i = 0;i < lines.length; i++) {
|
|
27742
|
+
const line = lines[i];
|
|
27743
|
+
const trimmed = line.trim();
|
|
27744
|
+
if (trimmed.startsWith("//") || trimmed.startsWith("/*") || trimmed.startsWith("*"))
|
|
27745
|
+
continue;
|
|
27746
|
+
const match = line.match(importRe);
|
|
27747
|
+
if (!match || match.index === undefined)
|
|
27748
|
+
continue;
|
|
27749
|
+
if (!/\bBuffer\b/.test(line))
|
|
27750
|
+
continue;
|
|
27751
|
+
issues.push({
|
|
27752
|
+
filePath: context.filePath,
|
|
27753
|
+
line: i + 1,
|
|
27754
|
+
column: match.index + 1,
|
|
27755
|
+
ruleId: "node/prefer-global/buffer",
|
|
27756
|
+
message: "Unexpected import of 'Buffer'. Use the global 'Buffer' instead",
|
|
27757
|
+
severity: "error",
|
|
27758
|
+
help: "`Buffer` is a global in Node.js \u2014 remove the import and use it directly."
|
|
27759
|
+
});
|
|
27483
27760
|
}
|
|
27484
27761
|
return issues;
|
|
27485
27762
|
}
|
|
@@ -27497,36 +27774,24 @@ var init_prefer_global_process = __esm(() => {
|
|
|
27497
27774
|
check(content, context) {
|
|
27498
27775
|
const issues = [];
|
|
27499
27776
|
const lines = content.split(/\r?\n/);
|
|
27500
|
-
const
|
|
27501
|
-
|
|
27502
|
-
|
|
27503
|
-
|
|
27504
|
-
|
|
27505
|
-
|
|
27506
|
-
|
|
27507
|
-
|
|
27508
|
-
|
|
27509
|
-
|
|
27510
|
-
|
|
27511
|
-
|
|
27512
|
-
|
|
27513
|
-
|
|
27514
|
-
|
|
27515
|
-
|
|
27516
|
-
|
|
27517
|
-
|
|
27518
|
-
issues.push({
|
|
27519
|
-
filePath: context.filePath,
|
|
27520
|
-
line: i + 1,
|
|
27521
|
-
column,
|
|
27522
|
-
ruleId: "node/prefer-global/process",
|
|
27523
|
-
message: `Unexpected use of the global variable 'process'. Use 'require("process")' instead`,
|
|
27524
|
-
severity: "error",
|
|
27525
|
-
help: 'Import process explicitly: const process = require("process")'
|
|
27526
|
-
});
|
|
27527
|
-
}
|
|
27528
|
-
}
|
|
27529
|
-
}
|
|
27777
|
+
const importRe = /(?:import\b[^;\n]*\bfrom\s*|require\s*\(\s*)['"](?:node:)?process['"]/;
|
|
27778
|
+
for (let i = 0;i < lines.length; i++) {
|
|
27779
|
+
const line = lines[i];
|
|
27780
|
+
const trimmed = line.trim();
|
|
27781
|
+
if (trimmed.startsWith("//") || trimmed.startsWith("/*") || trimmed.startsWith("*"))
|
|
27782
|
+
continue;
|
|
27783
|
+
const match = line.match(importRe);
|
|
27784
|
+
if (!match || match.index === undefined)
|
|
27785
|
+
continue;
|
|
27786
|
+
issues.push({
|
|
27787
|
+
filePath: context.filePath,
|
|
27788
|
+
line: i + 1,
|
|
27789
|
+
column: match.index + 1,
|
|
27790
|
+
ruleId: "node/prefer-global/process",
|
|
27791
|
+
message: "Unexpected import of 'process'. Use the global 'process' instead",
|
|
27792
|
+
severity: "error",
|
|
27793
|
+
help: "`process` is a global in Node.js \u2014 remove the import and use it directly."
|
|
27794
|
+
});
|
|
27530
27795
|
}
|
|
27531
27796
|
return issues;
|
|
27532
27797
|
}
|
|
@@ -27686,7 +27951,7 @@ function startsWithShebang(code) {
|
|
|
27686
27951
|
return /^#!\s*\//.test(code);
|
|
27687
27952
|
}
|
|
27688
27953
|
function stripComments(code) {
|
|
27689
|
-
return code.replace(/\/\*
|
|
27954
|
+
return code.replace(/\/\*[\s\S]*?\*\//g, "").replace(/\/\/.*/g, "");
|
|
27690
27955
|
}
|
|
27691
27956
|
function crawlExportsOrImports(value, basePath, isImports, visitor) {
|
|
27692
27957
|
_crawl(value, basePath, isImports, visitor);
|
|
@@ -28167,11 +28432,15 @@ var init_local_dependency = __esm(() => {
|
|
|
28167
28432
|
if (!pkg)
|
|
28168
28433
|
return [];
|
|
28169
28434
|
const issues = [];
|
|
28170
|
-
|
|
28171
|
-
|
|
28172
|
-
|
|
28435
|
+
const fields = ["dependencies", "optionalDependencies", "peerDependencies"];
|
|
28436
|
+
for (const field of fields) {
|
|
28437
|
+
const deps = pkg[field];
|
|
28438
|
+
if (!deps || typeof deps !== "object")
|
|
28439
|
+
continue;
|
|
28440
|
+
for (const depName of Object.keys(deps)) {
|
|
28441
|
+
const depVersion = deps[depName];
|
|
28173
28442
|
if (typeof depVersion === "string" && (depVersion.startsWith("file:") || depVersion.startsWith("link:"))) {
|
|
28174
|
-
issues.push(createIssue(context.filePath, content, [
|
|
28443
|
+
issues.push(createIssue(context.filePath, content, [field, depName], "publint/local-dependency", `The "${depName}" dependency references "${depVersion}" that will likely not work when installed by end-users.`, "error", "Local file references (file: or link:) are not portable and will fail for consumers of the package."));
|
|
28175
28444
|
}
|
|
28176
28445
|
}
|
|
28177
28446
|
}
|
|
@@ -29860,7 +30129,7 @@ function parseRegexLiteral(content, idx) {
|
|
|
29860
30129
|
return null;
|
|
29861
30130
|
const pattern = content.slice(idx + 1, closedAt);
|
|
29862
30131
|
let flagEnd = closedAt + 1;
|
|
29863
|
-
while (flagEnd < content.length && /[
|
|
30132
|
+
while (flagEnd < content.length && /[gimsuvy]/.test(content[flagEnd]))
|
|
29864
30133
|
flagEnd++;
|
|
29865
30134
|
if (/\\[1-9]/.test(pattern))
|
|
29866
30135
|
return null;
|
|
@@ -29978,7 +30247,7 @@ function skipRegexLiteral(content, idx) {
|
|
|
29978
30247
|
inClass = false;
|
|
29979
30248
|
} else if (c === "/" && !inClass) {
|
|
29980
30249
|
i++;
|
|
29981
|
-
while (i < content.length && /[
|
|
30250
|
+
while (i < content.length && /[gimsuvy]/.test(content[i]))
|
|
29982
30251
|
i++;
|
|
29983
30252
|
return i;
|
|
29984
30253
|
} else if (c === `
|
|
@@ -30675,16 +30944,12 @@ var init_quote_variables = __esm(() => {
|
|
|
30675
30944
|
inHeredoc = false;
|
|
30676
30945
|
continue;
|
|
30677
30946
|
}
|
|
30678
|
-
const
|
|
30679
|
-
if (
|
|
30680
|
-
inHeredoc = true;
|
|
30681
|
-
heredocDelim = heredocMatch[2];
|
|
30682
|
-
continue;
|
|
30683
|
-
}
|
|
30684
|
-
const heredocMatch2 = line.match(/<<-?\s*(\w+)/);
|
|
30685
|
-
if (heredocMatch2 && !heredocMatch) {
|
|
30947
|
+
const delim = heredocDelimiter(line);
|
|
30948
|
+
if (delim) {
|
|
30686
30949
|
inHeredoc = true;
|
|
30687
|
-
heredocDelim =
|
|
30950
|
+
heredocDelim = delim;
|
|
30951
|
+
if (new RegExp(`<<-?\\s*['"]${delim}['"]`).test(line))
|
|
30952
|
+
continue;
|
|
30688
30953
|
}
|
|
30689
30954
|
const trimmed = line.replace(/^\s+/, "");
|
|
30690
30955
|
if (trimmed.startsWith("#"))
|
|
@@ -31012,283 +31277,6 @@ var init_indent = __esm(() => {
|
|
|
31012
31277
|
};
|
|
31013
31278
|
});
|
|
31014
31279
|
|
|
31015
|
-
// src/rules/shell/_shared.ts
|
|
31016
|
-
function maskShellStrings(line) {
|
|
31017
|
-
const n = line.length;
|
|
31018
|
-
const out = Array.from({ length: n }, (_, i2) => line[i2]);
|
|
31019
|
-
let i = 0;
|
|
31020
|
-
while (i < n) {
|
|
31021
|
-
const ch = line[i];
|
|
31022
|
-
if (ch === "#" && (i === 0 || /\s/.test(line[i - 1]))) {
|
|
31023
|
-
while (i < n) {
|
|
31024
|
-
out[i] = " ";
|
|
31025
|
-
i++;
|
|
31026
|
-
}
|
|
31027
|
-
break;
|
|
31028
|
-
}
|
|
31029
|
-
if (ch === "$" && line[i + 1] === "'") {
|
|
31030
|
-
i += 2;
|
|
31031
|
-
while (i < n) {
|
|
31032
|
-
if (line[i] === "\\" && i + 1 < n) {
|
|
31033
|
-
out[i] = " ";
|
|
31034
|
-
out[i + 1] = " ";
|
|
31035
|
-
i += 2;
|
|
31036
|
-
continue;
|
|
31037
|
-
}
|
|
31038
|
-
if (line[i] === "'") {
|
|
31039
|
-
i++;
|
|
31040
|
-
break;
|
|
31041
|
-
}
|
|
31042
|
-
out[i] = " ";
|
|
31043
|
-
i++;
|
|
31044
|
-
}
|
|
31045
|
-
continue;
|
|
31046
|
-
}
|
|
31047
|
-
if (ch === "$" && line[i + 1] === '"') {
|
|
31048
|
-
i++;
|
|
31049
|
-
i = maskDoubleQuoted(line, i, out);
|
|
31050
|
-
continue;
|
|
31051
|
-
}
|
|
31052
|
-
if (ch === "$" && line[i + 1] === "{") {
|
|
31053
|
-
i += 2;
|
|
31054
|
-
let depth = 1;
|
|
31055
|
-
while (i < n && depth > 0) {
|
|
31056
|
-
const c = line[i];
|
|
31057
|
-
if (c === "\\" && i + 1 < n) {
|
|
31058
|
-
out[i] = " ";
|
|
31059
|
-
out[i + 1] = " ";
|
|
31060
|
-
i += 2;
|
|
31061
|
-
continue;
|
|
31062
|
-
}
|
|
31063
|
-
if (c === "'") {
|
|
31064
|
-
i++;
|
|
31065
|
-
while (i < n && line[i] !== "'") {
|
|
31066
|
-
out[i] = " ";
|
|
31067
|
-
i++;
|
|
31068
|
-
}
|
|
31069
|
-
if (i < n)
|
|
31070
|
-
i++;
|
|
31071
|
-
continue;
|
|
31072
|
-
}
|
|
31073
|
-
if (c === '"') {
|
|
31074
|
-
i = maskDoubleQuoted(line, i, out);
|
|
31075
|
-
continue;
|
|
31076
|
-
}
|
|
31077
|
-
if (c === "{") {
|
|
31078
|
-
depth++;
|
|
31079
|
-
i++;
|
|
31080
|
-
continue;
|
|
31081
|
-
}
|
|
31082
|
-
if (c === "}") {
|
|
31083
|
-
depth--;
|
|
31084
|
-
i++;
|
|
31085
|
-
continue;
|
|
31086
|
-
}
|
|
31087
|
-
out[i] = " ";
|
|
31088
|
-
i++;
|
|
31089
|
-
}
|
|
31090
|
-
continue;
|
|
31091
|
-
}
|
|
31092
|
-
if (ch === "$" && line[i + 1] === "(" && line[i + 2] === "(") {
|
|
31093
|
-
i += 3;
|
|
31094
|
-
let depth = 2;
|
|
31095
|
-
while (i < n && depth > 0) {
|
|
31096
|
-
const c = line[i];
|
|
31097
|
-
if (c === "(") {
|
|
31098
|
-
depth++;
|
|
31099
|
-
i++;
|
|
31100
|
-
continue;
|
|
31101
|
-
}
|
|
31102
|
-
if (c === ")") {
|
|
31103
|
-
depth--;
|
|
31104
|
-
i++;
|
|
31105
|
-
continue;
|
|
31106
|
-
}
|
|
31107
|
-
out[i] = " ";
|
|
31108
|
-
i++;
|
|
31109
|
-
}
|
|
31110
|
-
continue;
|
|
31111
|
-
}
|
|
31112
|
-
if (ch === "$" && line[i + 1] === "(") {
|
|
31113
|
-
i += 2;
|
|
31114
|
-
let depth = 1;
|
|
31115
|
-
while (i < n && depth > 0) {
|
|
31116
|
-
const c = line[i];
|
|
31117
|
-
if (c === "\\" && i + 1 < n) {
|
|
31118
|
-
out[i] = " ";
|
|
31119
|
-
out[i + 1] = " ";
|
|
31120
|
-
i += 2;
|
|
31121
|
-
continue;
|
|
31122
|
-
}
|
|
31123
|
-
if (c === "'") {
|
|
31124
|
-
i++;
|
|
31125
|
-
while (i < n && line[i] !== "'") {
|
|
31126
|
-
out[i] = " ";
|
|
31127
|
-
i++;
|
|
31128
|
-
}
|
|
31129
|
-
if (i < n)
|
|
31130
|
-
i++;
|
|
31131
|
-
continue;
|
|
31132
|
-
}
|
|
31133
|
-
if (c === '"') {
|
|
31134
|
-
i = maskDoubleQuoted(line, i, out);
|
|
31135
|
-
continue;
|
|
31136
|
-
}
|
|
31137
|
-
if (c === "(") {
|
|
31138
|
-
depth++;
|
|
31139
|
-
i++;
|
|
31140
|
-
continue;
|
|
31141
|
-
}
|
|
31142
|
-
if (c === ")") {
|
|
31143
|
-
depth--;
|
|
31144
|
-
i++;
|
|
31145
|
-
continue;
|
|
31146
|
-
}
|
|
31147
|
-
out[i] = " ";
|
|
31148
|
-
i++;
|
|
31149
|
-
}
|
|
31150
|
-
continue;
|
|
31151
|
-
}
|
|
31152
|
-
if (ch === "'") {
|
|
31153
|
-
i++;
|
|
31154
|
-
while (i < n && line[i] !== "'") {
|
|
31155
|
-
out[i] = " ";
|
|
31156
|
-
i++;
|
|
31157
|
-
}
|
|
31158
|
-
if (i < n)
|
|
31159
|
-
i++;
|
|
31160
|
-
continue;
|
|
31161
|
-
}
|
|
31162
|
-
if (ch === '"') {
|
|
31163
|
-
i = maskDoubleQuoted(line, i, out);
|
|
31164
|
-
continue;
|
|
31165
|
-
}
|
|
31166
|
-
if (ch === "`") {
|
|
31167
|
-
i++;
|
|
31168
|
-
while (i < n && line[i] !== "`") {
|
|
31169
|
-
if (line[i] === "\\" && i + 1 < n) {
|
|
31170
|
-
out[i] = " ";
|
|
31171
|
-
out[i + 1] = " ";
|
|
31172
|
-
i += 2;
|
|
31173
|
-
continue;
|
|
31174
|
-
}
|
|
31175
|
-
out[i] = " ";
|
|
31176
|
-
i++;
|
|
31177
|
-
}
|
|
31178
|
-
if (i < n)
|
|
31179
|
-
i++;
|
|
31180
|
-
continue;
|
|
31181
|
-
}
|
|
31182
|
-
i++;
|
|
31183
|
-
}
|
|
31184
|
-
return out.join("");
|
|
31185
|
-
}
|
|
31186
|
-
function maskDoubleQuoted(line, start, out) {
|
|
31187
|
-
const n = line.length;
|
|
31188
|
-
let i = start + 1;
|
|
31189
|
-
while (i < n) {
|
|
31190
|
-
const c = line[i];
|
|
31191
|
-
if (c === "\\" && i + 1 < n) {
|
|
31192
|
-
out[i] = " ";
|
|
31193
|
-
out[i + 1] = " ";
|
|
31194
|
-
i += 2;
|
|
31195
|
-
continue;
|
|
31196
|
-
}
|
|
31197
|
-
if (c === '"')
|
|
31198
|
-
return i + 1;
|
|
31199
|
-
if (c === "$" && line[i + 1] === "(" && line[i + 2] === "(") {
|
|
31200
|
-
i += 3;
|
|
31201
|
-
let depth = 2;
|
|
31202
|
-
while (i < n && depth > 0) {
|
|
31203
|
-
const x = line[i];
|
|
31204
|
-
if (x === "(") {
|
|
31205
|
-
depth++;
|
|
31206
|
-
i++;
|
|
31207
|
-
continue;
|
|
31208
|
-
}
|
|
31209
|
-
if (x === ")") {
|
|
31210
|
-
depth--;
|
|
31211
|
-
i++;
|
|
31212
|
-
continue;
|
|
31213
|
-
}
|
|
31214
|
-
out[i] = " ";
|
|
31215
|
-
i++;
|
|
31216
|
-
}
|
|
31217
|
-
continue;
|
|
31218
|
-
}
|
|
31219
|
-
if (c === "$" && line[i + 1] === "(") {
|
|
31220
|
-
i += 2;
|
|
31221
|
-
let depth = 1;
|
|
31222
|
-
while (i < n && depth > 0) {
|
|
31223
|
-
const x = line[i];
|
|
31224
|
-
if (x === "\\" && i + 1 < n) {
|
|
31225
|
-
out[i] = " ";
|
|
31226
|
-
out[i + 1] = " ";
|
|
31227
|
-
i += 2;
|
|
31228
|
-
continue;
|
|
31229
|
-
}
|
|
31230
|
-
if (x === "'") {
|
|
31231
|
-
i++;
|
|
31232
|
-
while (i < n && line[i] !== "'") {
|
|
31233
|
-
out[i] = " ";
|
|
31234
|
-
i++;
|
|
31235
|
-
}
|
|
31236
|
-
if (i < n)
|
|
31237
|
-
i++;
|
|
31238
|
-
continue;
|
|
31239
|
-
}
|
|
31240
|
-
if (x === '"') {
|
|
31241
|
-
i = maskDoubleQuoted(line, i, out);
|
|
31242
|
-
continue;
|
|
31243
|
-
}
|
|
31244
|
-
if (x === "(") {
|
|
31245
|
-
depth++;
|
|
31246
|
-
i++;
|
|
31247
|
-
continue;
|
|
31248
|
-
}
|
|
31249
|
-
if (x === ")") {
|
|
31250
|
-
depth--;
|
|
31251
|
-
i++;
|
|
31252
|
-
continue;
|
|
31253
|
-
}
|
|
31254
|
-
out[i] = " ";
|
|
31255
|
-
i++;
|
|
31256
|
-
}
|
|
31257
|
-
continue;
|
|
31258
|
-
}
|
|
31259
|
-
if (c === "$" && line[i + 1] === "{") {
|
|
31260
|
-
i += 2;
|
|
31261
|
-
let depth = 1;
|
|
31262
|
-
while (i < n && depth > 0) {
|
|
31263
|
-
const x = line[i];
|
|
31264
|
-
if (x === "{") {
|
|
31265
|
-
depth++;
|
|
31266
|
-
i++;
|
|
31267
|
-
continue;
|
|
31268
|
-
}
|
|
31269
|
-
if (x === "}") {
|
|
31270
|
-
depth--;
|
|
31271
|
-
i++;
|
|
31272
|
-
continue;
|
|
31273
|
-
}
|
|
31274
|
-
out[i] = " ";
|
|
31275
|
-
i++;
|
|
31276
|
-
}
|
|
31277
|
-
continue;
|
|
31278
|
-
}
|
|
31279
|
-
out[i] = " ";
|
|
31280
|
-
i++;
|
|
31281
|
-
}
|
|
31282
|
-
return i;
|
|
31283
|
-
}
|
|
31284
|
-
function heredocDelimiter(line) {
|
|
31285
|
-
const masked = maskShellStrings(line);
|
|
31286
|
-
const m = masked.match(/<<-?\s*['"]?(\w+)['"]?/);
|
|
31287
|
-
if (!m)
|
|
31288
|
-
return null;
|
|
31289
|
-
return m[1];
|
|
31290
|
-
}
|
|
31291
|
-
|
|
31292
31280
|
// src/rules/shell/keyword-spacing.ts
|
|
31293
31281
|
var keywordSpacingRule;
|
|
31294
31282
|
var init_keyword_spacing = __esm(() => {
|
|
@@ -31448,10 +31436,10 @@ var init_no_trailing_whitespace = __esm(() => {
|
|
|
31448
31436
|
inHeredoc = false;
|
|
31449
31437
|
continue;
|
|
31450
31438
|
}
|
|
31451
|
-
const
|
|
31452
|
-
if (
|
|
31439
|
+
const delim = heredocDelimiter(line);
|
|
31440
|
+
if (delim) {
|
|
31453
31441
|
inHeredoc = true;
|
|
31454
|
-
heredocDelim =
|
|
31442
|
+
heredocDelim = delim;
|
|
31455
31443
|
}
|
|
31456
31444
|
if (/[ \t]+$/.test(line)) {
|
|
31457
31445
|
const trailingMatch = line.match(/[ \t]+$/);
|
|
@@ -31468,7 +31456,24 @@ var init_no_trailing_whitespace = __esm(() => {
|
|
|
31468
31456
|
return issues;
|
|
31469
31457
|
},
|
|
31470
31458
|
fix(content) {
|
|
31471
|
-
|
|
31459
|
+
const lines = content.split(/\r?\n/);
|
|
31460
|
+
let inHeredoc = false;
|
|
31461
|
+
let heredocDelim = "";
|
|
31462
|
+
const fixed = lines.map((line) => {
|
|
31463
|
+
if (inHeredoc) {
|
|
31464
|
+
if (line.trim() === heredocDelim)
|
|
31465
|
+
inHeredoc = false;
|
|
31466
|
+
return line;
|
|
31467
|
+
}
|
|
31468
|
+
const delim = heredocDelimiter(line);
|
|
31469
|
+
if (delim) {
|
|
31470
|
+
inHeredoc = true;
|
|
31471
|
+
heredocDelim = delim;
|
|
31472
|
+
}
|
|
31473
|
+
return line.replace(/[ \t]+$/, "");
|
|
31474
|
+
});
|
|
31475
|
+
return fixed.join(`
|
|
31476
|
+
`);
|
|
31472
31477
|
}
|
|
31473
31478
|
};
|
|
31474
31479
|
});
|
|
@@ -31866,21 +31871,26 @@ var init_heredoc_indent = __esm(() => {
|
|
|
31866
31871
|
const trimmed = line.replace(/^\s+/, "");
|
|
31867
31872
|
if (trimmed.startsWith("#"))
|
|
31868
31873
|
continue;
|
|
31869
|
-
const
|
|
31870
|
-
if (
|
|
31871
|
-
|
|
31872
|
-
|
|
31873
|
-
|
|
31874
|
-
|
|
31875
|
-
|
|
31876
|
-
|
|
31877
|
-
|
|
31878
|
-
|
|
31879
|
-
|
|
31880
|
-
|
|
31881
|
-
|
|
31882
|
-
|
|
31883
|
-
|
|
31874
|
+
const indent = line.match(/^\s+/);
|
|
31875
|
+
if (!indent)
|
|
31876
|
+
continue;
|
|
31877
|
+
const masked = maskShellStrings(line);
|
|
31878
|
+
const op = masked.match(/(?<!<)<<(?![<-])/);
|
|
31879
|
+
if (!op || op.index === undefined)
|
|
31880
|
+
continue;
|
|
31881
|
+
const after = line.slice(op.index + 2);
|
|
31882
|
+
const delimMatch = after.match(/^\s*(['"]?)(\w+)\1\s*$/);
|
|
31883
|
+
if (delimMatch) {
|
|
31884
|
+
const delim = delimMatch[2];
|
|
31885
|
+
issues.push({
|
|
31886
|
+
filePath: ctx.filePath,
|
|
31887
|
+
line: i + 1,
|
|
31888
|
+
column: op.index + 1,
|
|
31889
|
+
ruleId: "shell/heredoc-indent",
|
|
31890
|
+
message: `Use <<- instead of << for indented heredoc (delimiter '${delim}' must be at column 0 otherwise)`,
|
|
31891
|
+
severity: "warning",
|
|
31892
|
+
help: "Use <<- to strip leading tabs from heredoc content, allowing proper indentation"
|
|
31893
|
+
});
|
|
31884
31894
|
}
|
|
31885
31895
|
}
|
|
31886
31896
|
return issues;
|
|
@@ -31908,17 +31918,18 @@ var init_no_broken_redirect = __esm(() => {
|
|
|
31908
31918
|
inHeredoc = false;
|
|
31909
31919
|
continue;
|
|
31910
31920
|
}
|
|
31911
|
-
const
|
|
31912
|
-
if (
|
|
31921
|
+
const delim = heredocDelimiter(line);
|
|
31922
|
+
if (delim) {
|
|
31913
31923
|
inHeredoc = true;
|
|
31914
|
-
heredocDelim =
|
|
31924
|
+
heredocDelim = delim;
|
|
31915
31925
|
}
|
|
31916
31926
|
const trimmed = line.replace(/^\s+/, "");
|
|
31917
31927
|
if (trimmed.startsWith("#"))
|
|
31918
31928
|
continue;
|
|
31919
|
-
const
|
|
31929
|
+
const masked = maskShellStrings(line);
|
|
31930
|
+
const brokenPattern = masked.match(/2>&1\s+>(?!&)\s*\S/);
|
|
31920
31931
|
if (brokenPattern) {
|
|
31921
|
-
const col =
|
|
31932
|
+
const col = masked.indexOf("2>&1");
|
|
31922
31933
|
issues.push({
|
|
31923
31934
|
filePath: ctx.filePath,
|
|
31924
31935
|
line: i + 1,
|
|
@@ -32216,8 +32227,6 @@ function createSpellRule(ruleId, filterFn) {
|
|
|
32216
32227
|
for (const { word, offset: wordOffset } of words) {
|
|
32217
32228
|
if (word.length < minLen)
|
|
32218
32229
|
continue;
|
|
32219
|
-
if (word.length <= 2)
|
|
32220
|
-
continue;
|
|
32221
32230
|
if (word === word.toUpperCase() && word.length <= 5)
|
|
32222
32231
|
continue;
|
|
32223
32232
|
if (userWords.has(word.toLowerCase()))
|
|
@@ -32474,9 +32483,36 @@ var init_arrow_spacing = __esm(() => {
|
|
|
32474
32483
|
return issues;
|
|
32475
32484
|
},
|
|
32476
32485
|
fix(content) {
|
|
32477
|
-
|
|
32478
|
-
|
|
32479
|
-
|
|
32486
|
+
const lines = content.split(`
|
|
32487
|
+
`);
|
|
32488
|
+
for (let li = 0;li < lines.length; li++) {
|
|
32489
|
+
const line = lines[li];
|
|
32490
|
+
const trimmed = line.trim();
|
|
32491
|
+
if (!trimmed || trimmed.startsWith("//") || trimmed.startsWith("*") || trimmed.startsWith("/*"))
|
|
32492
|
+
continue;
|
|
32493
|
+
let out = "";
|
|
32494
|
+
let last = 0;
|
|
32495
|
+
ARROW_RE.lastIndex = 0;
|
|
32496
|
+
let m;
|
|
32497
|
+
while ((m = ARROW_RE.exec(line)) !== null) {
|
|
32498
|
+
const idx = m.index;
|
|
32499
|
+
if (isInStringOrComment3(line, idx))
|
|
32500
|
+
continue;
|
|
32501
|
+
const before = line[idx - 1];
|
|
32502
|
+
const after = line[idx + 2];
|
|
32503
|
+
const needBefore = idx > 0 && before !== " " && before !== "\t";
|
|
32504
|
+
const needAfter = after !== undefined && after !== " " && after !== "\t";
|
|
32505
|
+
if (!needBefore && !needAfter)
|
|
32506
|
+
continue;
|
|
32507
|
+
out += line.slice(last, idx);
|
|
32508
|
+
out += `${needBefore ? " " : ""}=>${needAfter ? " " : ""}`;
|
|
32509
|
+
last = idx + 2;
|
|
32510
|
+
}
|
|
32511
|
+
if (last > 0)
|
|
32512
|
+
lines[li] = out + line.slice(last);
|
|
32513
|
+
}
|
|
32514
|
+
return lines.join(`
|
|
32515
|
+
`);
|
|
32480
32516
|
}
|
|
32481
32517
|
};
|
|
32482
32518
|
});
|
|
@@ -33733,11 +33769,14 @@ var init_dot_location = __esm(() => {
|
|
|
33733
33769
|
check(content, context) {
|
|
33734
33770
|
const issues = [];
|
|
33735
33771
|
const lines = content.split(/\r?\n/);
|
|
33772
|
+
const inTemplate = computeLineStartsInTemplate(content);
|
|
33736
33773
|
for (let i = 0;i < lines.length; i++) {
|
|
33737
33774
|
const line = lines[i];
|
|
33738
33775
|
const trimmed = line.trim();
|
|
33739
33776
|
if (!trimmed || trimmed.startsWith("//") || trimmed.startsWith("*") || trimmed.startsWith("/*"))
|
|
33740
33777
|
continue;
|
|
33778
|
+
if (inTemplate[i + 1])
|
|
33779
|
+
continue;
|
|
33741
33780
|
if (trimmed.endsWith(".") && i + 1 < lines.length) {
|
|
33742
33781
|
const nextTrimmed = lines[i + 1].trim();
|
|
33743
33782
|
if (nextTrimmed && /^[a-zA-Z_$]/.test(nextTrimmed)) {
|
|
@@ -33757,10 +33796,11 @@ var init_dot_location = __esm(() => {
|
|
|
33757
33796
|
fix(content) {
|
|
33758
33797
|
const lines = content.split(/\r?\n/);
|
|
33759
33798
|
const result = [];
|
|
33799
|
+
const inTemplate = computeLineStartsInTemplate(content);
|
|
33760
33800
|
for (let i = 0;i < lines.length; i++) {
|
|
33761
33801
|
const line = lines[i];
|
|
33762
33802
|
const trimmed = line.trim();
|
|
33763
|
-
if (trimmed.endsWith(".") && i + 1 < lines.length) {
|
|
33803
|
+
if (trimmed.endsWith(".") && !inTemplate[i + 1] && i + 1 < lines.length) {
|
|
33764
33804
|
const nextLine = lines[i + 1];
|
|
33765
33805
|
const nextTrimmed = nextLine.trim();
|
|
33766
33806
|
if (nextTrimmed && /^[a-zA-Z_$]/.test(nextTrimmed)) {
|
|
@@ -37490,32 +37530,60 @@ var init_prefer_nullish_coalescing = __esm(() => {
|
|
|
37490
37530
|
const lines = text.split(/\r?\n/);
|
|
37491
37531
|
let inBlockComment = false;
|
|
37492
37532
|
for (let i = 0;i < lines.length; i++) {
|
|
37493
|
-
|
|
37494
|
-
const
|
|
37533
|
+
const originalLine = lines[i];
|
|
37534
|
+
const chars = originalLine.split("");
|
|
37535
|
+
const n = chars.length;
|
|
37536
|
+
let k = 0;
|
|
37495
37537
|
if (inBlockComment) {
|
|
37496
|
-
const endIdx =
|
|
37497
|
-
if (endIdx
|
|
37498
|
-
line = line.slice(endIdx + 2);
|
|
37499
|
-
inBlockComment = false;
|
|
37500
|
-
} else {
|
|
37538
|
+
const endIdx = originalLine.indexOf("*/");
|
|
37539
|
+
if (endIdx < 0)
|
|
37501
37540
|
continue;
|
|
37502
|
-
|
|
37541
|
+
for (let p = 0;p <= endIdx + 1; p++)
|
|
37542
|
+
chars[p] = " ";
|
|
37543
|
+
inBlockComment = false;
|
|
37544
|
+
k = endIdx + 2;
|
|
37503
37545
|
}
|
|
37504
|
-
|
|
37505
|
-
|
|
37506
|
-
|
|
37507
|
-
|
|
37508
|
-
|
|
37509
|
-
|
|
37510
|
-
|
|
37511
|
-
|
|
37512
|
-
|
|
37546
|
+
let inStr = null;
|
|
37547
|
+
for (;k < n; k++) {
|
|
37548
|
+
const ch = chars[k];
|
|
37549
|
+
if (inStr) {
|
|
37550
|
+
if (ch === "\\") {
|
|
37551
|
+
chars[k] = " ";
|
|
37552
|
+
if (k + 1 < n) {
|
|
37553
|
+
chars[k + 1] = " ";
|
|
37554
|
+
k++;
|
|
37555
|
+
}
|
|
37556
|
+
continue;
|
|
37557
|
+
}
|
|
37558
|
+
if (ch === inStr) {
|
|
37559
|
+
inStr = null;
|
|
37560
|
+
continue;
|
|
37561
|
+
}
|
|
37562
|
+
chars[k] = " ";
|
|
37563
|
+
continue;
|
|
37513
37564
|
}
|
|
37565
|
+
if (ch === "/" && chars[k + 1] === "/") {
|
|
37566
|
+
for (let p = k;p < n; p++)
|
|
37567
|
+
chars[p] = " ";
|
|
37568
|
+
break;
|
|
37569
|
+
}
|
|
37570
|
+
if (ch === "/" && chars[k + 1] === "*") {
|
|
37571
|
+
const endIdx = originalLine.indexOf("*/", k + 2);
|
|
37572
|
+
if (endIdx < 0) {
|
|
37573
|
+
for (let p = k;p < n; p++)
|
|
37574
|
+
chars[p] = " ";
|
|
37575
|
+
inBlockComment = true;
|
|
37576
|
+
break;
|
|
37577
|
+
}
|
|
37578
|
+
for (let p = k;p <= endIdx + 1; p++)
|
|
37579
|
+
chars[p] = " ";
|
|
37580
|
+
k = endIdx + 1;
|
|
37581
|
+
continue;
|
|
37582
|
+
}
|
|
37583
|
+
if (ch === '"' || ch === "'" || ch === "`")
|
|
37584
|
+
inStr = ch;
|
|
37514
37585
|
}
|
|
37515
|
-
|
|
37516
|
-
line = line.slice(0, lineComment);
|
|
37517
|
-
}
|
|
37518
|
-
const cleanedLine = line.replace(/(['"`])(?:(?!\1)[^\\]|\\.)*?\1/g, '""');
|
|
37586
|
+
const cleanedLine = chars.join("");
|
|
37519
37587
|
const orPattern = /\|\|/g;
|
|
37520
37588
|
let match;
|
|
37521
37589
|
while ((match = orPattern.exec(cleanedLine)) !== null) {
|
|
@@ -37610,11 +37678,10 @@ var init_prefer_nullish_coalescing = __esm(() => {
|
|
|
37610
37678
|
const looksLikeDefaultValue = /^["'`\d]/.test(rightOperand) || /^\{/.test(rightOperand) || /^[\w$]+\(/.test(rightOperand) || /^[\w$.[\]]+$/.test(rightOperand);
|
|
37611
37679
|
const looksLikeNullableValue = /^[\w$]+$/.test(leftOperand) || /^[\w$.?[\]()]+$/.test(leftOperand);
|
|
37612
37680
|
if (looksLikeDefaultValue && looksLikeNullableValue) {
|
|
37613
|
-
const actualIdx = originalLine.indexOf("||", Math.max(0, idx - 5));
|
|
37614
37681
|
issues.push({
|
|
37615
37682
|
filePath: ctx.filePath,
|
|
37616
37683
|
line: i + 1,
|
|
37617
|
-
column:
|
|
37684
|
+
column: idx + 1,
|
|
37618
37685
|
ruleId: "ts/prefer-nullish-coalescing",
|
|
37619
37686
|
message: "Prefer nullish coalescing operator (??) over logical OR (||)",
|
|
37620
37687
|
severity: "error",
|
|
@@ -38311,35 +38378,30 @@ async function runFormat(globs, options) {
|
|
|
38311
38378
|
return extSet.has(ext);
|
|
38312
38379
|
});
|
|
38313
38380
|
trace("filtered files", files.length);
|
|
38314
|
-
let changed = 0;
|
|
38315
38381
|
let checked = 0;
|
|
38382
|
+
const unformatted = [];
|
|
38316
38383
|
for (const file of files) {
|
|
38317
38384
|
trace("format start", relative6(process23.cwd(), file));
|
|
38318
38385
|
const src = readFileSync9(file, "utf8");
|
|
38319
38386
|
const fmt = formatCode(src, cfg, file);
|
|
38320
|
-
|
|
38321
|
-
|
|
38322
|
-
|
|
38323
|
-
changed++;
|
|
38324
|
-
}
|
|
38325
|
-
checked++;
|
|
38326
|
-
} else if (options.write) {
|
|
38327
|
-
if (fmt !== src) {
|
|
38387
|
+
const differs = fmt !== src;
|
|
38388
|
+
if (options.write) {
|
|
38389
|
+
if (differs)
|
|
38328
38390
|
writeFileSync10(file, fmt, "utf8");
|
|
38329
|
-
changed++;
|
|
38330
|
-
}
|
|
38331
|
-
checked++;
|
|
38332
|
-
} else {
|
|
38333
|
-
if (fmt !== src) {
|
|
38334
|
-
getLogger().debug(`${relative6(process23.cwd(), file)} needs formatting`);
|
|
38335
|
-
changed++;
|
|
38336
|
-
}
|
|
38337
|
-
checked++;
|
|
38338
38391
|
}
|
|
38392
|
+
if (differs)
|
|
38393
|
+
unformatted.push(relative6(process23.cwd(), file));
|
|
38394
|
+
checked++;
|
|
38339
38395
|
}
|
|
38340
|
-
const
|
|
38341
|
-
if (
|
|
38342
|
-
|
|
38396
|
+
const changed = unformatted.length;
|
|
38397
|
+
if (changed > 0) {
|
|
38398
|
+
for (const file of unformatted)
|
|
38399
|
+
console.log(colors.gray(` ${file}`));
|
|
38400
|
+
console.log(options.write ? colors.gray(`Formatted ${changed} of ${checked} file(s).`) : colors.yellow(`${changed} of ${checked} file(s) need formatting. Run with --write to fix.`));
|
|
38401
|
+
} else {
|
|
38402
|
+
const isVerbose = options.verbose !== undefined ? options.verbose : cfg.verbose;
|
|
38403
|
+
if (isVerbose)
|
|
38404
|
+
console.log(colors.gray(`Checked ${checked} files, all formatted.`));
|
|
38343
38405
|
}
|
|
38344
38406
|
return options.check && changed > 0 ? 1 : 0;
|
|
38345
38407
|
}
|
|
@@ -38362,7 +38424,7 @@ __export(exports_linter, {
|
|
|
38362
38424
|
applyPlugins: () => applyPlugins
|
|
38363
38425
|
});
|
|
38364
38426
|
import { readdirSync as readdirSync9, readFileSync as readFileSync10, statSync as statSync6, writeFileSync as writeFileSync11 } from "fs";
|
|
38365
|
-
import { isAbsolute as isAbsolute8, join as join11, relative as relative7, resolve as resolve23 } from "path";
|
|
38427
|
+
import { isAbsolute as isAbsolute8, join as join11, relative as relative7, resolve as resolve23, sep } from "path";
|
|
38366
38428
|
import process25 from "process";
|
|
38367
38429
|
function getLogger2() {
|
|
38368
38430
|
if (!_logger2)
|
|
@@ -38419,7 +38481,8 @@ async function runLintProgrammatic(globs, options, signal) {
|
|
|
38419
38481
|
const isGlobbingOutsideProject = patterns.some((p) => {
|
|
38420
38482
|
const base = p.replace(/\/?\*\*\/*\*\*$/, "");
|
|
38421
38483
|
const absBase = isAbsolute8(base) ? base : resolve23(process25.cwd(), base);
|
|
38422
|
-
|
|
38484
|
+
const cwd = process25.cwd();
|
|
38485
|
+
return absBase !== cwd && !absBase.startsWith(cwd + sep);
|
|
38423
38486
|
});
|
|
38424
38487
|
const globIgnores = isGlobbingOutsideProject ? [...UNIVERSAL_IGNORES] : cfg.ignores;
|
|
38425
38488
|
const ignoreMatcher = createIgnoreMatcher(globIgnores);
|
|
@@ -39450,7 +39513,10 @@ function scanContentOptimized(filePath, content, cfg, suppress, commentLines) {
|
|
|
39450
39513
|
}
|
|
39451
39514
|
} else {
|
|
39452
39515
|
if (inString === "double" && ch === '"' || inString === "single" && ch === "'" || inString === "template" && ch === "`") {
|
|
39453
|
-
|
|
39516
|
+
let backslashes = 0;
|
|
39517
|
+
for (let p = k - 1;p >= 0 && line[p] === "\\"; p--)
|
|
39518
|
+
backslashes++;
|
|
39519
|
+
if (backslashes % 2 === 0)
|
|
39454
39520
|
inString = null;
|
|
39455
39521
|
}
|
|
39456
39522
|
}
|
|
@@ -39527,6 +39593,12 @@ function scanContentOptimized(filePath, content, cfg, suppress, commentLines) {
|
|
|
39527
39593
|
const strippedLine = stripComments2(stripRegexLiterals(line));
|
|
39528
39594
|
const conditionLine = strippedLine.replace(/'[^']*'|"[^"]*"/g, '""');
|
|
39529
39595
|
const checkCond = (cond) => /[^=!<>]=(?![=>])/.test(cond);
|
|
39596
|
+
const condParenColumn = (keyword) => {
|
|
39597
|
+
const km = line.match(keyword);
|
|
39598
|
+
if (km && km.index !== undefined)
|
|
39599
|
+
return km.index + km[0].length;
|
|
39600
|
+
return Math.max(1, line.indexOf("(") + 1);
|
|
39601
|
+
};
|
|
39530
39602
|
const m1 = conditionLine.match(/\b(?:if|while)\s*\(([^)]*)\)/);
|
|
39531
39603
|
if (m1) {
|
|
39532
39604
|
const cond = m1[1];
|
|
@@ -39535,7 +39607,7 @@ function scanContentOptimized(filePath, content, cfg, suppress, commentLines) {
|
|
|
39535
39607
|
issues.push({
|
|
39536
39608
|
filePath,
|
|
39537
39609
|
line: lineNo,
|
|
39538
|
-
column:
|
|
39610
|
+
column: condParenColumn(/\b(?:if|while)\s*\(/),
|
|
39539
39611
|
ruleId: "no-cond-assign",
|
|
39540
39612
|
message: "Unexpected assignment within a conditional expression",
|
|
39541
39613
|
severity: wantNoCondAssign,
|
|
@@ -39555,7 +39627,7 @@ function scanContentOptimized(filePath, content, cfg, suppress, commentLines) {
|
|
|
39555
39627
|
issues.push({
|
|
39556
39628
|
filePath,
|
|
39557
39629
|
line: lineNo,
|
|
39558
|
-
column:
|
|
39630
|
+
column: condParenColumn(/\bfor\s*\(/),
|
|
39559
39631
|
ruleId: "no-cond-assign",
|
|
39560
39632
|
message: "Unexpected assignment within a conditional expression",
|
|
39561
39633
|
severity: wantNoCondAssign,
|
|
@@ -39622,7 +39694,8 @@ async function runLint(globs, options) {
|
|
|
39622
39694
|
const isGlobbingOutsideProject = patterns.some((p) => {
|
|
39623
39695
|
const base = p.replace(/\/?\*\*\/*\*\*$/, "");
|
|
39624
39696
|
const absBase = isAbsolute8(base) ? base : resolve23(process25.cwd(), base);
|
|
39625
|
-
|
|
39697
|
+
const cwd = process25.cwd();
|
|
39698
|
+
return absBase !== cwd && !absBase.startsWith(cwd + sep);
|
|
39626
39699
|
});
|
|
39627
39700
|
const globIgnores = isGlobbingOutsideProject ? [...UNIVERSAL_IGNORES] : cfg.ignores;
|
|
39628
39701
|
const ignoreMatcher = createIgnoreMatcher(globIgnores);
|
|
@@ -44090,7 +44163,7 @@ var require_package = __commonJS((exports, module) => {
|
|
|
44090
44163
|
module.exports = {
|
|
44091
44164
|
name: "pickier",
|
|
44092
44165
|
type: "module",
|
|
44093
|
-
version: "0.1.
|
|
44166
|
+
version: "0.1.38",
|
|
44094
44167
|
description: "Format, lint and more in a fraction of seconds.",
|
|
44095
44168
|
author: "Chris Breuer <chris@stacksjs.org>",
|
|
44096
44169
|
license: "MIT",
|