eslint-plugin-markdown-preferences 0.31.0 → 0.33.0
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/lib/index.d.ts +7 -1
- package/lib/index.js +177 -43
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -478,6 +478,12 @@ type MarkdownPreferencesTableLeadingTrailingPipes = [] | [(("always" | "never")
|
|
|
478
478
|
})];
|
|
479
479
|
type MarkdownPreferencesTablePipeAlignment = [] | [{
|
|
480
480
|
column?: ("minimum" | "consistent");
|
|
481
|
+
delimiterMinLength?: ("minimum" | number | {
|
|
482
|
+
defaultDelimiter?: number;
|
|
483
|
+
leftAlignmentDelimiter?: number;
|
|
484
|
+
centerAlignmentDelimiter?: number;
|
|
485
|
+
rightAlignmentDelimiter?: number;
|
|
486
|
+
});
|
|
481
487
|
}];
|
|
482
488
|
type MarkdownPreferencesTablePipeSpacing = [] | [{
|
|
483
489
|
space?: (("always" | "never") | {
|
|
@@ -532,7 +538,7 @@ declare namespace meta_d_exports {
|
|
|
532
538
|
export { name, version };
|
|
533
539
|
}
|
|
534
540
|
declare const name: "eslint-plugin-markdown-preferences";
|
|
535
|
-
declare const version: "0.
|
|
541
|
+
declare const version: "0.33.0";
|
|
536
542
|
//#endregion
|
|
537
543
|
//#region src/language/ast-types.d.ts
|
|
538
544
|
type Node = mdast.Node;
|
package/lib/index.js
CHANGED
|
@@ -828,7 +828,7 @@ function getOtherMarker(unavailableMarker) {
|
|
|
828
828
|
/**
|
|
829
829
|
* Parse rule options.
|
|
830
830
|
*/
|
|
831
|
-
function parseOptions$
|
|
831
|
+
function parseOptions$6(options) {
|
|
832
832
|
const primary = options.primary || "-";
|
|
833
833
|
const secondary = options.secondary || getOtherMarker(primary);
|
|
834
834
|
if (primary === secondary) throw new Error(`\`primary\` and \`secondary\` cannot be the same (primary: "${primary}", secondary: "${secondary}").`);
|
|
@@ -896,7 +896,7 @@ var bullet_list_marker_style_default = createRule("bullet-list-marker-style", {
|
|
|
896
896
|
},
|
|
897
897
|
create(context) {
|
|
898
898
|
const sourceCode = context.sourceCode;
|
|
899
|
-
const options = parseOptions$
|
|
899
|
+
const options = parseOptions$6(context.options[0] || {});
|
|
900
900
|
let containerStack = {
|
|
901
901
|
node: sourceCode.ast,
|
|
902
902
|
level: 1,
|
|
@@ -1509,7 +1509,7 @@ var custom_container_marker_spacing_default = createRule("custom-container-marke
|
|
|
1509
1509
|
/**
|
|
1510
1510
|
* Parse options with defaults.
|
|
1511
1511
|
*/
|
|
1512
|
-
function parseOptions$
|
|
1512
|
+
function parseOptions$5(options) {
|
|
1513
1513
|
const linkDefinitionPlacement = {
|
|
1514
1514
|
referencedFromSingleSection: options?.linkDefinitionPlacement?.referencedFromSingleSection || "document-last",
|
|
1515
1515
|
referencedFromMultipleSections: options?.linkDefinitionPlacement?.referencedFromMultipleSections || "document-last"
|
|
@@ -1583,7 +1583,7 @@ var definitions_last_default = createRule("definitions-last", {
|
|
|
1583
1583
|
},
|
|
1584
1584
|
create(context) {
|
|
1585
1585
|
const sourceCode = context.sourceCode;
|
|
1586
|
-
const options = parseOptions$
|
|
1586
|
+
const options = parseOptions$5(context.options[0]);
|
|
1587
1587
|
/**
|
|
1588
1588
|
* Determine whether a node can be placed as the last node of the document or a section.
|
|
1589
1589
|
*/
|
|
@@ -5594,7 +5594,7 @@ function parseMathClosingSequenceFromText(text) {
|
|
|
5594
5594
|
/**
|
|
5595
5595
|
* Parse options.
|
|
5596
5596
|
*/
|
|
5597
|
-
function parseOptions$
|
|
5597
|
+
function parseOptions$4(options) {
|
|
5598
5598
|
const listItems = options?.listItems;
|
|
5599
5599
|
return { listItems: {
|
|
5600
5600
|
first: listItems?.first ?? 1,
|
|
@@ -5647,7 +5647,7 @@ var indent_default = createRule("indent", {
|
|
|
5647
5647
|
},
|
|
5648
5648
|
create(context) {
|
|
5649
5649
|
const sourceCode = context.sourceCode;
|
|
5650
|
-
const options = parseOptions$
|
|
5650
|
+
const options = parseOptions$4(context.options[0]);
|
|
5651
5651
|
class AbsBlockStack {
|
|
5652
5652
|
violations = [];
|
|
5653
5653
|
getCurrentBlockquote() {
|
|
@@ -6817,11 +6817,11 @@ var link_bracket_newline_default = createRule("link-bracket-newline", {
|
|
|
6817
6817
|
},
|
|
6818
6818
|
create(context) {
|
|
6819
6819
|
const sourceCode = context.sourceCode;
|
|
6820
|
-
const optionProvider = parseOptions$
|
|
6820
|
+
const optionProvider = parseOptions$7(context.options[0]);
|
|
6821
6821
|
/**
|
|
6822
6822
|
* Parse the options.
|
|
6823
6823
|
*/
|
|
6824
|
-
function parseOptions$
|
|
6824
|
+
function parseOptions$7(option) {
|
|
6825
6825
|
const newline = option?.newline ?? "never";
|
|
6826
6826
|
const multiline = option?.multiline ?? false;
|
|
6827
6827
|
return (bracketsRange) => {
|
|
@@ -6952,7 +6952,7 @@ var link_bracket_newline_default = createRule("link-bracket-newline", {
|
|
|
6952
6952
|
/**
|
|
6953
6953
|
* The basic option for links and images.
|
|
6954
6954
|
*/
|
|
6955
|
-
function parseOptions$
|
|
6955
|
+
function parseOptions$3(option) {
|
|
6956
6956
|
const space = option?.space ?? "never";
|
|
6957
6957
|
const imagesInLinks = option?.imagesInLinks;
|
|
6958
6958
|
return {
|
|
@@ -7002,7 +7002,7 @@ var link_bracket_spacing_default = createRule("link-bracket-spacing", {
|
|
|
7002
7002
|
},
|
|
7003
7003
|
create(context) {
|
|
7004
7004
|
const sourceCode = context.sourceCode;
|
|
7005
|
-
const options = parseOptions$
|
|
7005
|
+
const options = parseOptions$3(context.options[0]);
|
|
7006
7006
|
/**
|
|
7007
7007
|
* Verify the space after the opening bracket and before the closing bracket.
|
|
7008
7008
|
*/
|
|
@@ -7295,11 +7295,11 @@ var link_paren_newline_default = createRule("link-paren-newline", {
|
|
|
7295
7295
|
},
|
|
7296
7296
|
create(context) {
|
|
7297
7297
|
const sourceCode = context.sourceCode;
|
|
7298
|
-
const optionProvider = parseOptions$
|
|
7298
|
+
const optionProvider = parseOptions$7(context.options[0]);
|
|
7299
7299
|
/**
|
|
7300
7300
|
* Parse the options.
|
|
7301
7301
|
*/
|
|
7302
|
-
function parseOptions$
|
|
7302
|
+
function parseOptions$7(option) {
|
|
7303
7303
|
const newline = option?.newline ?? "never";
|
|
7304
7304
|
const multiline = option?.multiline ?? false;
|
|
7305
7305
|
return (openingParenIndex, closingParenIndex) => {
|
|
@@ -8905,7 +8905,7 @@ function markerToKind(marker) {
|
|
|
8905
8905
|
/**
|
|
8906
8906
|
* Parse rule options.
|
|
8907
8907
|
*/
|
|
8908
|
-
function parseOptions$
|
|
8908
|
+
function parseOptions$2(options) {
|
|
8909
8909
|
const prefer = markerToKind(options.prefer) || ".";
|
|
8910
8910
|
const overrides = (options.overrides ?? []).map((override) => {
|
|
8911
8911
|
const preferForOverride = markerToKind(override.prefer) || ".";
|
|
@@ -8966,7 +8966,7 @@ var ordered_list_marker_style_default = createRule("ordered-list-marker-style",
|
|
|
8966
8966
|
},
|
|
8967
8967
|
create(context) {
|
|
8968
8968
|
const sourceCode = context.sourceCode;
|
|
8969
|
-
const options = parseOptions$
|
|
8969
|
+
const options = parseOptions$2(context.options[0] || {});
|
|
8970
8970
|
let containerStack = {
|
|
8971
8971
|
node: sourceCode.ast,
|
|
8972
8972
|
level: 1,
|
|
@@ -10819,7 +10819,7 @@ function getCurrentTablePipeSpacingOption(sourceCode) {
|
|
|
10819
10819
|
/**
|
|
10820
10820
|
* Parsed options
|
|
10821
10821
|
*/
|
|
10822
|
-
function parseOptions(options) {
|
|
10822
|
+
function parseOptions$1(options) {
|
|
10823
10823
|
const spaceOption = options?.space;
|
|
10824
10824
|
const leadingSpace = (typeof spaceOption === "object" ? spaceOption.leading : spaceOption) || "always";
|
|
10825
10825
|
const trailingSpace = (typeof spaceOption === "object" ? spaceOption.trailing : spaceOption) || "always";
|
|
@@ -10929,7 +10929,7 @@ var table_pipe_spacing_default = createRule("table-pipe-spacing", {
|
|
|
10929
10929
|
},
|
|
10930
10930
|
create(context) {
|
|
10931
10931
|
const sourceCode = context.sourceCode;
|
|
10932
|
-
const options = parseOptions(context.options[0]);
|
|
10932
|
+
const options = parseOptions$1(context.options[0]);
|
|
10933
10933
|
currentOption.set(sourceCode, options);
|
|
10934
10934
|
/**
|
|
10935
10935
|
* Verify for the leading pipe.
|
|
@@ -11190,6 +11190,38 @@ var table_pipe_spacing_default = createRule("table-pipe-spacing", {
|
|
|
11190
11190
|
|
|
11191
11191
|
//#endregion
|
|
11192
11192
|
//#region src/rules/table-pipe-alignment.ts
|
|
11193
|
+
/**
|
|
11194
|
+
* Parse and normalize options
|
|
11195
|
+
*/
|
|
11196
|
+
function parseOptions(options) {
|
|
11197
|
+
const columnOption = options?.column || "minimum";
|
|
11198
|
+
const delimiterMinLengthOption = options?.delimiterMinLength || 3;
|
|
11199
|
+
let delimiterMinLength;
|
|
11200
|
+
if (delimiterMinLengthOption === "minimum" || delimiterMinLengthOption == null) delimiterMinLength = {
|
|
11201
|
+
defaultDelimiter: 1,
|
|
11202
|
+
leftAlignmentDelimiter: 2,
|
|
11203
|
+
centerAlignmentDelimiter: 3,
|
|
11204
|
+
rightAlignmentDelimiter: 2
|
|
11205
|
+
};
|
|
11206
|
+
else if (typeof delimiterMinLengthOption === "number") {
|
|
11207
|
+
const v = Math.max(3, delimiterMinLengthOption);
|
|
11208
|
+
delimiterMinLength = {
|
|
11209
|
+
defaultDelimiter: v,
|
|
11210
|
+
leftAlignmentDelimiter: v,
|
|
11211
|
+
centerAlignmentDelimiter: v,
|
|
11212
|
+
rightAlignmentDelimiter: v
|
|
11213
|
+
};
|
|
11214
|
+
} else delimiterMinLength = {
|
|
11215
|
+
defaultDelimiter: typeof delimiterMinLengthOption.defaultDelimiter === "number" ? Math.max(1, delimiterMinLengthOption.defaultDelimiter) : 3,
|
|
11216
|
+
leftAlignmentDelimiter: typeof delimiterMinLengthOption.leftAlignmentDelimiter === "number" ? Math.max(2, delimiterMinLengthOption.leftAlignmentDelimiter) : 3,
|
|
11217
|
+
centerAlignmentDelimiter: typeof delimiterMinLengthOption.centerAlignmentDelimiter === "number" ? Math.max(3, delimiterMinLengthOption.centerAlignmentDelimiter) : 3,
|
|
11218
|
+
rightAlignmentDelimiter: typeof delimiterMinLengthOption.rightAlignmentDelimiter === "number" ? Math.max(2, delimiterMinLengthOption.rightAlignmentDelimiter) : 3
|
|
11219
|
+
};
|
|
11220
|
+
return {
|
|
11221
|
+
columnOption,
|
|
11222
|
+
delimiterMinLength
|
|
11223
|
+
};
|
|
11224
|
+
}
|
|
11193
11225
|
var table_pipe_alignment_default = createRule("table-pipe-alignment", {
|
|
11194
11226
|
meta: {
|
|
11195
11227
|
type: "layout",
|
|
@@ -11202,7 +11234,38 @@ var table_pipe_alignment_default = createRule("table-pipe-alignment", {
|
|
|
11202
11234
|
hasSuggestions: false,
|
|
11203
11235
|
schema: [{
|
|
11204
11236
|
type: "object",
|
|
11205
|
-
properties: {
|
|
11237
|
+
properties: {
|
|
11238
|
+
column: { enum: ["minimum", "consistent"] },
|
|
11239
|
+
delimiterMinLength: { anyOf: [
|
|
11240
|
+
{ const: "minimum" },
|
|
11241
|
+
{
|
|
11242
|
+
type: "number",
|
|
11243
|
+
minimum: 3
|
|
11244
|
+
},
|
|
11245
|
+
{
|
|
11246
|
+
type: "object",
|
|
11247
|
+
properties: {
|
|
11248
|
+
defaultDelimiter: {
|
|
11249
|
+
type: "number",
|
|
11250
|
+
minimum: 1
|
|
11251
|
+
},
|
|
11252
|
+
leftAlignmentDelimiter: {
|
|
11253
|
+
type: "number",
|
|
11254
|
+
minimum: 2
|
|
11255
|
+
},
|
|
11256
|
+
centerAlignmentDelimiter: {
|
|
11257
|
+
type: "number",
|
|
11258
|
+
minimum: 3
|
|
11259
|
+
},
|
|
11260
|
+
rightAlignmentDelimiter: {
|
|
11261
|
+
type: "number",
|
|
11262
|
+
minimum: 2
|
|
11263
|
+
}
|
|
11264
|
+
},
|
|
11265
|
+
additionalProperties: false
|
|
11266
|
+
}
|
|
11267
|
+
] }
|
|
11268
|
+
},
|
|
11206
11269
|
additionalProperties: false
|
|
11207
11270
|
}],
|
|
11208
11271
|
messages: {
|
|
@@ -11212,14 +11275,17 @@ var table_pipe_alignment_default = createRule("table-pipe-alignment", {
|
|
|
11212
11275
|
},
|
|
11213
11276
|
create(context) {
|
|
11214
11277
|
const sourceCode = context.sourceCode;
|
|
11215
|
-
const
|
|
11278
|
+
const options = parseOptions(context.options[0]);
|
|
11216
11279
|
class TableContext {
|
|
11217
11280
|
rows;
|
|
11281
|
+
delimiterRow;
|
|
11218
11282
|
columnCount;
|
|
11219
|
-
|
|
11283
|
+
_cacheNeedSpaceBetweenLeadingPipeAndContent = /* @__PURE__ */ new Map();
|
|
11284
|
+
_cacheNeedSpaceBetweenContentAndTrailingPipe = /* @__PURE__ */ new Map();
|
|
11220
11285
|
_cacheExpectedPipePosition = /* @__PURE__ */ new Map();
|
|
11221
11286
|
constructor(parsed) {
|
|
11222
|
-
|
|
11287
|
+
this.delimiterRow = parsedTableDelimiterRowToRowData(parsed.delimiterRow);
|
|
11288
|
+
const rows = [parsedTableRowToRowData(parsed.headerRow), this.delimiterRow];
|
|
11223
11289
|
for (const bodyRow of parsed.bodyRows) rows.push(parsedTableRowToRowData(bodyRow));
|
|
11224
11290
|
this.rows = rows;
|
|
11225
11291
|
let columnCount = 0;
|
|
@@ -11237,17 +11303,29 @@ var table_pipe_alignment_default = createRule("table-pipe-alignment", {
|
|
|
11237
11303
|
return v;
|
|
11238
11304
|
}
|
|
11239
11305
|
/**
|
|
11306
|
+
* Check if there is at least one space between leading pipe and content
|
|
11307
|
+
*/
|
|
11308
|
+
isNeedSpaceBetweenLeadingPipeAndContent(pipeIndex) {
|
|
11309
|
+
let v = this._cacheNeedSpaceBetweenLeadingPipeAndContent.get(pipeIndex);
|
|
11310
|
+
if (v != null) return v;
|
|
11311
|
+
if (getCurrentTablePipeSpacingOption(sourceCode)?.leadingSpace === "always") v = true;
|
|
11312
|
+
else v = this._hasSpaceBetweenLeadingPipeAndContentWithoutCache(pipeIndex);
|
|
11313
|
+
this._cacheNeedSpaceBetweenLeadingPipeAndContent.set(pipeIndex, v);
|
|
11314
|
+
return v;
|
|
11315
|
+
}
|
|
11316
|
+
/**
|
|
11240
11317
|
* Check if there is at least one space between content and trailing pipe
|
|
11241
11318
|
* for the index
|
|
11242
11319
|
*
|
|
11243
11320
|
* This is used to determine if the pipe should be aligned with a space before it.
|
|
11244
11321
|
*/
|
|
11245
|
-
|
|
11322
|
+
isNeedSpaceBetweenContentAndTrailingPipe(pipeIndex) {
|
|
11246
11323
|
if (pipeIndex === 0) return false;
|
|
11247
|
-
let v = this.
|
|
11324
|
+
let v = this._cacheNeedSpaceBetweenContentAndTrailingPipe.get(pipeIndex);
|
|
11248
11325
|
if (v != null) return v;
|
|
11249
|
-
v =
|
|
11250
|
-
this.
|
|
11326
|
+
if (getCurrentTablePipeSpacingOption(sourceCode)?.trailingSpace === "always") v = true;
|
|
11327
|
+
else v = this._hasSpaceBetweenContentAndTrailingPipeWithoutCache(pipeIndex);
|
|
11328
|
+
this._cacheNeedSpaceBetweenContentAndTrailingPipe.set(pipeIndex, v);
|
|
11251
11329
|
return v;
|
|
11252
11330
|
}
|
|
11253
11331
|
/**
|
|
@@ -11258,16 +11336,16 @@ var table_pipe_alignment_default = createRule("table-pipe-alignment", {
|
|
|
11258
11336
|
const firstCell = this.rows[0].cells[0];
|
|
11259
11337
|
const firstToken = firstCell.leadingPipe ?? firstCell.content;
|
|
11260
11338
|
if (!firstToken) return null;
|
|
11261
|
-
return getTextWidth(sourceCode.lines[firstToken.loc.start.line - 1]
|
|
11339
|
+
return getTextWidth(sourceCode.lines[firstToken.loc.start.line - 1], 0, firstToken.loc.start.column - 1);
|
|
11262
11340
|
}
|
|
11263
|
-
if (columnOption === "minimum") return this.getMinimumPipePosition(pipeIndex);
|
|
11264
|
-
else if (columnOption === "consistent") {
|
|
11341
|
+
if (options.columnOption === "minimum") return this.getMinimumPipePosition(pipeIndex);
|
|
11342
|
+
else if (options.columnOption === "consistent") {
|
|
11265
11343
|
const columnIndex = pipeIndex - 1;
|
|
11266
11344
|
for (const row of this.rows) {
|
|
11267
11345
|
if (row.cells.length <= columnIndex) continue;
|
|
11268
11346
|
const cell = row.cells[columnIndex];
|
|
11269
11347
|
if (cell.type === "delimiter" || !cell.trailingPipe) continue;
|
|
11270
|
-
const width = getTextWidth(sourceCode.lines[cell.trailingPipe.loc.start.line - 1]
|
|
11348
|
+
const width = getTextWidth(sourceCode.lines[cell.trailingPipe.loc.start.line - 1], 0, cell.trailingPipe.loc.start.column - 1);
|
|
11271
11349
|
return Math.max(width, this.getMinimumPipePosition(pipeIndex) || 0);
|
|
11272
11350
|
}
|
|
11273
11351
|
}
|
|
@@ -11277,20 +11355,29 @@ var table_pipe_alignment_default = createRule("table-pipe-alignment", {
|
|
|
11277
11355
|
* Get the minimum pipe position for the index
|
|
11278
11356
|
*/
|
|
11279
11357
|
getMinimumPipePosition(pipeIndex) {
|
|
11280
|
-
const
|
|
11281
|
-
const needSpaceBeforePipe =
|
|
11358
|
+
const needSpaceAfterPipe = this.isNeedSpaceBetweenLeadingPipeAndContent(pipeIndex - 1);
|
|
11359
|
+
const needSpaceBeforePipe = this.isNeedSpaceBetweenContentAndTrailingPipe(pipeIndex);
|
|
11282
11360
|
let maxWidth = 0;
|
|
11283
11361
|
const columnIndex = pipeIndex - 1;
|
|
11284
11362
|
for (const row of this.rows) {
|
|
11285
11363
|
if (row.cells.length <= columnIndex) continue;
|
|
11286
11364
|
const cell = row.cells[columnIndex];
|
|
11287
11365
|
let width;
|
|
11288
|
-
if (cell.
|
|
11366
|
+
if (cell.leadingPipe) {
|
|
11367
|
+
const leadingPipeEndOffset = getTextWidth(sourceCode.lines[cell.leadingPipe.loc.end.line - 1], 0, cell.leadingPipe.loc.end.column - 1);
|
|
11368
|
+
let contentLength;
|
|
11369
|
+
if (cell.type === "delimiter") contentLength = getMinimumDelimiterLength(cell.align);
|
|
11370
|
+
else {
|
|
11371
|
+
if (!cell.content) continue;
|
|
11372
|
+
contentLength = getTextWidth(sourceCode.lines[cell.content.loc.start.line - 1], cell.content.loc.start.column - 1, cell.content.loc.end.column - 1);
|
|
11373
|
+
}
|
|
11374
|
+
width = leadingPipeEndOffset + (needSpaceAfterPipe ? 1 : 0) + contentLength;
|
|
11375
|
+
} else if (cell.type === "delimiter") {
|
|
11289
11376
|
const minimumDelimiterLength = getMinimumDelimiterLength(cell.align);
|
|
11290
|
-
width = getTextWidth(sourceCode.lines[cell.delimiter.loc.start.line - 1]
|
|
11377
|
+
width = getTextWidth(sourceCode.lines[cell.delimiter.loc.start.line - 1], 0, cell.delimiter.loc.start.column - 1) + minimumDelimiterLength;
|
|
11291
11378
|
} else {
|
|
11292
11379
|
if (!cell.content) continue;
|
|
11293
|
-
width = getTextWidth(sourceCode.lines[cell.content.loc.end.line - 1]
|
|
11380
|
+
width = getTextWidth(sourceCode.lines[cell.content.loc.end.line - 1], 0, cell.content.loc.end.column - 1);
|
|
11294
11381
|
}
|
|
11295
11382
|
if (needSpaceBeforePipe) width += 1;
|
|
11296
11383
|
maxWidth = Math.max(maxWidth, width);
|
|
@@ -11298,6 +11385,26 @@ var table_pipe_alignment_default = createRule("table-pipe-alignment", {
|
|
|
11298
11385
|
return maxWidth;
|
|
11299
11386
|
}
|
|
11300
11387
|
/**
|
|
11388
|
+
* Check if there is at least one space between leading pipe and content
|
|
11389
|
+
*/
|
|
11390
|
+
_hasSpaceBetweenLeadingPipeAndContentWithoutCache(pipeIndex) {
|
|
11391
|
+
const columnIndex = pipeIndex;
|
|
11392
|
+
for (const row of this.rows) {
|
|
11393
|
+
if (row.cells.length <= columnIndex) continue;
|
|
11394
|
+
const cell = row.cells[columnIndex];
|
|
11395
|
+
if (!cell.leadingPipe) continue;
|
|
11396
|
+
let content;
|
|
11397
|
+
if (cell.type === "delimiter") content = cell.delimiter;
|
|
11398
|
+
else {
|
|
11399
|
+
if (!cell.content) continue;
|
|
11400
|
+
content = cell.content;
|
|
11401
|
+
}
|
|
11402
|
+
if (cell.leadingPipe.range[1] < content.range[0]) continue;
|
|
11403
|
+
return false;
|
|
11404
|
+
}
|
|
11405
|
+
return true;
|
|
11406
|
+
}
|
|
11407
|
+
/**
|
|
11301
11408
|
* Check if there is at least one space between content and trailing pipe
|
|
11302
11409
|
*/
|
|
11303
11410
|
_hasSpaceBetweenContentAndTrailingPipeWithoutCache(pipeIndex) {
|
|
@@ -11350,7 +11457,7 @@ var table_pipe_alignment_default = createRule("table-pipe-alignment", {
|
|
|
11350
11457
|
function verifyPipe(pipe, pipeIndex, table, cell) {
|
|
11351
11458
|
const expected = table.getExpectedPipePosition(pipeIndex);
|
|
11352
11459
|
if (expected == null) return true;
|
|
11353
|
-
const actual = getTextWidth(sourceCode.lines[pipe.loc.start.line - 1]
|
|
11460
|
+
const actual = getTextWidth(sourceCode.lines[pipe.loc.start.line - 1], 0, pipe.loc.start.column - 1);
|
|
11354
11461
|
const diff = expected - actual;
|
|
11355
11462
|
if (diff === 0) return true;
|
|
11356
11463
|
context.report({
|
|
@@ -11373,12 +11480,19 @@ var table_pipe_alignment_default = createRule("table-pipe-alignment", {
|
|
|
11373
11480
|
const widthBeforeDelimiter = getTextWidth(beforeDelimiter);
|
|
11374
11481
|
const newLength = expected - widthBeforeDelimiter;
|
|
11375
11482
|
const minimumDelimiterLength = getMinimumDelimiterLength(cell.align);
|
|
11376
|
-
const spaceAfter = table.
|
|
11377
|
-
if (newLength < minimumDelimiterLength + spaceAfter.length)
|
|
11483
|
+
const spaceAfter = table.isNeedSpaceBetweenContentAndTrailingPipe(pipeIndex) ? " " : "";
|
|
11484
|
+
if (newLength < minimumDelimiterLength + spaceAfter.length) {
|
|
11485
|
+
const edit = fixRemoveSpacesFromLeadingSpaces(Math.abs(newLength - minimumDelimiterLength) + spaceAfter.length);
|
|
11486
|
+
if (!edit) return null;
|
|
11487
|
+
const delimiterPrefix$1 = cell.align === "left" || cell.align === "center" ? ":" : "";
|
|
11488
|
+
const delimiterSuffix$1 = cell.align === "right" || cell.align === "center" ? ":" : "";
|
|
11489
|
+
const newDelimiter$1 = "-".repeat(minimumDelimiterLength - delimiterPrefix$1.length - delimiterSuffix$1.length);
|
|
11490
|
+
return [edit, fixer.replaceTextRange([cell.delimiter.range[0], pipe.range[0]], delimiterPrefix$1 + newDelimiter$1 + delimiterSuffix$1 + spaceAfter)];
|
|
11491
|
+
}
|
|
11378
11492
|
const delimiterPrefix = cell.align === "left" || cell.align === "center" ? ":" : "";
|
|
11379
|
-
const delimiterSuffix =
|
|
11380
|
-
const newDelimiter = "-".repeat(newLength - delimiterPrefix.length - delimiterSuffix.length);
|
|
11381
|
-
return fixer.replaceTextRange([cell.delimiter.range[0], pipe.range[0]], delimiterPrefix + newDelimiter + delimiterSuffix);
|
|
11493
|
+
const delimiterSuffix = cell.align === "right" || cell.align === "center" ? ":" : "";
|
|
11494
|
+
const newDelimiter = "-".repeat(newLength - delimiterPrefix.length - delimiterSuffix.length - spaceAfter.length);
|
|
11495
|
+
return fixer.replaceTextRange([cell.delimiter.range[0], pipe.range[0]], delimiterPrefix + newDelimiter + delimiterSuffix + spaceAfter);
|
|
11382
11496
|
/**
|
|
11383
11497
|
* Fixer to remove spaces before the pipe
|
|
11384
11498
|
*/
|
|
@@ -11388,18 +11502,38 @@ var table_pipe_alignment_default = createRule("table-pipe-alignment", {
|
|
|
11388
11502
|
const spacesBeforePipeLength = beforePipe.length - trimmedBeforePipe.length;
|
|
11389
11503
|
const widthBeforePipe = getTextWidth(trimmedBeforePipe);
|
|
11390
11504
|
const newSpacesLength = expected - widthBeforePipe;
|
|
11391
|
-
|
|
11505
|
+
const minTrailingSpaceWidth = table.isNeedSpaceBetweenContentAndTrailingPipe(pipeIndex) ? 1 : 0;
|
|
11506
|
+
if (newSpacesLength < minTrailingSpaceWidth) {
|
|
11507
|
+
const edit = fixRemoveSpacesFromLeadingSpaces(Math.abs(newSpacesLength) + minTrailingSpaceWidth);
|
|
11508
|
+
if (!edit) return null;
|
|
11509
|
+
return [edit, fixer.replaceTextRange([pipe.range[0] - spacesBeforePipeLength, pipe.range[0]], " ".repeat(minTrailingSpaceWidth))];
|
|
11510
|
+
}
|
|
11392
11511
|
return fixer.replaceTextRange([pipe.range[0] - spacesBeforePipeLength, pipe.range[0]], " ".repeat(newSpacesLength));
|
|
11393
11512
|
}
|
|
11513
|
+
/**
|
|
11514
|
+
* Fixer to remove spaces from the leading spaces
|
|
11515
|
+
*/
|
|
11516
|
+
function fixRemoveSpacesFromLeadingSpaces(removeSpaceLength) {
|
|
11517
|
+
if (!cell.leadingPipe || pipeIndex === 0) return null;
|
|
11518
|
+
const content = cell.type === "delimiter" ? cell.delimiter : cell.content;
|
|
11519
|
+
if (!content) return null;
|
|
11520
|
+
const newSpacesLength = getTextWidth(sourceCode.lines[cell.leadingPipe.loc.end.line - 1], cell.leadingPipe.loc.end.column - 1, content.loc.start.column - 1) - removeSpaceLength;
|
|
11521
|
+
if (newSpacesLength < (table.isNeedSpaceBetweenLeadingPipeAndContent(pipeIndex - 1) ? 1 : 0)) return null;
|
|
11522
|
+
return fixer.replaceTextRange([cell.leadingPipe.range[1], content.range[0]], " ".repeat(newSpacesLength));
|
|
11523
|
+
}
|
|
11394
11524
|
}
|
|
11395
11525
|
});
|
|
11396
11526
|
return false;
|
|
11397
11527
|
}
|
|
11398
11528
|
/**
|
|
11399
|
-
* Get the minimum delimiter length based on alignment
|
|
11529
|
+
* Get the minimum delimiter length based on alignment and options
|
|
11400
11530
|
*/
|
|
11401
11531
|
function getMinimumDelimiterLength(align) {
|
|
11402
|
-
|
|
11532
|
+
if (align === "none") return options.delimiterMinLength.defaultDelimiter;
|
|
11533
|
+
if (align === "left") return options.delimiterMinLength.leftAlignmentDelimiter;
|
|
11534
|
+
if (align === "center") return options.delimiterMinLength.centerAlignmentDelimiter;
|
|
11535
|
+
if (align === "right") return options.delimiterMinLength.rightAlignmentDelimiter;
|
|
11536
|
+
return options.delimiterMinLength.defaultDelimiter;
|
|
11403
11537
|
}
|
|
11404
11538
|
return { table(node) {
|
|
11405
11539
|
const parsed = parseTable(sourceCode, node);
|
|
@@ -11803,7 +11937,7 @@ var meta_exports = /* @__PURE__ */ __export({
|
|
|
11803
11937
|
version: () => version
|
|
11804
11938
|
});
|
|
11805
11939
|
const name = "eslint-plugin-markdown-preferences";
|
|
11806
|
-
const version = "0.
|
|
11940
|
+
const version = "0.33.0";
|
|
11807
11941
|
|
|
11808
11942
|
//#endregion
|
|
11809
11943
|
//#region src/language/extensions/micromark-custom-container.ts
|