eslint-plugin-markdown-preferences 0.31.0 → 0.32.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
@@ -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.31.0";
541
+ declare const version: "0.32.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$5(options) {
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$5(context.options[0] || {});
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$4(options) {
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$4(context.options[0]);
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$3(options) {
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$3(context.options[0]);
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$6(context.options[0]);
6820
+ const optionProvider = parseOptions$7(context.options[0]);
6821
6821
  /**
6822
6822
  * Parse the options.
6823
6823
  */
6824
- function parseOptions$6(option) {
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$2(option) {
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$2(context.options[0]);
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$6(context.options[0]);
7298
+ const optionProvider = parseOptions$7(context.options[0]);
7299
7299
  /**
7300
7300
  * Parse the options.
7301
7301
  */
7302
- function parseOptions$6(option) {
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$1(options) {
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$1(context.options[0] || {});
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: { column: { enum: ["minimum", "consistent"] } },
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,7 +11275,7 @@ var table_pipe_alignment_default = createRule("table-pipe-alignment", {
11212
11275
  },
11213
11276
  create(context) {
11214
11277
  const sourceCode = context.sourceCode;
11215
- const columnOption = (context.options[0] || {}).column || "minimum";
11278
+ const options = parseOptions(context.options[0]);
11216
11279
  class TableContext {
11217
11280
  rows;
11218
11281
  columnCount;
@@ -11260,8 +11323,8 @@ var table_pipe_alignment_default = createRule("table-pipe-alignment", {
11260
11323
  if (!firstToken) return null;
11261
11324
  return getTextWidth(sourceCode.lines[firstToken.loc.start.line - 1].slice(0, firstToken.loc.start.column - 1));
11262
11325
  }
11263
- if (columnOption === "minimum") return this.getMinimumPipePosition(pipeIndex);
11264
- else if (columnOption === "consistent") {
11326
+ if (options.columnOption === "minimum") return this.getMinimumPipePosition(pipeIndex);
11327
+ else if (options.columnOption === "consistent") {
11265
11328
  const columnIndex = pipeIndex - 1;
11266
11329
  for (const row of this.rows) {
11267
11330
  if (row.cells.length <= columnIndex) continue;
@@ -11396,10 +11459,14 @@ var table_pipe_alignment_default = createRule("table-pipe-alignment", {
11396
11459
  return false;
11397
11460
  }
11398
11461
  /**
11399
- * Get the minimum delimiter length based on alignment
11462
+ * Get the minimum delimiter length based on alignment and options
11400
11463
  */
11401
11464
  function getMinimumDelimiterLength(align) {
11402
- return align === "none" ? 1 : align === "center" ? 3 : 2;
11465
+ if (align === "none") return options.delimiterMinLength.defaultDelimiter;
11466
+ if (align === "left") return options.delimiterMinLength.leftAlignmentDelimiter;
11467
+ if (align === "center") return options.delimiterMinLength.centerAlignmentDelimiter;
11468
+ if (align === "right") return options.delimiterMinLength.rightAlignmentDelimiter;
11469
+ return options.delimiterMinLength.defaultDelimiter;
11403
11470
  }
11404
11471
  return { table(node) {
11405
11472
  const parsed = parseTable(sourceCode, node);
@@ -11803,7 +11870,7 @@ var meta_exports = /* @__PURE__ */ __export({
11803
11870
  version: () => version
11804
11871
  });
11805
11872
  const name = "eslint-plugin-markdown-preferences";
11806
- const version = "0.31.0";
11873
+ const version = "0.32.0";
11807
11874
 
11808
11875
  //#endregion
11809
11876
  //#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.31.0",
3
+ "version": "0.32.0",
4
4
  "description": "ESLint plugin that enforces our markdown preferences",
5
5
  "type": "module",
6
6
  "exports": {