pickier 0.1.35 → 0.1.36
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 +163 -31
- package/dist/rules/markdown/_fence-tracking.d.ts +14 -0
- package/dist/src/index.js +162 -30
- package/package.json +1 -1
package/dist/bin/cli.js
CHANGED
|
@@ -21166,6 +21166,15 @@ var init_no_unused_vars = __esm(() => {
|
|
|
21166
21166
|
continue;
|
|
21167
21167
|
}
|
|
21168
21168
|
if (!inString) {
|
|
21169
|
+
if (ch === "/" && after[k + 1] === "/")
|
|
21170
|
+
break;
|
|
21171
|
+
if (ch === "/" && after[k + 1] === "*") {
|
|
21172
|
+
k += 2;
|
|
21173
|
+
while (k < after.length && !(after[k] === "*" && after[k + 1] === "/"))
|
|
21174
|
+
k++;
|
|
21175
|
+
k++;
|
|
21176
|
+
continue;
|
|
21177
|
+
}
|
|
21169
21178
|
if (ch === "'") {
|
|
21170
21179
|
inString = "single";
|
|
21171
21180
|
} else if (ch === '"') {
|
|
@@ -23780,24 +23789,39 @@ var init_blanks_around_lists = __esm(() => {
|
|
|
23780
23789
|
const lines = text.split(/\r?\n/);
|
|
23781
23790
|
const result = [];
|
|
23782
23791
|
let inList = false;
|
|
23792
|
+
let inFence = false;
|
|
23793
|
+
const isListItemLine = (l) => /^(?:\s*)(?:[*\-+]|\d+\.)\s+/.test(l);
|
|
23783
23794
|
for (let i = 0;i < lines.length; i++) {
|
|
23784
23795
|
const line = lines[i];
|
|
23785
23796
|
const prevLine = i > 0 ? lines[i - 1] : "";
|
|
23786
|
-
|
|
23797
|
+
if (/^(?:`{3,}|~{3,})/.test(line.trim())) {
|
|
23798
|
+
inFence = !inFence;
|
|
23799
|
+
inList = false;
|
|
23800
|
+
result.push(line);
|
|
23801
|
+
continue;
|
|
23802
|
+
}
|
|
23803
|
+
if (inFence) {
|
|
23804
|
+
result.push(line);
|
|
23805
|
+
continue;
|
|
23806
|
+
}
|
|
23807
|
+
const isListItem = isListItemLine(line);
|
|
23808
|
+
const isBlank = line.trim().length === 0;
|
|
23809
|
+
const isContinuation = inList && !isListItem && !isBlank && /^\s/.test(line);
|
|
23787
23810
|
if (isListItem && !inList) {
|
|
23788
23811
|
if (i > 0 && prevLine.trim().length > 0 && result.length > 0) {
|
|
23789
23812
|
result.push("");
|
|
23790
23813
|
}
|
|
23791
23814
|
inList = true;
|
|
23792
|
-
} else if (!isListItem &&
|
|
23815
|
+
} else if (!isListItem && !isContinuation && !isBlank && inList) {
|
|
23793
23816
|
inList = false;
|
|
23794
23817
|
if (result.length > 0) {
|
|
23795
23818
|
result.push("");
|
|
23796
23819
|
}
|
|
23797
|
-
} else if (
|
|
23820
|
+
} else if (isBlank) {
|
|
23798
23821
|
const nextLine = i + 1 < lines.length ? lines[i + 1] : "";
|
|
23799
|
-
const nextIsListItem =
|
|
23800
|
-
|
|
23822
|
+
const nextIsListItem = isListItemLine(nextLine);
|
|
23823
|
+
const nextIsContinuation = /^\s+\S/.test(nextLine);
|
|
23824
|
+
if (!nextIsListItem && !nextIsContinuation && inList) {
|
|
23801
23825
|
inList = false;
|
|
23802
23826
|
}
|
|
23803
23827
|
}
|
|
@@ -23868,6 +23892,64 @@ function getCodeBlockLines(lines) {
|
|
|
23868
23892
|
}
|
|
23869
23893
|
return out;
|
|
23870
23894
|
}
|
|
23895
|
+
function eachInlineSegment(line, onText, onCode) {
|
|
23896
|
+
let i = 0;
|
|
23897
|
+
let textStart = 0;
|
|
23898
|
+
while (i < line.length) {
|
|
23899
|
+
if (line[i] !== "`") {
|
|
23900
|
+
i++;
|
|
23901
|
+
continue;
|
|
23902
|
+
}
|
|
23903
|
+
let n = 0;
|
|
23904
|
+
while (line[i + n] === "`")
|
|
23905
|
+
n++;
|
|
23906
|
+
let j = i + n;
|
|
23907
|
+
let close = -1;
|
|
23908
|
+
while (j < line.length) {
|
|
23909
|
+
if (line[j] === "`") {
|
|
23910
|
+
let k = 0;
|
|
23911
|
+
while (line[j + k] === "`")
|
|
23912
|
+
k++;
|
|
23913
|
+
if (k === n) {
|
|
23914
|
+
close = j;
|
|
23915
|
+
break;
|
|
23916
|
+
}
|
|
23917
|
+
j += k;
|
|
23918
|
+
} else {
|
|
23919
|
+
j++;
|
|
23920
|
+
}
|
|
23921
|
+
}
|
|
23922
|
+
if (close === -1) {
|
|
23923
|
+
i += n;
|
|
23924
|
+
continue;
|
|
23925
|
+
}
|
|
23926
|
+
if (textStart < i)
|
|
23927
|
+
onText(line.slice(textStart, i));
|
|
23928
|
+
onCode(line.slice(i, close + n));
|
|
23929
|
+
i = close + n;
|
|
23930
|
+
textStart = i;
|
|
23931
|
+
}
|
|
23932
|
+
if (textStart < line.length)
|
|
23933
|
+
onText(line.slice(textStart));
|
|
23934
|
+
}
|
|
23935
|
+
function replaceOutsideInlineCode(line, transform) {
|
|
23936
|
+
let out = "";
|
|
23937
|
+
eachInlineSegment(line, (seg) => {
|
|
23938
|
+
out += transform(seg);
|
|
23939
|
+
}, (seg) => {
|
|
23940
|
+
out += seg;
|
|
23941
|
+
});
|
|
23942
|
+
return out;
|
|
23943
|
+
}
|
|
23944
|
+
function maskInlineCode(line) {
|
|
23945
|
+
let out = "";
|
|
23946
|
+
eachInlineSegment(line, (seg) => {
|
|
23947
|
+
out += seg;
|
|
23948
|
+
}, (seg) => {
|
|
23949
|
+
out += " ".repeat(seg.length);
|
|
23950
|
+
});
|
|
23951
|
+
return out;
|
|
23952
|
+
}
|
|
23871
23953
|
|
|
23872
23954
|
// src/rules/markdown/_shared.ts
|
|
23873
23955
|
function findTableRows(lines) {
|
|
@@ -24278,8 +24360,10 @@ var init_descriptive_link_text = __esm(() => {
|
|
|
24278
24360
|
});
|
|
24279
24361
|
|
|
24280
24362
|
// src/rules/markdown/emphasis-style.ts
|
|
24281
|
-
var emphasisStyleRule;
|
|
24363
|
+
var ASTERISK_EMPHASIS, UNDERSCORE_EMPHASIS, emphasisStyleRule;
|
|
24282
24364
|
var init_emphasis_style = __esm(() => {
|
|
24365
|
+
ASTERISK_EMPHASIS = /(?<!\*)\*(?!\*)([^*]+)\*(?!\*)/;
|
|
24366
|
+
UNDERSCORE_EMPHASIS = /(?<!_)_(?!_)([^_]+)_(?!_)/;
|
|
24283
24367
|
emphasisStyleRule = {
|
|
24284
24368
|
meta: {
|
|
24285
24369
|
docs: "Emphasis style should be consistent (asterisk or underscore)"
|
|
@@ -24358,27 +24442,51 @@ var init_emphasis_style = __esm(() => {
|
|
|
24358
24442
|
fix: (text, ctx) => {
|
|
24359
24443
|
const options = ctx.options || {};
|
|
24360
24444
|
const style = options.style || "consistent";
|
|
24445
|
+
const lines = text.split(/\r?\n/);
|
|
24446
|
+
const inCode = getCodeBlockLines(lines);
|
|
24361
24447
|
let targetStyle = "asterisk";
|
|
24362
24448
|
if (style === "asterisk") {
|
|
24363
24449
|
targetStyle = "asterisk";
|
|
24364
24450
|
} else if (style === "underscore") {
|
|
24365
24451
|
targetStyle = "underscore";
|
|
24366
24452
|
} else if (style === "consistent") {
|
|
24367
|
-
|
|
24368
|
-
|
|
24369
|
-
|
|
24453
|
+
let firstAsterisk = null;
|
|
24454
|
+
let firstUnderscore = null;
|
|
24455
|
+
for (let i = 0;i < lines.length; i++) {
|
|
24456
|
+
if (inCode.has(i))
|
|
24457
|
+
continue;
|
|
24458
|
+
const stripped = maskInlineCode(lines[i]);
|
|
24459
|
+
if (firstAsterisk === null) {
|
|
24460
|
+
const m = stripped.match(ASTERISK_EMPHASIS);
|
|
24461
|
+
if (m)
|
|
24462
|
+
firstAsterisk = { line: i, col: m.index };
|
|
24463
|
+
}
|
|
24464
|
+
if (firstUnderscore === null) {
|
|
24465
|
+
const m = stripped.match(UNDERSCORE_EMPHASIS);
|
|
24466
|
+
if (m)
|
|
24467
|
+
firstUnderscore = { line: i, col: m.index };
|
|
24468
|
+
}
|
|
24469
|
+
if (firstAsterisk && firstUnderscore)
|
|
24470
|
+
break;
|
|
24471
|
+
}
|
|
24472
|
+
const cmp = (a, b) => a.line !== b.line ? a.line - b.line : a.col - b.col;
|
|
24473
|
+
if (firstAsterisk && (!firstUnderscore || cmp(firstAsterisk, firstUnderscore) < 0))
|
|
24370
24474
|
targetStyle = "asterisk";
|
|
24371
|
-
|
|
24475
|
+
else if (firstUnderscore)
|
|
24372
24476
|
targetStyle = "underscore";
|
|
24373
|
-
}
|
|
24374
24477
|
}
|
|
24375
|
-
let
|
|
24376
|
-
|
|
24377
|
-
|
|
24378
|
-
|
|
24379
|
-
|
|
24478
|
+
let changed = false;
|
|
24479
|
+
for (let i = 0;i < lines.length; i++) {
|
|
24480
|
+
if (inCode.has(i))
|
|
24481
|
+
continue;
|
|
24482
|
+
const after = replaceOutsideInlineCode(lines[i], (seg) => targetStyle === "asterisk" ? seg.replace(/(?<!_)_(?!_)([^_]+)_(?!_)/g, "*$1*") : seg.replace(/(?<!\*)\*(?!\*)([^*]+)\*(?!\*)/g, "_$1_"));
|
|
24483
|
+
if (after !== lines[i]) {
|
|
24484
|
+
lines[i] = after;
|
|
24485
|
+
changed = true;
|
|
24486
|
+
}
|
|
24380
24487
|
}
|
|
24381
|
-
return
|
|
24488
|
+
return changed ? lines.join(`
|
|
24489
|
+
`) : text;
|
|
24382
24490
|
}
|
|
24383
24491
|
};
|
|
24384
24492
|
});
|
|
@@ -26022,8 +26130,14 @@ var init_no_space_in_code = __esm(() => {
|
|
|
26022
26130
|
});
|
|
26023
26131
|
|
|
26024
26132
|
// src/rules/markdown/no-space-in-emphasis.ts
|
|
26025
|
-
var noSpaceInEmphasisRule;
|
|
26133
|
+
var EMPHASIS_SPACE_PATTERNS, noSpaceInEmphasisRule;
|
|
26026
26134
|
var init_no_space_in_emphasis = __esm(() => {
|
|
26135
|
+
EMPHASIS_SPACE_PATTERNS = [
|
|
26136
|
+
/(?<![A-Za-z0-9])\*\*\s+[^*]+?\*\*(?![A-Za-z0-9])/g,
|
|
26137
|
+
/(?<![A-Za-z0-9])\*\*[^*]+?\s+\*\*(?![A-Za-z0-9])/g,
|
|
26138
|
+
/(?<![A-Za-z0-9])__\s+[^_]+?__(?![A-Za-z0-9])/g,
|
|
26139
|
+
/(?<![A-Za-z0-9])__[^_]+?\s+__(?![A-Za-z0-9])/g
|
|
26140
|
+
];
|
|
26027
26141
|
noSpaceInEmphasisRule = {
|
|
26028
26142
|
meta: {
|
|
26029
26143
|
docs: "Emphasis markers should not have spaces inside them"
|
|
@@ -26041,13 +26155,7 @@ var init_no_space_in_emphasis = __esm(() => {
|
|
|
26041
26155
|
if (inFence)
|
|
26042
26156
|
continue;
|
|
26043
26157
|
const stripped = line.replace(/`[^`]+`/g, (m) => "\x01".repeat(m.length));
|
|
26044
|
-
const
|
|
26045
|
-
/\*\*\s+[^*]+?\*\*/g,
|
|
26046
|
-
/\*\*[^*]+?\s+\*\*/g,
|
|
26047
|
-
/__\s+[^_]+?__/g,
|
|
26048
|
-
/__[^_]+?\s+__/g
|
|
26049
|
-
];
|
|
26050
|
-
for (const pattern of patterns) {
|
|
26158
|
+
for (const pattern of EMPHASIS_SPACE_PATTERNS) {
|
|
26051
26159
|
for (const match of stripped.matchAll(pattern)) {
|
|
26052
26160
|
issues.push({
|
|
26053
26161
|
filePath: ctx.filePath,
|
|
@@ -26076,11 +26184,14 @@ var init_no_space_in_emphasis = __esm(() => {
|
|
|
26076
26184
|
result.push(line);
|
|
26077
26185
|
continue;
|
|
26078
26186
|
}
|
|
26079
|
-
|
|
26080
|
-
|
|
26081
|
-
|
|
26082
|
-
|
|
26083
|
-
|
|
26187
|
+
const fixed = replaceOutsideInlineCode(line, (seg) => {
|
|
26188
|
+
let s = seg;
|
|
26189
|
+
s = s.replace(/(?<![A-Za-z0-9])(\*\*)\s+([^*]+?)\*\*(?![A-Za-z0-9])/g, "$1$2**");
|
|
26190
|
+
s = s.replace(/(?<![A-Za-z0-9])(\*\*)([^*]+?)\s+\*\*(?![A-Za-z0-9])/g, "$1$2**");
|
|
26191
|
+
s = s.replace(/(?<![A-Za-z0-9])(__)\s+([^_]+?)__(?![A-Za-z0-9])/g, "$1$2__");
|
|
26192
|
+
s = s.replace(/(?<![A-Za-z0-9])(__)([^_]+?)\s+__(?![A-Za-z0-9])/g, "$1$2__");
|
|
26193
|
+
return s;
|
|
26194
|
+
});
|
|
26084
26195
|
result.push(fixed);
|
|
26085
26196
|
}
|
|
26086
26197
|
return result.join(`
|
|
@@ -39008,6 +39119,7 @@ function getCommentLines(content) {
|
|
|
39008
39119
|
let lineHasCode = false;
|
|
39009
39120
|
let lineSawComment = false;
|
|
39010
39121
|
let lineStartedInBlockComment = false;
|
|
39122
|
+
const interpStack = [];
|
|
39011
39123
|
for (let i = 0;i < content.length; i++) {
|
|
39012
39124
|
const ch = content[i];
|
|
39013
39125
|
const next = content[i + 1];
|
|
@@ -39131,6 +39243,20 @@ function getCommentLines(content) {
|
|
|
39131
39243
|
} else if (ch === "`") {
|
|
39132
39244
|
state = "string-template";
|
|
39133
39245
|
lineHasCode = true;
|
|
39246
|
+
} else if (ch === "{") {
|
|
39247
|
+
if (interpStack.length)
|
|
39248
|
+
interpStack[interpStack.length - 1]++;
|
|
39249
|
+
lineHasCode = true;
|
|
39250
|
+
} else if (ch === "}") {
|
|
39251
|
+
if (interpStack.length) {
|
|
39252
|
+
if (interpStack[interpStack.length - 1] === 0) {
|
|
39253
|
+
interpStack.pop();
|
|
39254
|
+
state = "string-template";
|
|
39255
|
+
} else {
|
|
39256
|
+
interpStack[interpStack.length - 1]--;
|
|
39257
|
+
}
|
|
39258
|
+
}
|
|
39259
|
+
lineHasCode = true;
|
|
39134
39260
|
} else if (!/\s/.test(ch)) {
|
|
39135
39261
|
lineHasCode = true;
|
|
39136
39262
|
}
|
|
@@ -39156,6 +39282,12 @@ function getCommentLines(content) {
|
|
|
39156
39282
|
i++;
|
|
39157
39283
|
break;
|
|
39158
39284
|
}
|
|
39285
|
+
if (ch === "$" && next === "{") {
|
|
39286
|
+
interpStack.push(0);
|
|
39287
|
+
state = "code";
|
|
39288
|
+
i++;
|
|
39289
|
+
break;
|
|
39290
|
+
}
|
|
39159
39291
|
if (ch === "`")
|
|
39160
39292
|
state = "code";
|
|
39161
39293
|
break;
|
|
@@ -43934,7 +44066,7 @@ var require_package = __commonJS((exports, module) => {
|
|
|
43934
44066
|
module.exports = {
|
|
43935
44067
|
name: "pickier",
|
|
43936
44068
|
type: "module",
|
|
43937
|
-
version: "0.1.
|
|
44069
|
+
version: "0.1.36",
|
|
43938
44070
|
description: "Format, lint and more in a fraction of seconds.",
|
|
43939
44071
|
author: "Chris Breuer <chris@stacksjs.org>",
|
|
43940
44072
|
license: "MIT",
|
|
@@ -30,3 +30,17 @@ export declare function getCodeBlockLines(lines: string[]): Set<number>;
|
|
|
30
30
|
* don't already have the set computed.
|
|
31
31
|
*/
|
|
32
32
|
export declare function isInsideCodeBlock(lines: string[], targetIdx: number): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Apply `transform` to the parts of `line` that are OUTSIDE inline code
|
|
35
|
+
* spans, leaving code-span text (and its backticks) verbatim. Lets
|
|
36
|
+
* emphasis/style fixers rewrite prose without corrupting literal markers
|
|
37
|
+
* such as `reverse_proxy` inside `` `caddy reverse_proxy` ``.
|
|
38
|
+
*/
|
|
39
|
+
export declare function replaceOutsideInlineCode(line: string, transform: (segment: string) => string): string;
|
|
40
|
+
/**
|
|
41
|
+
* Blank out inline code spans (replacing every character — backticks and
|
|
42
|
+
* content — with spaces) while preserving length and column positions. Used
|
|
43
|
+
* by detectors that want to scan prose for markers without matching anything
|
|
44
|
+
* inside a code span.
|
|
45
|
+
*/
|
|
46
|
+
export declare function maskInlineCode(line: string): string;
|
package/dist/src/index.js
CHANGED
|
@@ -20764,6 +20764,15 @@ var init_no_unused_vars = __esm(() => {
|
|
|
20764
20764
|
continue;
|
|
20765
20765
|
}
|
|
20766
20766
|
if (!inString) {
|
|
20767
|
+
if (ch === "/" && after[k + 1] === "/")
|
|
20768
|
+
break;
|
|
20769
|
+
if (ch === "/" && after[k + 1] === "*") {
|
|
20770
|
+
k += 2;
|
|
20771
|
+
while (k < after.length && !(after[k] === "*" && after[k + 1] === "/"))
|
|
20772
|
+
k++;
|
|
20773
|
+
k++;
|
|
20774
|
+
continue;
|
|
20775
|
+
}
|
|
20767
20776
|
if (ch === "'") {
|
|
20768
20777
|
inString = "single";
|
|
20769
20778
|
} else if (ch === '"') {
|
|
@@ -23378,24 +23387,39 @@ var init_blanks_around_lists = __esm(() => {
|
|
|
23378
23387
|
const lines = text.split(/\r?\n/);
|
|
23379
23388
|
const result = [];
|
|
23380
23389
|
let inList = false;
|
|
23390
|
+
let inFence = false;
|
|
23391
|
+
const isListItemLine = (l) => /^(?:\s*)(?:[*\-+]|\d+\.)\s+/.test(l);
|
|
23381
23392
|
for (let i = 0;i < lines.length; i++) {
|
|
23382
23393
|
const line = lines[i];
|
|
23383
23394
|
const prevLine = i > 0 ? lines[i - 1] : "";
|
|
23384
|
-
|
|
23395
|
+
if (/^(?:`{3,}|~{3,})/.test(line.trim())) {
|
|
23396
|
+
inFence = !inFence;
|
|
23397
|
+
inList = false;
|
|
23398
|
+
result.push(line);
|
|
23399
|
+
continue;
|
|
23400
|
+
}
|
|
23401
|
+
if (inFence) {
|
|
23402
|
+
result.push(line);
|
|
23403
|
+
continue;
|
|
23404
|
+
}
|
|
23405
|
+
const isListItem = isListItemLine(line);
|
|
23406
|
+
const isBlank = line.trim().length === 0;
|
|
23407
|
+
const isContinuation = inList && !isListItem && !isBlank && /^\s/.test(line);
|
|
23385
23408
|
if (isListItem && !inList) {
|
|
23386
23409
|
if (i > 0 && prevLine.trim().length > 0 && result.length > 0) {
|
|
23387
23410
|
result.push("");
|
|
23388
23411
|
}
|
|
23389
23412
|
inList = true;
|
|
23390
|
-
} else if (!isListItem &&
|
|
23413
|
+
} else if (!isListItem && !isContinuation && !isBlank && inList) {
|
|
23391
23414
|
inList = false;
|
|
23392
23415
|
if (result.length > 0) {
|
|
23393
23416
|
result.push("");
|
|
23394
23417
|
}
|
|
23395
|
-
} else if (
|
|
23418
|
+
} else if (isBlank) {
|
|
23396
23419
|
const nextLine = i + 1 < lines.length ? lines[i + 1] : "";
|
|
23397
|
-
const nextIsListItem =
|
|
23398
|
-
|
|
23420
|
+
const nextIsListItem = isListItemLine(nextLine);
|
|
23421
|
+
const nextIsContinuation = /^\s+\S/.test(nextLine);
|
|
23422
|
+
if (!nextIsListItem && !nextIsContinuation && inList) {
|
|
23399
23423
|
inList = false;
|
|
23400
23424
|
}
|
|
23401
23425
|
}
|
|
@@ -23466,6 +23490,64 @@ function getCodeBlockLines(lines) {
|
|
|
23466
23490
|
}
|
|
23467
23491
|
return out;
|
|
23468
23492
|
}
|
|
23493
|
+
function eachInlineSegment(line, onText, onCode) {
|
|
23494
|
+
let i = 0;
|
|
23495
|
+
let textStart = 0;
|
|
23496
|
+
while (i < line.length) {
|
|
23497
|
+
if (line[i] !== "`") {
|
|
23498
|
+
i++;
|
|
23499
|
+
continue;
|
|
23500
|
+
}
|
|
23501
|
+
let n = 0;
|
|
23502
|
+
while (line[i + n] === "`")
|
|
23503
|
+
n++;
|
|
23504
|
+
let j = i + n;
|
|
23505
|
+
let close = -1;
|
|
23506
|
+
while (j < line.length) {
|
|
23507
|
+
if (line[j] === "`") {
|
|
23508
|
+
let k = 0;
|
|
23509
|
+
while (line[j + k] === "`")
|
|
23510
|
+
k++;
|
|
23511
|
+
if (k === n) {
|
|
23512
|
+
close = j;
|
|
23513
|
+
break;
|
|
23514
|
+
}
|
|
23515
|
+
j += k;
|
|
23516
|
+
} else {
|
|
23517
|
+
j++;
|
|
23518
|
+
}
|
|
23519
|
+
}
|
|
23520
|
+
if (close === -1) {
|
|
23521
|
+
i += n;
|
|
23522
|
+
continue;
|
|
23523
|
+
}
|
|
23524
|
+
if (textStart < i)
|
|
23525
|
+
onText(line.slice(textStart, i));
|
|
23526
|
+
onCode(line.slice(i, close + n));
|
|
23527
|
+
i = close + n;
|
|
23528
|
+
textStart = i;
|
|
23529
|
+
}
|
|
23530
|
+
if (textStart < line.length)
|
|
23531
|
+
onText(line.slice(textStart));
|
|
23532
|
+
}
|
|
23533
|
+
function replaceOutsideInlineCode(line, transform) {
|
|
23534
|
+
let out = "";
|
|
23535
|
+
eachInlineSegment(line, (seg) => {
|
|
23536
|
+
out += transform(seg);
|
|
23537
|
+
}, (seg) => {
|
|
23538
|
+
out += seg;
|
|
23539
|
+
});
|
|
23540
|
+
return out;
|
|
23541
|
+
}
|
|
23542
|
+
function maskInlineCode(line) {
|
|
23543
|
+
let out = "";
|
|
23544
|
+
eachInlineSegment(line, (seg) => {
|
|
23545
|
+
out += seg;
|
|
23546
|
+
}, (seg) => {
|
|
23547
|
+
out += " ".repeat(seg.length);
|
|
23548
|
+
});
|
|
23549
|
+
return out;
|
|
23550
|
+
}
|
|
23469
23551
|
|
|
23470
23552
|
// src/rules/markdown/_shared.ts
|
|
23471
23553
|
function findTableRows(lines) {
|
|
@@ -23876,8 +23958,10 @@ var init_descriptive_link_text = __esm(() => {
|
|
|
23876
23958
|
});
|
|
23877
23959
|
|
|
23878
23960
|
// src/rules/markdown/emphasis-style.ts
|
|
23879
|
-
var emphasisStyleRule;
|
|
23961
|
+
var ASTERISK_EMPHASIS, UNDERSCORE_EMPHASIS, emphasisStyleRule;
|
|
23880
23962
|
var init_emphasis_style = __esm(() => {
|
|
23963
|
+
ASTERISK_EMPHASIS = /(?<!\*)\*(?!\*)([^*]+)\*(?!\*)/;
|
|
23964
|
+
UNDERSCORE_EMPHASIS = /(?<!_)_(?!_)([^_]+)_(?!_)/;
|
|
23881
23965
|
emphasisStyleRule = {
|
|
23882
23966
|
meta: {
|
|
23883
23967
|
docs: "Emphasis style should be consistent (asterisk or underscore)"
|
|
@@ -23956,27 +24040,51 @@ var init_emphasis_style = __esm(() => {
|
|
|
23956
24040
|
fix: (text, ctx) => {
|
|
23957
24041
|
const options = ctx.options || {};
|
|
23958
24042
|
const style = options.style || "consistent";
|
|
24043
|
+
const lines = text.split(/\r?\n/);
|
|
24044
|
+
const inCode = getCodeBlockLines(lines);
|
|
23959
24045
|
let targetStyle = "asterisk";
|
|
23960
24046
|
if (style === "asterisk") {
|
|
23961
24047
|
targetStyle = "asterisk";
|
|
23962
24048
|
} else if (style === "underscore") {
|
|
23963
24049
|
targetStyle = "underscore";
|
|
23964
24050
|
} else if (style === "consistent") {
|
|
23965
|
-
|
|
23966
|
-
|
|
23967
|
-
|
|
24051
|
+
let firstAsterisk = null;
|
|
24052
|
+
let firstUnderscore = null;
|
|
24053
|
+
for (let i = 0;i < lines.length; i++) {
|
|
24054
|
+
if (inCode.has(i))
|
|
24055
|
+
continue;
|
|
24056
|
+
const stripped = maskInlineCode(lines[i]);
|
|
24057
|
+
if (firstAsterisk === null) {
|
|
24058
|
+
const m = stripped.match(ASTERISK_EMPHASIS);
|
|
24059
|
+
if (m)
|
|
24060
|
+
firstAsterisk = { line: i, col: m.index };
|
|
24061
|
+
}
|
|
24062
|
+
if (firstUnderscore === null) {
|
|
24063
|
+
const m = stripped.match(UNDERSCORE_EMPHASIS);
|
|
24064
|
+
if (m)
|
|
24065
|
+
firstUnderscore = { line: i, col: m.index };
|
|
24066
|
+
}
|
|
24067
|
+
if (firstAsterisk && firstUnderscore)
|
|
24068
|
+
break;
|
|
24069
|
+
}
|
|
24070
|
+
const cmp = (a, b) => a.line !== b.line ? a.line - b.line : a.col - b.col;
|
|
24071
|
+
if (firstAsterisk && (!firstUnderscore || cmp(firstAsterisk, firstUnderscore) < 0))
|
|
23968
24072
|
targetStyle = "asterisk";
|
|
23969
|
-
|
|
24073
|
+
else if (firstUnderscore)
|
|
23970
24074
|
targetStyle = "underscore";
|
|
23971
|
-
}
|
|
23972
24075
|
}
|
|
23973
|
-
let
|
|
23974
|
-
|
|
23975
|
-
|
|
23976
|
-
|
|
23977
|
-
|
|
24076
|
+
let changed = false;
|
|
24077
|
+
for (let i = 0;i < lines.length; i++) {
|
|
24078
|
+
if (inCode.has(i))
|
|
24079
|
+
continue;
|
|
24080
|
+
const after = replaceOutsideInlineCode(lines[i], (seg) => targetStyle === "asterisk" ? seg.replace(/(?<!_)_(?!_)([^_]+)_(?!_)/g, "*$1*") : seg.replace(/(?<!\*)\*(?!\*)([^*]+)\*(?!\*)/g, "_$1_"));
|
|
24081
|
+
if (after !== lines[i]) {
|
|
24082
|
+
lines[i] = after;
|
|
24083
|
+
changed = true;
|
|
24084
|
+
}
|
|
23978
24085
|
}
|
|
23979
|
-
return
|
|
24086
|
+
return changed ? lines.join(`
|
|
24087
|
+
`) : text;
|
|
23980
24088
|
}
|
|
23981
24089
|
};
|
|
23982
24090
|
});
|
|
@@ -25620,8 +25728,14 @@ var init_no_space_in_code = __esm(() => {
|
|
|
25620
25728
|
});
|
|
25621
25729
|
|
|
25622
25730
|
// src/rules/markdown/no-space-in-emphasis.ts
|
|
25623
|
-
var noSpaceInEmphasisRule;
|
|
25731
|
+
var EMPHASIS_SPACE_PATTERNS, noSpaceInEmphasisRule;
|
|
25624
25732
|
var init_no_space_in_emphasis = __esm(() => {
|
|
25733
|
+
EMPHASIS_SPACE_PATTERNS = [
|
|
25734
|
+
/(?<![A-Za-z0-9])\*\*\s+[^*]+?\*\*(?![A-Za-z0-9])/g,
|
|
25735
|
+
/(?<![A-Za-z0-9])\*\*[^*]+?\s+\*\*(?![A-Za-z0-9])/g,
|
|
25736
|
+
/(?<![A-Za-z0-9])__\s+[^_]+?__(?![A-Za-z0-9])/g,
|
|
25737
|
+
/(?<![A-Za-z0-9])__[^_]+?\s+__(?![A-Za-z0-9])/g
|
|
25738
|
+
];
|
|
25625
25739
|
noSpaceInEmphasisRule = {
|
|
25626
25740
|
meta: {
|
|
25627
25741
|
docs: "Emphasis markers should not have spaces inside them"
|
|
@@ -25639,13 +25753,7 @@ var init_no_space_in_emphasis = __esm(() => {
|
|
|
25639
25753
|
if (inFence)
|
|
25640
25754
|
continue;
|
|
25641
25755
|
const stripped = line.replace(/`[^`]+`/g, (m) => "\x01".repeat(m.length));
|
|
25642
|
-
const
|
|
25643
|
-
/\*\*\s+[^*]+?\*\*/g,
|
|
25644
|
-
/\*\*[^*]+?\s+\*\*/g,
|
|
25645
|
-
/__\s+[^_]+?__/g,
|
|
25646
|
-
/__[^_]+?\s+__/g
|
|
25647
|
-
];
|
|
25648
|
-
for (const pattern of patterns) {
|
|
25756
|
+
for (const pattern of EMPHASIS_SPACE_PATTERNS) {
|
|
25649
25757
|
for (const match of stripped.matchAll(pattern)) {
|
|
25650
25758
|
issues.push({
|
|
25651
25759
|
filePath: ctx.filePath,
|
|
@@ -25674,11 +25782,14 @@ var init_no_space_in_emphasis = __esm(() => {
|
|
|
25674
25782
|
result.push(line);
|
|
25675
25783
|
continue;
|
|
25676
25784
|
}
|
|
25677
|
-
|
|
25678
|
-
|
|
25679
|
-
|
|
25680
|
-
|
|
25681
|
-
|
|
25785
|
+
const fixed = replaceOutsideInlineCode(line, (seg) => {
|
|
25786
|
+
let s = seg;
|
|
25787
|
+
s = s.replace(/(?<![A-Za-z0-9])(\*\*)\s+([^*]+?)\*\*(?![A-Za-z0-9])/g, "$1$2**");
|
|
25788
|
+
s = s.replace(/(?<![A-Za-z0-9])(\*\*)([^*]+?)\s+\*\*(?![A-Za-z0-9])/g, "$1$2**");
|
|
25789
|
+
s = s.replace(/(?<![A-Za-z0-9])(__)\s+([^_]+?)__(?![A-Za-z0-9])/g, "$1$2__");
|
|
25790
|
+
s = s.replace(/(?<![A-Za-z0-9])(__)([^_]+?)\s+__(?![A-Za-z0-9])/g, "$1$2__");
|
|
25791
|
+
return s;
|
|
25792
|
+
});
|
|
25682
25793
|
result.push(fixed);
|
|
25683
25794
|
}
|
|
25684
25795
|
return result.join(`
|
|
@@ -39007,6 +39118,7 @@ function getCommentLines(content) {
|
|
|
39007
39118
|
let lineHasCode = false;
|
|
39008
39119
|
let lineSawComment = false;
|
|
39009
39120
|
let lineStartedInBlockComment = false;
|
|
39121
|
+
const interpStack = [];
|
|
39010
39122
|
for (let i = 0;i < content.length; i++) {
|
|
39011
39123
|
const ch = content[i];
|
|
39012
39124
|
const next = content[i + 1];
|
|
@@ -39130,6 +39242,20 @@ function getCommentLines(content) {
|
|
|
39130
39242
|
} else if (ch === "`") {
|
|
39131
39243
|
state = "string-template";
|
|
39132
39244
|
lineHasCode = true;
|
|
39245
|
+
} else if (ch === "{") {
|
|
39246
|
+
if (interpStack.length)
|
|
39247
|
+
interpStack[interpStack.length - 1]++;
|
|
39248
|
+
lineHasCode = true;
|
|
39249
|
+
} else if (ch === "}") {
|
|
39250
|
+
if (interpStack.length) {
|
|
39251
|
+
if (interpStack[interpStack.length - 1] === 0) {
|
|
39252
|
+
interpStack.pop();
|
|
39253
|
+
state = "string-template";
|
|
39254
|
+
} else {
|
|
39255
|
+
interpStack[interpStack.length - 1]--;
|
|
39256
|
+
}
|
|
39257
|
+
}
|
|
39258
|
+
lineHasCode = true;
|
|
39133
39259
|
} else if (!/\s/.test(ch)) {
|
|
39134
39260
|
lineHasCode = true;
|
|
39135
39261
|
}
|
|
@@ -39155,6 +39281,12 @@ function getCommentLines(content) {
|
|
|
39155
39281
|
i++;
|
|
39156
39282
|
break;
|
|
39157
39283
|
}
|
|
39284
|
+
if (ch === "$" && next === "{") {
|
|
39285
|
+
interpStack.push(0);
|
|
39286
|
+
state = "code";
|
|
39287
|
+
i++;
|
|
39288
|
+
break;
|
|
39289
|
+
}
|
|
39158
39290
|
if (ch === "`")
|
|
39159
39291
|
state = "code";
|
|
39160
39292
|
break;
|