eslint-plugin-markdown-preferences 0.32.0 → 0.34.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 CHANGED
@@ -412,6 +412,13 @@ type MarkdownPreferencesOrderedListMarkerStyle = [] | [{
412
412
  }];
413
413
  type MarkdownPreferencesPaddedCustomContainers = [] | [{
414
414
  padding?: ("always" | "never");
415
+ overrides?: [{
416
+ info?: (string | [string, ...(string)[]]);
417
+ padding?: ("always" | "never");
418
+ }, ...({
419
+ info?: (string | [string, ...(string)[]]);
420
+ padding?: ("always" | "never");
421
+ })[]];
415
422
  }];
416
423
  type MarkdownPreferencesPaddingLineBetweenBlocks = {
417
424
  prev: (("blockquote" | "code" | "heading" | "html" | "list" | "paragraph" | "thematic-break" | "table" | "link-definition" | "footnote-definition" | "frontmatter" | "custom-container" | "math" | "import-code-snippet" | "*") | [("blockquote" | "code" | "heading" | "html" | "list" | "paragraph" | "thematic-break" | "table" | "link-definition" | "footnote-definition" | "frontmatter" | "custom-container" | "math" | "import-code-snippet" | "*"), ...(("blockquote" | "code" | "heading" | "html" | "list" | "paragraph" | "thematic-break" | "table" | "link-definition" | "footnote-definition" | "frontmatter" | "custom-container" | "math" | "import-code-snippet" | "*"))[]] | {
@@ -538,7 +545,7 @@ declare namespace meta_d_exports {
538
545
  export { name, version };
539
546
  }
540
547
  declare const name: "eslint-plugin-markdown-preferences";
541
- declare const version: "0.32.0";
548
+ declare const version: "0.34.0";
542
549
  //#endregion
543
550
  //#region src/language/ast-types.d.ts
544
551
  type Node = mdast.Node;
@@ -580,7 +587,7 @@ interface CustomContainer extends ExtendChildren<mdast.Parent, CustomContainer |
580
587
  /**
581
588
  * Info string (e.g., "warning" in ::: warning ... :::).
582
589
  */
583
- info: string | null;
590
+ info: string;
584
591
  /**
585
592
  * Children of custom container.
586
593
  */
package/lib/index.js CHANGED
@@ -828,7 +828,7 @@ function getOtherMarker(unavailableMarker) {
828
828
  /**
829
829
  * Parse rule options.
830
830
  */
831
- function parseOptions$6(options) {
831
+ function parseOptions$7(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$6(context.options[0] || {});
899
+ const options = parseOptions$7(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$5(options) {
1512
+ function parseOptions$6(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$5(context.options[0]);
1586
+ const options = parseOptions$6(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$4(options) {
5597
+ function parseOptions$5(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$4(context.options[0]);
5650
+ const options = parseOptions$5(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$7(context.options[0]);
6820
+ const optionProvider = parseOptions$8(context.options[0]);
6821
6821
  /**
6822
6822
  * Parse the options.
6823
6823
  */
6824
- function parseOptions$7(option) {
6824
+ function parseOptions$8(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$3(option) {
6955
+ function parseOptions$4(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$3(context.options[0]);
7005
+ const options = parseOptions$4(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$7(context.options[0]);
7298
+ const optionProvider = parseOptions$8(context.options[0]);
7299
7299
  /**
7300
7300
  * Parse the options.
7301
7301
  */
7302
- function parseOptions$7(option) {
7302
+ function parseOptions$8(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$2(options) {
8908
+ function parseOptions$3(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$2(context.options[0] || {});
8969
+ const options = parseOptions$3(context.options[0] || {});
8970
8970
  let containerStack = {
8971
8971
  node: sourceCode.ast,
8972
8972
  level: 1,
@@ -9056,6 +9056,38 @@ var ordered_list_marker_style_default = createRule("ordered-list-marker-style",
9056
9056
 
9057
9057
  //#endregion
9058
9058
  //#region src/rules/padded-custom-containers.ts
9059
+ /**
9060
+ * Parse the given options.
9061
+ */
9062
+ function parseOptions$2(options) {
9063
+ const padding = options?.padding || "never";
9064
+ const overrides = (options?.overrides || []).map((override) => {
9065
+ return {
9066
+ test: normalizeTest(override.info),
9067
+ padding: override.padding || padding
9068
+ };
9069
+ }).reverse();
9070
+ /**
9071
+ * Get the padding setting for the given container.
9072
+ */
9073
+ function getPaddingForContainer(node) {
9074
+ for (const override of overrides) if (override.test(node)) return override.padding;
9075
+ return padding;
9076
+ }
9077
+ return { getPaddingForContainer };
9078
+ /**
9079
+ * Normalize the given info option.
9080
+ */
9081
+ function normalizeTest(infoOption) {
9082
+ if (infoOption == null) return () => false;
9083
+ if (Array.isArray(infoOption)) {
9084
+ const tests = infoOption.map(normalizeTest);
9085
+ return (n) => tests.some((t) => t(n));
9086
+ }
9087
+ const test = toRegExp(infoOption);
9088
+ return (n) => test.test(n.info);
9089
+ }
9090
+ }
9059
9091
  var padded_custom_containers_default = createRule("padded-custom-containers", {
9060
9092
  meta: {
9061
9093
  type: "layout",
@@ -9068,11 +9100,34 @@ var padded_custom_containers_default = createRule("padded-custom-containers", {
9068
9100
  hasSuggestions: false,
9069
9101
  schema: [{
9070
9102
  type: "object",
9071
- properties: { padding: {
9072
- type: "string",
9073
- enum: ["always", "never"],
9074
- default: "never"
9075
- } },
9103
+ properties: {
9104
+ padding: {
9105
+ type: "string",
9106
+ enum: ["always", "never"],
9107
+ default: "never"
9108
+ },
9109
+ overrides: {
9110
+ type: "array",
9111
+ items: {
9112
+ type: "object",
9113
+ properties: {
9114
+ info: { anyOf: [{ type: "string" }, {
9115
+ type: "array",
9116
+ items: { type: "string" },
9117
+ minItems: 1,
9118
+ uniqueItems: true
9119
+ }] },
9120
+ padding: {
9121
+ type: "string",
9122
+ enum: ["always", "never"]
9123
+ }
9124
+ },
9125
+ additionalProperties: false
9126
+ },
9127
+ uniqueItems: true,
9128
+ minItems: 1
9129
+ }
9130
+ },
9076
9131
  additionalProperties: false
9077
9132
  }],
9078
9133
  messages: {
@@ -9084,9 +9139,10 @@ var padded_custom_containers_default = createRule("padded-custom-containers", {
9084
9139
  },
9085
9140
  create(context) {
9086
9141
  const sourceCode = context.sourceCode;
9087
- const padding = (context.options[0] || {}).padding || "never";
9142
+ const options = parseOptions$2(context.options[0]);
9088
9143
  return { customContainer(node) {
9089
9144
  if (node.children.length === 0) return;
9145
+ const padding = options.getPaddingForContainer(node);
9090
9146
  const parsed = parseCustomContainer(sourceCode, node);
9091
9147
  if (!parsed) return;
9092
9148
  const { openingSequence, closingSequence } = parsed;
@@ -9117,30 +9173,28 @@ var padded_custom_containers_default = createRule("padded-custom-containers", {
9117
9173
  });
9118
9174
  } else if (padding === "never") {
9119
9175
  if (paddingAfterOpeningLines > 0) {
9120
- const firstChildRange = sourceCode.getRange(firstChild);
9176
+ const lines = getParsedLines(sourceCode);
9177
+ const reportLines = [];
9178
+ for (let lineNumber = openingSequence.loc.end.line + 1; lineNumber < firstChildLoc.start.line; lineNumber++) reportLines.push(lines.get(lineNumber));
9179
+ const removeRange = [reportLines[0].range[0], reportLines[reportLines.length - 1].range[1]];
9121
9180
  context.report({
9122
9181
  messageId: "unexpectedPaddingAfterOpeningMarker",
9123
- loc: getSourceLocationFromRange(sourceCode, node, [openingSequence.range[1], firstChildRange[0]]),
9124
- *fix(fixer) {
9125
- const lines = getParsedLines(sourceCode);
9126
- for (let lineNumber = openingSequence.loc.end.line + 1; lineNumber < firstChildLoc.start.line; lineNumber++) {
9127
- const line = lines.get(lineNumber);
9128
- yield fixer.removeRange(line.range);
9129
- }
9182
+ loc: getSourceLocationFromRange(sourceCode, node, removeRange),
9183
+ fix(fixer) {
9184
+ return fixer.removeRange(removeRange);
9130
9185
  }
9131
9186
  });
9132
9187
  }
9133
9188
  if (closingSequence && paddingBeforeClosingLines !== null && paddingBeforeClosingLines > 0) {
9134
- const lastChildRange = sourceCode.getRange(lastChild);
9189
+ const lines = getParsedLines(sourceCode);
9190
+ const reportLines = [];
9191
+ for (let lineNumber = lastChildLoc.end.line + 1; lineNumber < closingSequence.loc.start.line; lineNumber++) reportLines.push(lines.get(lineNumber));
9192
+ const removeRange = [reportLines[0].range[0], reportLines[reportLines.length - 1].range[1]];
9135
9193
  context.report({
9136
9194
  messageId: "unexpectedPaddingBeforeClosingMarker",
9137
- loc: getSourceLocationFromRange(sourceCode, node, [lastChildRange[1], closingSequence.range[0]]),
9138
- *fix(fixer) {
9139
- const lines = getParsedLines(sourceCode);
9140
- for (let lineNumber = lastChildLoc.end.line + 1; lineNumber < closingSequence.loc.start.line; lineNumber++) {
9141
- const line = lines.get(lineNumber);
9142
- yield fixer.removeRange(line.range);
9143
- }
9195
+ loc: getSourceLocationFromRange(sourceCode, node, removeRange),
9196
+ fix(fixer) {
9197
+ return fixer.removeRange(removeRange);
9144
9198
  }
9145
9199
  });
9146
9200
  }
@@ -11278,11 +11332,14 @@ var table_pipe_alignment_default = createRule("table-pipe-alignment", {
11278
11332
  const options = parseOptions(context.options[0]);
11279
11333
  class TableContext {
11280
11334
  rows;
11335
+ delimiterRow;
11281
11336
  columnCount;
11282
- _cacheHasSpaceBetweenContentAndTrailingPipe = /* @__PURE__ */ new Map();
11337
+ _cacheNeedSpaceBetweenLeadingPipeAndContent = /* @__PURE__ */ new Map();
11338
+ _cacheNeedSpaceBetweenContentAndTrailingPipe = /* @__PURE__ */ new Map();
11283
11339
  _cacheExpectedPipePosition = /* @__PURE__ */ new Map();
11284
11340
  constructor(parsed) {
11285
- const rows = [parsedTableRowToRowData(parsed.headerRow), parsedTableDelimiterRowToRowData(parsed.delimiterRow)];
11341
+ this.delimiterRow = parsedTableDelimiterRowToRowData(parsed.delimiterRow);
11342
+ const rows = [parsedTableRowToRowData(parsed.headerRow), this.delimiterRow];
11286
11343
  for (const bodyRow of parsed.bodyRows) rows.push(parsedTableRowToRowData(bodyRow));
11287
11344
  this.rows = rows;
11288
11345
  let columnCount = 0;
@@ -11300,17 +11357,29 @@ var table_pipe_alignment_default = createRule("table-pipe-alignment", {
11300
11357
  return v;
11301
11358
  }
11302
11359
  /**
11360
+ * Check if there is at least one space between leading pipe and content
11361
+ */
11362
+ isNeedSpaceBetweenLeadingPipeAndContent(pipeIndex) {
11363
+ let v = this._cacheNeedSpaceBetweenLeadingPipeAndContent.get(pipeIndex);
11364
+ if (v != null) return v;
11365
+ if (getCurrentTablePipeSpacingOption(sourceCode)?.leadingSpace === "always") v = true;
11366
+ else v = this._hasSpaceBetweenLeadingPipeAndContentWithoutCache(pipeIndex);
11367
+ this._cacheNeedSpaceBetweenLeadingPipeAndContent.set(pipeIndex, v);
11368
+ return v;
11369
+ }
11370
+ /**
11303
11371
  * Check if there is at least one space between content and trailing pipe
11304
11372
  * for the index
11305
11373
  *
11306
11374
  * This is used to determine if the pipe should be aligned with a space before it.
11307
11375
  */
11308
- hasSpaceBetweenContentAndTrailingPipe(pipeIndex) {
11376
+ isNeedSpaceBetweenContentAndTrailingPipe(pipeIndex) {
11309
11377
  if (pipeIndex === 0) return false;
11310
- let v = this._cacheHasSpaceBetweenContentAndTrailingPipe.get(pipeIndex);
11378
+ let v = this._cacheNeedSpaceBetweenContentAndTrailingPipe.get(pipeIndex);
11311
11379
  if (v != null) return v;
11312
- v = this._hasSpaceBetweenContentAndTrailingPipeWithoutCache(pipeIndex);
11313
- this._cacheHasSpaceBetweenContentAndTrailingPipe.set(pipeIndex, v);
11380
+ if (getCurrentTablePipeSpacingOption(sourceCode)?.trailingSpace === "always") v = true;
11381
+ else v = this._hasSpaceBetweenContentAndTrailingPipeWithoutCache(pipeIndex);
11382
+ this._cacheNeedSpaceBetweenContentAndTrailingPipe.set(pipeIndex, v);
11314
11383
  return v;
11315
11384
  }
11316
11385
  /**
@@ -11321,7 +11390,7 @@ var table_pipe_alignment_default = createRule("table-pipe-alignment", {
11321
11390
  const firstCell = this.rows[0].cells[0];
11322
11391
  const firstToken = firstCell.leadingPipe ?? firstCell.content;
11323
11392
  if (!firstToken) return null;
11324
- return getTextWidth(sourceCode.lines[firstToken.loc.start.line - 1].slice(0, firstToken.loc.start.column - 1));
11393
+ return getTextWidth(sourceCode.lines[firstToken.loc.start.line - 1], 0, firstToken.loc.start.column - 1);
11325
11394
  }
11326
11395
  if (options.columnOption === "minimum") return this.getMinimumPipePosition(pipeIndex);
11327
11396
  else if (options.columnOption === "consistent") {
@@ -11330,7 +11399,7 @@ var table_pipe_alignment_default = createRule("table-pipe-alignment", {
11330
11399
  if (row.cells.length <= columnIndex) continue;
11331
11400
  const cell = row.cells[columnIndex];
11332
11401
  if (cell.type === "delimiter" || !cell.trailingPipe) continue;
11333
- const width = getTextWidth(sourceCode.lines[cell.trailingPipe.loc.start.line - 1].slice(0, cell.trailingPipe.loc.start.column - 1));
11402
+ const width = getTextWidth(sourceCode.lines[cell.trailingPipe.loc.start.line - 1], 0, cell.trailingPipe.loc.start.column - 1);
11334
11403
  return Math.max(width, this.getMinimumPipePosition(pipeIndex) || 0);
11335
11404
  }
11336
11405
  }
@@ -11340,20 +11409,29 @@ var table_pipe_alignment_default = createRule("table-pipe-alignment", {
11340
11409
  * Get the minimum pipe position for the index
11341
11410
  */
11342
11411
  getMinimumPipePosition(pipeIndex) {
11343
- const spacingRuleOptions = getCurrentTablePipeSpacingOption(sourceCode);
11344
- const needSpaceBeforePipe = spacingRuleOptions ? spacingRuleOptions.trailingSpace === "always" : this.hasSpaceBetweenContentAndTrailingPipe(pipeIndex);
11412
+ const needSpaceAfterPipe = this.isNeedSpaceBetweenLeadingPipeAndContent(pipeIndex - 1);
11413
+ const needSpaceBeforePipe = this.isNeedSpaceBetweenContentAndTrailingPipe(pipeIndex);
11345
11414
  let maxWidth = 0;
11346
11415
  const columnIndex = pipeIndex - 1;
11347
11416
  for (const row of this.rows) {
11348
11417
  if (row.cells.length <= columnIndex) continue;
11349
11418
  const cell = row.cells[columnIndex];
11350
11419
  let width;
11351
- if (cell.type === "delimiter") {
11420
+ if (cell.leadingPipe) {
11421
+ const leadingPipeEndOffset = getTextWidth(sourceCode.lines[cell.leadingPipe.loc.end.line - 1], 0, cell.leadingPipe.loc.end.column - 1);
11422
+ let contentLength;
11423
+ if (cell.type === "delimiter") contentLength = getMinimumDelimiterLength(cell.align);
11424
+ else {
11425
+ if (!cell.content) continue;
11426
+ contentLength = getTextWidth(sourceCode.lines[cell.content.loc.start.line - 1], cell.content.loc.start.column - 1, cell.content.loc.end.column - 1);
11427
+ }
11428
+ width = leadingPipeEndOffset + (needSpaceAfterPipe ? 1 : 0) + contentLength;
11429
+ } else if (cell.type === "delimiter") {
11352
11430
  const minimumDelimiterLength = getMinimumDelimiterLength(cell.align);
11353
- width = getTextWidth(sourceCode.lines[cell.delimiter.loc.start.line - 1].slice(0, cell.delimiter.loc.start.column - 1)) + minimumDelimiterLength;
11431
+ width = getTextWidth(sourceCode.lines[cell.delimiter.loc.start.line - 1], 0, cell.delimiter.loc.start.column - 1) + minimumDelimiterLength;
11354
11432
  } else {
11355
11433
  if (!cell.content) continue;
11356
- width = getTextWidth(sourceCode.lines[cell.content.loc.end.line - 1].slice(0, cell.content.loc.end.column - 1));
11434
+ width = getTextWidth(sourceCode.lines[cell.content.loc.end.line - 1], 0, cell.content.loc.end.column - 1);
11357
11435
  }
11358
11436
  if (needSpaceBeforePipe) width += 1;
11359
11437
  maxWidth = Math.max(maxWidth, width);
@@ -11361,6 +11439,26 @@ var table_pipe_alignment_default = createRule("table-pipe-alignment", {
11361
11439
  return maxWidth;
11362
11440
  }
11363
11441
  /**
11442
+ * Check if there is at least one space between leading pipe and content
11443
+ */
11444
+ _hasSpaceBetweenLeadingPipeAndContentWithoutCache(pipeIndex) {
11445
+ const columnIndex = pipeIndex;
11446
+ for (const row of this.rows) {
11447
+ if (row.cells.length <= columnIndex) continue;
11448
+ const cell = row.cells[columnIndex];
11449
+ if (!cell.leadingPipe) continue;
11450
+ let content;
11451
+ if (cell.type === "delimiter") content = cell.delimiter;
11452
+ else {
11453
+ if (!cell.content) continue;
11454
+ content = cell.content;
11455
+ }
11456
+ if (cell.leadingPipe.range[1] < content.range[0]) continue;
11457
+ return false;
11458
+ }
11459
+ return true;
11460
+ }
11461
+ /**
11364
11462
  * Check if there is at least one space between content and trailing pipe
11365
11463
  */
11366
11464
  _hasSpaceBetweenContentAndTrailingPipeWithoutCache(pipeIndex) {
@@ -11413,7 +11511,7 @@ var table_pipe_alignment_default = createRule("table-pipe-alignment", {
11413
11511
  function verifyPipe(pipe, pipeIndex, table, cell) {
11414
11512
  const expected = table.getExpectedPipePosition(pipeIndex);
11415
11513
  if (expected == null) return true;
11416
- const actual = getTextWidth(sourceCode.lines[pipe.loc.start.line - 1].slice(0, pipe.loc.start.column - 1));
11514
+ const actual = getTextWidth(sourceCode.lines[pipe.loc.start.line - 1], 0, pipe.loc.start.column - 1);
11417
11515
  const diff = expected - actual;
11418
11516
  if (diff === 0) return true;
11419
11517
  context.report({
@@ -11436,12 +11534,19 @@ var table_pipe_alignment_default = createRule("table-pipe-alignment", {
11436
11534
  const widthBeforeDelimiter = getTextWidth(beforeDelimiter);
11437
11535
  const newLength = expected - widthBeforeDelimiter;
11438
11536
  const minimumDelimiterLength = getMinimumDelimiterLength(cell.align);
11439
- const spaceAfter = table.hasSpaceBetweenContentAndTrailingPipe(pipeIndex) ? " " : "";
11440
- if (newLength < minimumDelimiterLength + spaceAfter.length) return null;
11537
+ const spaceAfter = table.isNeedSpaceBetweenContentAndTrailingPipe(pipeIndex) ? " " : "";
11538
+ if (newLength < minimumDelimiterLength + spaceAfter.length) {
11539
+ const edit = fixRemoveSpacesFromLeadingSpaces(Math.abs(newLength - minimumDelimiterLength) + spaceAfter.length);
11540
+ if (!edit) return null;
11541
+ const delimiterPrefix$1 = cell.align === "left" || cell.align === "center" ? ":" : "";
11542
+ const delimiterSuffix$1 = cell.align === "right" || cell.align === "center" ? ":" : "";
11543
+ const newDelimiter$1 = "-".repeat(minimumDelimiterLength - delimiterPrefix$1.length - delimiterSuffix$1.length);
11544
+ return [edit, fixer.replaceTextRange([cell.delimiter.range[0], pipe.range[0]], delimiterPrefix$1 + newDelimiter$1 + delimiterSuffix$1 + spaceAfter)];
11545
+ }
11441
11546
  const delimiterPrefix = cell.align === "left" || cell.align === "center" ? ":" : "";
11442
- const delimiterSuffix = (cell.align === "right" || cell.align === "center" ? ":" : "") + spaceAfter;
11443
- const newDelimiter = "-".repeat(newLength - delimiterPrefix.length - delimiterSuffix.length);
11444
- return fixer.replaceTextRange([cell.delimiter.range[0], pipe.range[0]], delimiterPrefix + newDelimiter + delimiterSuffix);
11547
+ const delimiterSuffix = cell.align === "right" || cell.align === "center" ? ":" : "";
11548
+ const newDelimiter = "-".repeat(newLength - delimiterPrefix.length - delimiterSuffix.length - spaceAfter.length);
11549
+ return fixer.replaceTextRange([cell.delimiter.range[0], pipe.range[0]], delimiterPrefix + newDelimiter + delimiterSuffix + spaceAfter);
11445
11550
  /**
11446
11551
  * Fixer to remove spaces before the pipe
11447
11552
  */
@@ -11451,9 +11556,25 @@ var table_pipe_alignment_default = createRule("table-pipe-alignment", {
11451
11556
  const spacesBeforePipeLength = beforePipe.length - trimmedBeforePipe.length;
11452
11557
  const widthBeforePipe = getTextWidth(trimmedBeforePipe);
11453
11558
  const newSpacesLength = expected - widthBeforePipe;
11454
- if (newSpacesLength < (table.hasSpaceBetweenContentAndTrailingPipe(pipeIndex) ? 1 : 0)) return null;
11559
+ const minTrailingSpaceWidth = table.isNeedSpaceBetweenContentAndTrailingPipe(pipeIndex) ? 1 : 0;
11560
+ if (newSpacesLength < minTrailingSpaceWidth) {
11561
+ const edit = fixRemoveSpacesFromLeadingSpaces(Math.abs(newSpacesLength) + minTrailingSpaceWidth);
11562
+ if (!edit) return null;
11563
+ return [edit, fixer.replaceTextRange([pipe.range[0] - spacesBeforePipeLength, pipe.range[0]], " ".repeat(minTrailingSpaceWidth))];
11564
+ }
11455
11565
  return fixer.replaceTextRange([pipe.range[0] - spacesBeforePipeLength, pipe.range[0]], " ".repeat(newSpacesLength));
11456
11566
  }
11567
+ /**
11568
+ * Fixer to remove spaces from the leading spaces
11569
+ */
11570
+ function fixRemoveSpacesFromLeadingSpaces(removeSpaceLength) {
11571
+ if (!cell.leadingPipe || pipeIndex === 0) return null;
11572
+ const content = cell.type === "delimiter" ? cell.delimiter : cell.content;
11573
+ if (!content) return null;
11574
+ const newSpacesLength = getTextWidth(sourceCode.lines[cell.leadingPipe.loc.end.line - 1], cell.leadingPipe.loc.end.column - 1, content.loc.start.column - 1) - removeSpaceLength;
11575
+ if (newSpacesLength < (table.isNeedSpaceBetweenLeadingPipeAndContent(pipeIndex - 1) ? 1 : 0)) return null;
11576
+ return fixer.replaceTextRange([cell.leadingPipe.range[1], content.range[0]], " ".repeat(newSpacesLength));
11577
+ }
11457
11578
  }
11458
11579
  });
11459
11580
  return false;
@@ -11870,7 +11991,7 @@ var meta_exports = /* @__PURE__ */ __export({
11870
11991
  version: () => version
11871
11992
  });
11872
11993
  const name = "eslint-plugin-markdown-preferences";
11873
- const version = "0.32.0";
11994
+ const version = "0.34.0";
11874
11995
 
11875
11996
  //#endregion
11876
11997
  //#region src/language/extensions/micromark-custom-container.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-markdown-preferences",
3
- "version": "0.32.0",
3
+ "version": "0.34.0",
4
4
  "description": "ESLint plugin that enforces our markdown preferences",
5
5
  "type": "module",
6
6
  "exports": {
@@ -79,7 +79,7 @@
79
79
  "@changesets/changelog-github": "^0.5.1",
80
80
  "@changesets/cli": "^2.28.1",
81
81
  "@changesets/get-release-plan": "^4.0.8",
82
- "@eslint/core": "^0.15.0",
82
+ "@eslint/core": "^0.16.0",
83
83
  "@eslint/markdown": "^7.2.0",
84
84
  "@ota-meshi/eslint-plugin": "^0.18.0",
85
85
  "@shikijs/vitepress-twoslash": "^3.0.0",