eslint-plugin-markdown-preferences 0.33.0 → 0.34.1

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.33.0";
548
+ declare const version: "0.34.1";
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
@@ -408,7 +408,6 @@ let segmenter;
408
408
  */
409
409
  function getTextWidth(text, start = 0, end = text.length) {
410
410
  if (!text.includes(" ")) return stringWidth(text.slice(start, end));
411
- if (!segmenter) segmenter = new Intl.Segmenter("en");
412
411
  const prefixWidth = getTextWidthBySegment(text.slice(0, start), 0);
413
412
  return getTextWidthBySegment(text.slice(start, end), prefixWidth);
414
413
  }
@@ -828,7 +827,7 @@ function getOtherMarker(unavailableMarker) {
828
827
  /**
829
828
  * Parse rule options.
830
829
  */
831
- function parseOptions$6(options) {
830
+ function parseOptions$7(options) {
832
831
  const primary = options.primary || "-";
833
832
  const secondary = options.secondary || getOtherMarker(primary);
834
833
  if (primary === secondary) throw new Error(`\`primary\` and \`secondary\` cannot be the same (primary: "${primary}", secondary: "${secondary}").`);
@@ -896,7 +895,7 @@ var bullet_list_marker_style_default = createRule("bullet-list-marker-style", {
896
895
  },
897
896
  create(context) {
898
897
  const sourceCode = context.sourceCode;
899
- const options = parseOptions$6(context.options[0] || {});
898
+ const options = parseOptions$7(context.options[0] || {});
900
899
  let containerStack = {
901
900
  node: sourceCode.ast,
902
901
  level: 1,
@@ -1509,7 +1508,7 @@ var custom_container_marker_spacing_default = createRule("custom-container-marke
1509
1508
  /**
1510
1509
  * Parse options with defaults.
1511
1510
  */
1512
- function parseOptions$5(options) {
1511
+ function parseOptions$6(options) {
1513
1512
  const linkDefinitionPlacement = {
1514
1513
  referencedFromSingleSection: options?.linkDefinitionPlacement?.referencedFromSingleSection || "document-last",
1515
1514
  referencedFromMultipleSections: options?.linkDefinitionPlacement?.referencedFromMultipleSections || "document-last"
@@ -1583,7 +1582,7 @@ var definitions_last_default = createRule("definitions-last", {
1583
1582
  },
1584
1583
  create(context) {
1585
1584
  const sourceCode = context.sourceCode;
1586
- const options = parseOptions$5(context.options[0]);
1585
+ const options = parseOptions$6(context.options[0]);
1587
1586
  /**
1588
1587
  * Determine whether a node can be placed as the last node of the document or a section.
1589
1588
  */
@@ -5594,7 +5593,7 @@ function parseMathClosingSequenceFromText(text) {
5594
5593
  /**
5595
5594
  * Parse options.
5596
5595
  */
5597
- function parseOptions$4(options) {
5596
+ function parseOptions$5(options) {
5598
5597
  const listItems = options?.listItems;
5599
5598
  return { listItems: {
5600
5599
  first: listItems?.first ?? 1,
@@ -5647,7 +5646,7 @@ var indent_default = createRule("indent", {
5647
5646
  },
5648
5647
  create(context) {
5649
5648
  const sourceCode = context.sourceCode;
5650
- const options = parseOptions$4(context.options[0]);
5649
+ const options = parseOptions$5(context.options[0]);
5651
5650
  class AbsBlockStack {
5652
5651
  violations = [];
5653
5652
  getCurrentBlockquote() {
@@ -6817,11 +6816,11 @@ var link_bracket_newline_default = createRule("link-bracket-newline", {
6817
6816
  },
6818
6817
  create(context) {
6819
6818
  const sourceCode = context.sourceCode;
6820
- const optionProvider = parseOptions$7(context.options[0]);
6819
+ const optionProvider = parseOptions$8(context.options[0]);
6821
6820
  /**
6822
6821
  * Parse the options.
6823
6822
  */
6824
- function parseOptions$7(option) {
6823
+ function parseOptions$8(option) {
6825
6824
  const newline = option?.newline ?? "never";
6826
6825
  const multiline = option?.multiline ?? false;
6827
6826
  return (bracketsRange) => {
@@ -6952,7 +6951,7 @@ var link_bracket_newline_default = createRule("link-bracket-newline", {
6952
6951
  /**
6953
6952
  * The basic option for links and images.
6954
6953
  */
6955
- function parseOptions$3(option) {
6954
+ function parseOptions$4(option) {
6956
6955
  const space = option?.space ?? "never";
6957
6956
  const imagesInLinks = option?.imagesInLinks;
6958
6957
  return {
@@ -7002,7 +7001,7 @@ var link_bracket_spacing_default = createRule("link-bracket-spacing", {
7002
7001
  },
7003
7002
  create(context) {
7004
7003
  const sourceCode = context.sourceCode;
7005
- const options = parseOptions$3(context.options[0]);
7004
+ const options = parseOptions$4(context.options[0]);
7006
7005
  /**
7007
7006
  * Verify the space after the opening bracket and before the closing bracket.
7008
7007
  */
@@ -7295,11 +7294,11 @@ var link_paren_newline_default = createRule("link-paren-newline", {
7295
7294
  },
7296
7295
  create(context) {
7297
7296
  const sourceCode = context.sourceCode;
7298
- const optionProvider = parseOptions$7(context.options[0]);
7297
+ const optionProvider = parseOptions$8(context.options[0]);
7299
7298
  /**
7300
7299
  * Parse the options.
7301
7300
  */
7302
- function parseOptions$7(option) {
7301
+ function parseOptions$8(option) {
7303
7302
  const newline = option?.newline ?? "never";
7304
7303
  const multiline = option?.multiline ?? false;
7305
7304
  return (openingParenIndex, closingParenIndex) => {
@@ -8905,7 +8904,7 @@ function markerToKind(marker) {
8905
8904
  /**
8906
8905
  * Parse rule options.
8907
8906
  */
8908
- function parseOptions$2(options) {
8907
+ function parseOptions$3(options) {
8909
8908
  const prefer = markerToKind(options.prefer) || ".";
8910
8909
  const overrides = (options.overrides ?? []).map((override) => {
8911
8910
  const preferForOverride = markerToKind(override.prefer) || ".";
@@ -8966,7 +8965,7 @@ var ordered_list_marker_style_default = createRule("ordered-list-marker-style",
8966
8965
  },
8967
8966
  create(context) {
8968
8967
  const sourceCode = context.sourceCode;
8969
- const options = parseOptions$2(context.options[0] || {});
8968
+ const options = parseOptions$3(context.options[0] || {});
8970
8969
  let containerStack = {
8971
8970
  node: sourceCode.ast,
8972
8971
  level: 1,
@@ -9056,6 +9055,38 @@ var ordered_list_marker_style_default = createRule("ordered-list-marker-style",
9056
9055
 
9057
9056
  //#endregion
9058
9057
  //#region src/rules/padded-custom-containers.ts
9058
+ /**
9059
+ * Parse the given options.
9060
+ */
9061
+ function parseOptions$2(options) {
9062
+ const padding = options?.padding || "never";
9063
+ const overrides = (options?.overrides || []).map((override) => {
9064
+ return {
9065
+ test: normalizeTest(override.info),
9066
+ padding: override.padding || padding
9067
+ };
9068
+ }).reverse();
9069
+ /**
9070
+ * Get the padding setting for the given container.
9071
+ */
9072
+ function getPaddingForContainer(node) {
9073
+ for (const override of overrides) if (override.test(node)) return override.padding;
9074
+ return padding;
9075
+ }
9076
+ return { getPaddingForContainer };
9077
+ /**
9078
+ * Normalize the given info option.
9079
+ */
9080
+ function normalizeTest(infoOption) {
9081
+ if (infoOption == null) return () => false;
9082
+ if (Array.isArray(infoOption)) {
9083
+ const tests = infoOption.map(normalizeTest);
9084
+ return (n) => tests.some((t) => t(n));
9085
+ }
9086
+ const test = toRegExp(infoOption);
9087
+ return (n) => test.test(n.info);
9088
+ }
9089
+ }
9059
9090
  var padded_custom_containers_default = createRule("padded-custom-containers", {
9060
9091
  meta: {
9061
9092
  type: "layout",
@@ -9068,11 +9099,34 @@ var padded_custom_containers_default = createRule("padded-custom-containers", {
9068
9099
  hasSuggestions: false,
9069
9100
  schema: [{
9070
9101
  type: "object",
9071
- properties: { padding: {
9072
- type: "string",
9073
- enum: ["always", "never"],
9074
- default: "never"
9075
- } },
9102
+ properties: {
9103
+ padding: {
9104
+ type: "string",
9105
+ enum: ["always", "never"],
9106
+ default: "never"
9107
+ },
9108
+ overrides: {
9109
+ type: "array",
9110
+ items: {
9111
+ type: "object",
9112
+ properties: {
9113
+ info: { anyOf: [{ type: "string" }, {
9114
+ type: "array",
9115
+ items: { type: "string" },
9116
+ minItems: 1,
9117
+ uniqueItems: true
9118
+ }] },
9119
+ padding: {
9120
+ type: "string",
9121
+ enum: ["always", "never"]
9122
+ }
9123
+ },
9124
+ additionalProperties: false
9125
+ },
9126
+ uniqueItems: true,
9127
+ minItems: 1
9128
+ }
9129
+ },
9076
9130
  additionalProperties: false
9077
9131
  }],
9078
9132
  messages: {
@@ -9084,9 +9138,10 @@ var padded_custom_containers_default = createRule("padded-custom-containers", {
9084
9138
  },
9085
9139
  create(context) {
9086
9140
  const sourceCode = context.sourceCode;
9087
- const padding = (context.options[0] || {}).padding || "never";
9141
+ const options = parseOptions$2(context.options[0]);
9088
9142
  return { customContainer(node) {
9089
9143
  if (node.children.length === 0) return;
9144
+ const padding = options.getPaddingForContainer(node);
9090
9145
  const parsed = parseCustomContainer(sourceCode, node);
9091
9146
  if (!parsed) return;
9092
9147
  const { openingSequence, closingSequence } = parsed;
@@ -9117,30 +9172,28 @@ var padded_custom_containers_default = createRule("padded-custom-containers", {
9117
9172
  });
9118
9173
  } else if (padding === "never") {
9119
9174
  if (paddingAfterOpeningLines > 0) {
9120
- const firstChildRange = sourceCode.getRange(firstChild);
9175
+ const lines = getParsedLines(sourceCode);
9176
+ const reportLines = [];
9177
+ for (let lineNumber = openingSequence.loc.end.line + 1; lineNumber < firstChildLoc.start.line; lineNumber++) reportLines.push(lines.get(lineNumber));
9178
+ const removeRange = [reportLines[0].range[0], reportLines[reportLines.length - 1].range[1]];
9121
9179
  context.report({
9122
9180
  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
- }
9181
+ loc: getSourceLocationFromRange(sourceCode, node, removeRange),
9182
+ fix(fixer) {
9183
+ return fixer.removeRange(removeRange);
9130
9184
  }
9131
9185
  });
9132
9186
  }
9133
9187
  if (closingSequence && paddingBeforeClosingLines !== null && paddingBeforeClosingLines > 0) {
9134
- const lastChildRange = sourceCode.getRange(lastChild);
9188
+ const lines = getParsedLines(sourceCode);
9189
+ const reportLines = [];
9190
+ for (let lineNumber = lastChildLoc.end.line + 1; lineNumber < closingSequence.loc.start.line; lineNumber++) reportLines.push(lines.get(lineNumber));
9191
+ const removeRange = [reportLines[0].range[0], reportLines[reportLines.length - 1].range[1]];
9135
9192
  context.report({
9136
9193
  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
- }
9194
+ loc: getSourceLocationFromRange(sourceCode, node, removeRange),
9195
+ fix(fixer) {
9196
+ return fixer.removeRange(removeRange);
9144
9197
  }
9145
9198
  });
9146
9199
  }
@@ -11937,7 +11990,7 @@ var meta_exports = /* @__PURE__ */ __export({
11937
11990
  version: () => version
11938
11991
  });
11939
11992
  const name = "eslint-plugin-markdown-preferences";
11940
- const version = "0.33.0";
11993
+ const version = "0.34.1";
11941
11994
 
11942
11995
  //#endregion
11943
11996
  //#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.33.0",
3
+ "version": "0.34.1",
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",