eslint-plugin-markdown-preferences 0.36.3 → 0.37.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/README.md CHANGED
@@ -203,6 +203,7 @@ The rules with the following 💄 are included in the `standard` config.
203
203
  | [markdown-preferences/list-marker-alignment](https://ota-meshi.github.io/eslint-plugin-markdown-preferences/rules/list-marker-alignment.html) | enforce consistent alignment of list markers | 🔧 | ⭐💄 |
204
204
  | [markdown-preferences/no-multi-spaces](https://ota-meshi.github.io/eslint-plugin-markdown-preferences/rules/no-multi-spaces.html) | disallow multiple spaces | 🔧 | 💄 |
205
205
  | [markdown-preferences/no-multiple-empty-lines](https://ota-meshi.github.io/eslint-plugin-markdown-preferences/rules/no-multiple-empty-lines.html) | disallow multiple empty lines in Markdown files. | 🔧 | 💄 |
206
+ | [markdown-preferences/no-tabs](https://ota-meshi.github.io/eslint-plugin-markdown-preferences/rules/no-tabs.html) | Disallow tab characters in Markdown files. | 🔧 | 💄 |
206
207
  | [markdown-preferences/no-trailing-spaces](https://ota-meshi.github.io/eslint-plugin-markdown-preferences/rules/no-trailing-spaces.html) | disallow trailing whitespace at the end of lines in Markdown files. | 🔧 | 💄 |
207
208
  | [markdown-preferences/padded-custom-containers](https://ota-meshi.github.io/eslint-plugin-markdown-preferences/rules/padded-custom-containers.html) | disallow or require padding inside custom containers | 🔧 | 💄 |
208
209
  | [markdown-preferences/padding-line-between-blocks](https://ota-meshi.github.io/eslint-plugin-markdown-preferences/rules/padding-line-between-blocks.html) | require or disallow padding lines between blocks | 🔧 | 💄 |
@@ -0,0 +1,18 @@
1
+ //#region rolldown:runtime
2
+ var __defProp = Object.defineProperty;
3
+ var __export = (all, symbols) => {
4
+ let target = {};
5
+ for (var name in all) {
6
+ __defProp(target, name, {
7
+ get: all[name],
8
+ enumerable: true
9
+ });
10
+ }
11
+ if (symbols) {
12
+ __defProp(target, Symbol.toStringTag, { value: "Module" });
13
+ }
14
+ return target;
15
+ };
16
+
17
+ //#endregion
18
+ export { __export as t };
package/lib/index.d.ts CHANGED
@@ -160,6 +160,11 @@ interface RuleOptions {
160
160
  * @see https://ota-meshi.github.io/eslint-plugin-markdown-preferences/rules/no-multiple-empty-lines.html
161
161
  */
162
162
  'markdown-preferences/no-multiple-empty-lines'?: Linter.RuleEntry<MarkdownPreferencesNoMultipleEmptyLines>;
163
+ /**
164
+ * Disallow tab characters in Markdown files.
165
+ * @see https://ota-meshi.github.io/eslint-plugin-markdown-preferences/rules/no-tabs.html
166
+ */
167
+ 'markdown-preferences/no-tabs'?: Linter.RuleEntry<MarkdownPreferencesNoTabs>;
163
168
  /**
164
169
  * disallow text backslash at the end of a line.
165
170
  * @see https://ota-meshi.github.io/eslint-plugin-markdown-preferences/rules/no-text-backslash-linebreak.html
@@ -398,6 +403,11 @@ type MarkdownPreferencesNoMultipleEmptyLines = [] | [{
398
403
  maxEOF?: number;
399
404
  maxBOF?: number;
400
405
  }];
406
+ type MarkdownPreferencesNoTabs = [] | [{
407
+ checkTarget?: ("all" | "indentation" | "non-indentation");
408
+ ignoreCodeBlocks?: string[];
409
+ codeBlockTabWidth?: number;
410
+ }];
401
411
  type MarkdownPreferencesNoTrailingSpaces = [] | [{
402
412
  skipBlankLines?: boolean;
403
413
  ignoreComments?: boolean;
@@ -543,7 +553,7 @@ declare namespace meta_d_exports {
543
553
  export { name, version };
544
554
  }
545
555
  declare const name: "eslint-plugin-markdown-preferences";
546
- declare const version: "0.36.3";
556
+ declare const version: "0.37.0";
547
557
  //#endregion
548
558
  //#region src/language/ast-types.d.ts
549
559
  type Node = mdast.Node;
package/lib/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { t as __export } from "./chunk-Bp6m_JJh.js";
1
+ import { t as __export } from "./chunk-BAz01cYq.js";
2
2
  import stringWidth from "string-width";
3
3
  import emojiRegex from "emoji-regex-xs";
4
4
  import path from "node:path";
@@ -732,7 +732,7 @@ function getOtherMarker(unavailableMarker) {
732
732
  /**
733
733
  * Parse rule options.
734
734
  */
735
- function parseOptions$7(options) {
735
+ function parseOptions$8(options) {
736
736
  const primary = options.primary || "-";
737
737
  const secondary = options.secondary || getOtherMarker(primary);
738
738
  if (primary === secondary) throw new Error(`\`primary\` and \`secondary\` cannot be the same (primary: "${primary}", secondary: "${secondary}").`);
@@ -800,7 +800,7 @@ var bullet_list_marker_style_default = createRule("bullet-list-marker-style", {
800
800
  },
801
801
  create(context) {
802
802
  const sourceCode = context.sourceCode;
803
- const options = parseOptions$7(context.options[0] || {});
803
+ const options = parseOptions$8(context.options[0] || {});
804
804
  let containerStack = {
805
805
  node: sourceCode.ast,
806
806
  level: 1,
@@ -1418,7 +1418,7 @@ var custom_container_marker_spacing_default = createRule("custom-container-marke
1418
1418
  /**
1419
1419
  * Parse options with defaults.
1420
1420
  */
1421
- function parseOptions$6(options) {
1421
+ function parseOptions$7(options) {
1422
1422
  return {
1423
1423
  linkDefinitionPlacement: {
1424
1424
  referencedFromSingleSection: options?.linkDefinitionPlacement?.referencedFromSingleSection || "document-last",
@@ -1490,7 +1490,7 @@ var definitions_last_default = createRule("definitions-last", {
1490
1490
  },
1491
1491
  create(context) {
1492
1492
  const sourceCode = context.sourceCode;
1493
- const options = parseOptions$6(context.options[0]);
1493
+ const options = parseOptions$7(context.options[0]);
1494
1494
  /**
1495
1495
  * Determine whether a node can be placed as the last node of the document or a section.
1496
1496
  */
@@ -5464,7 +5464,7 @@ function parseMathClosingSequenceFromText(text) {
5464
5464
  /**
5465
5465
  * Parse options.
5466
5466
  */
5467
- function parseOptions$5(options) {
5467
+ function parseOptions$6(options) {
5468
5468
  const listItems = options?.listItems;
5469
5469
  return { listItems: {
5470
5470
  first: listItems?.first ?? 1,
@@ -5517,7 +5517,7 @@ var indent_default = createRule("indent", {
5517
5517
  },
5518
5518
  create(context) {
5519
5519
  const sourceCode = context.sourceCode;
5520
- const options = parseOptions$5(context.options[0]);
5520
+ const options = parseOptions$6(context.options[0]);
5521
5521
  class AbsBlockStack {
5522
5522
  violations = [];
5523
5523
  getCurrentBlockquote() {
@@ -6723,11 +6723,11 @@ var link_bracket_newline_default = createRule("link-bracket-newline", {
6723
6723
  },
6724
6724
  create(context) {
6725
6725
  const sourceCode = context.sourceCode;
6726
- const optionProvider = parseOptions$8(context.options[0]);
6726
+ const optionProvider = parseOptions$9(context.options[0]);
6727
6727
  /**
6728
6728
  * Parse the options.
6729
6729
  */
6730
- function parseOptions$8(option) {
6730
+ function parseOptions$9(option) {
6731
6731
  const newline = option?.newline ?? "never";
6732
6732
  const multiline = option?.multiline ?? false;
6733
6733
  return (bracketsRange) => {
@@ -6869,7 +6869,7 @@ var link_bracket_newline_default = createRule("link-bracket-newline", {
6869
6869
  /**
6870
6870
  * The basic option for links and images.
6871
6871
  */
6872
- function parseOptions$4(option) {
6872
+ function parseOptions$5(option) {
6873
6873
  const space = option?.space ?? "never";
6874
6874
  const imagesInLinks = option?.imagesInLinks;
6875
6875
  return {
@@ -6919,7 +6919,7 @@ var link_bracket_spacing_default = createRule("link-bracket-spacing", {
6919
6919
  },
6920
6920
  create(context) {
6921
6921
  const sourceCode = context.sourceCode;
6922
- const options = parseOptions$4(context.options[0]);
6922
+ const options = parseOptions$5(context.options[0]);
6923
6923
  /**
6924
6924
  * Verify the space after the opening bracket and before the closing bracket.
6925
6925
  */
@@ -7228,11 +7228,11 @@ var link_paren_newline_default = createRule("link-paren-newline", {
7228
7228
  },
7229
7229
  create(context) {
7230
7230
  const sourceCode = context.sourceCode;
7231
- const optionProvider = parseOptions$8(context.options[0]);
7231
+ const optionProvider = parseOptions$9(context.options[0]);
7232
7232
  /**
7233
7233
  * Parse the options.
7234
7234
  */
7235
- function parseOptions$8(option) {
7235
+ function parseOptions$9(option) {
7236
7236
  const newline = option?.newline ?? "never";
7237
7237
  const multiline = option?.multiline ?? false;
7238
7238
  return (openingParenIndex, closingParenIndex) => {
@@ -8486,6 +8486,161 @@ var no_multiple_empty_lines_default = createRule("no-multiple-empty-lines", {
8486
8486
  }
8487
8487
  });
8488
8488
 
8489
+ //#endregion
8490
+ //#region src/rules/no-tabs.ts
8491
+ /**
8492
+ * Parse options
8493
+ */
8494
+ function parseOptions$4(options) {
8495
+ const checkTarget = options?.checkTarget || "all";
8496
+ const checkTargets = checkTarget === "all" ? ["indentation", "non-indentation"] : [checkTarget];
8497
+ return {
8498
+ ignoreCodeBlocks: options?.ignoreCodeBlocks || [],
8499
+ checkTargets,
8500
+ codeBlockTabWidth: options?.codeBlockTabWidth ?? 4
8501
+ };
8502
+ }
8503
+ var no_tabs_default = createRule("no-tabs", {
8504
+ meta: {
8505
+ type: "layout",
8506
+ docs: {
8507
+ description: "Disallow tab characters in Markdown files.",
8508
+ categories: ["standard"],
8509
+ listCategory: "Whitespace"
8510
+ },
8511
+ fixable: "whitespace",
8512
+ hasSuggestions: false,
8513
+ schema: [{
8514
+ type: "object",
8515
+ properties: {
8516
+ checkTarget: {
8517
+ type: "string",
8518
+ enum: [
8519
+ "all",
8520
+ "indentation",
8521
+ "non-indentation"
8522
+ ],
8523
+ default: "all"
8524
+ },
8525
+ ignoreCodeBlocks: {
8526
+ type: "array",
8527
+ items: { type: "string" },
8528
+ default: []
8529
+ },
8530
+ codeBlockTabWidth: {
8531
+ type: "integer",
8532
+ minimum: 1,
8533
+ default: 4
8534
+ }
8535
+ },
8536
+ additionalProperties: false
8537
+ }],
8538
+ messages: { unexpectedTab: "Unexpected tab character." }
8539
+ },
8540
+ create(context) {
8541
+ const sourceCode = context.sourceCode;
8542
+ const { ignoreCodeBlocks, checkTargets, codeBlockTabWidth } = parseOptions$4(context.options[0]);
8543
+ const codeBlocks = [];
8544
+ /** Check if a language should be ignored based on ignoreCodeBlocks option */
8545
+ function shouldIgnoreLanguage(language$2) {
8546
+ if (ignoreCodeBlocks.length === 0) return false;
8547
+ if (ignoreCodeBlocks.includes("*")) return true;
8548
+ return language$2 !== null && ignoreCodeBlocks.includes(language$2);
8549
+ }
8550
+ /**
8551
+ * Check if the given index is at indentation (beginning of line)
8552
+ */
8553
+ function isAtIndentation(index) {
8554
+ const loc = sourceCode.getLocFromIndex(index);
8555
+ const text = sourceCode.lines[loc.line - 1].slice(0, loc.column - 1);
8556
+ return !text || isWhitespace(text);
8557
+ }
8558
+ /**
8559
+ * Find the code block containing the given index
8560
+ */
8561
+ function findCodeBlock(index) {
8562
+ const codeBlock = codeBlocks.find((block) => index >= block.contentRange[0] && index < block.contentRange[1]);
8563
+ if (!codeBlock) return null;
8564
+ const loc = sourceCode.getLocFromIndex(index);
8565
+ if (getWidth(sourceCode.lines[loc.line - 1].slice(0, loc.column - 1)) < codeBlock.indentWidth) return null;
8566
+ return codeBlock;
8567
+ }
8568
+ /**
8569
+ * Calculate the number of spaces to replace a tab.
8570
+ * Handles both regular tabs and tabs within code block content.
8571
+ */
8572
+ function calculateReplacementSpaces(tabIndex, codeBlock) {
8573
+ const loc = sourceCode.getLocFromIndex(tabIndex);
8574
+ const beforeText = sourceCode.lines[loc.line - 1].slice(0, loc.column - 1);
8575
+ if (!codeBlock || codeBlockTabWidth === 4) return 4 - getWidth(beforeText) % 4;
8576
+ let tabStop = codeBlock.indentWidth <= 0 ? codeBlockTabWidth : 4;
8577
+ let beforeWidth = 0;
8578
+ for (const c of beforeText) {
8579
+ if (c === " ") beforeWidth += tabStop - beforeWidth % tabStop;
8580
+ else beforeWidth++;
8581
+ if (tabStop === 4 && codeBlock.indentWidth <= beforeWidth) tabStop = codeBlockTabWidth;
8582
+ }
8583
+ return tabStop - beforeWidth % tabStop;
8584
+ }
8585
+ return {
8586
+ code(node) {
8587
+ const range = sourceCode.getRange(node);
8588
+ const loc = sourceCode.getLoc(node);
8589
+ const codeBlockStartLineText = sourceCode.lines[loc.start.line - 1];
8590
+ const codeBlockIndentText = codeBlockStartLineText.slice(0, loc.start.column - 1);
8591
+ if (getCodeBlockKind(sourceCode, node) === "indented") {
8592
+ const baseWidth = getWidth(codeBlockIndentText);
8593
+ let indentText;
8594
+ let indentColumnIndex = loc.start.column;
8595
+ while (getWidth(indentText = codeBlockStartLineText.slice(0, indentColumnIndex)) < baseWidth + 4) indentColumnIndex++;
8596
+ codeBlocks.push({
8597
+ contentRange: [range[0] + 1, range[1]],
8598
+ indentWidth: getWidth(indentText),
8599
+ ignore: shouldIgnoreLanguage(null) ? "check" : indentText.includes(" ") ? "fix" : false
8600
+ });
8601
+ return;
8602
+ }
8603
+ const parsed = parseFencedCodeBlock(sourceCode, node);
8604
+ if (!parsed) {
8605
+ codeBlocks.push({
8606
+ contentRange: range,
8607
+ indentWidth: getWidth(codeBlockIndentText),
8608
+ ignore: "check"
8609
+ });
8610
+ return;
8611
+ }
8612
+ codeBlocks.push({
8613
+ contentRange: [(parsed.meta ?? parsed.language ?? parsed.openingFence).range[1], parsed.closingFence?.range[0] ?? range[1]],
8614
+ indentWidth: getWidth(codeBlockIndentText),
8615
+ ignore: shouldIgnoreLanguage(node.lang?.toLowerCase() ?? null) ? "check" : false
8616
+ });
8617
+ },
8618
+ "root:exit"() {
8619
+ for (let i = 0; i < sourceCode.text.length; i++) {
8620
+ if (sourceCode.text[i] !== " ") continue;
8621
+ if (isAtIndentation(i)) {
8622
+ if (!checkTargets.includes("indentation")) continue;
8623
+ } else if (!checkTargets.includes("non-indentation")) continue;
8624
+ const codeBlock = findCodeBlock(i);
8625
+ if (codeBlock?.ignore === "check") continue;
8626
+ context.report({
8627
+ loc: {
8628
+ start: sourceCode.getLocFromIndex(i),
8629
+ end: sourceCode.getLocFromIndex(i + 1)
8630
+ },
8631
+ messageId: "unexpectedTab",
8632
+ fix: (fixer) => {
8633
+ if (codeBlock?.ignore === "fix") return null;
8634
+ const spaces = calculateReplacementSpaces(i, codeBlock);
8635
+ return fixer.replaceTextRange([i, i + 1], " ".repeat(spaces));
8636
+ }
8637
+ });
8638
+ }
8639
+ }
8640
+ };
8641
+ }
8642
+ });
8643
+
8489
8644
  //#endregion
8490
8645
  //#region src/rules/no-text-backslash-linebreak.ts
8491
8646
  var no_text_backslash_linebreak_default = createRule("no-text-backslash-linebreak", {
@@ -12109,6 +12264,7 @@ const rules$1 = [
12109
12264
  no_laziness_blockquotes_default,
12110
12265
  no_multi_spaces_default,
12111
12266
  no_multiple_empty_lines_default,
12267
+ no_tabs_default,
12112
12268
  no_text_backslash_linebreak_default,
12113
12269
  no_trailing_spaces_default,
12114
12270
  ordered_list_marker_sequence_default,
@@ -12209,6 +12365,7 @@ const rules$2 = {
12209
12365
  "markdown-preferences/no-laziness-blockquotes": "error",
12210
12366
  "markdown-preferences/no-multi-spaces": "error",
12211
12367
  "markdown-preferences/no-multiple-empty-lines": "error",
12368
+ "markdown-preferences/no-tabs": "error",
12212
12369
  "markdown-preferences/no-text-backslash-linebreak": "error",
12213
12370
  "markdown-preferences/no-trailing-spaces": "error",
12214
12371
  "markdown-preferences/ordered-list-marker-sequence": "error",
@@ -12236,7 +12393,7 @@ var meta_exports = /* @__PURE__ */ __export({
12236
12393
  version: () => version
12237
12394
  });
12238
12395
  const name = "eslint-plugin-markdown-preferences";
12239
- const version = "0.36.3";
12396
+ const version = "0.37.0";
12240
12397
 
12241
12398
  //#endregion
12242
12399
  //#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.36.3",
3
+ "version": "0.37.0",
4
4
  "description": "ESLint plugin that enforces our markdown preferences",
5
5
  "type": "module",
6
6
  "exports": {
@@ -80,7 +80,7 @@
80
80
  "@changesets/changelog-github": "^0.5.1",
81
81
  "@changesets/cli": "^2.28.1",
82
82
  "@changesets/get-release-plan": "^4.0.8",
83
- "@eslint/core": "^0.17.0",
83
+ "@eslint/core": "^1.0.0",
84
84
  "@eslint/markdown": "^7.4.0",
85
85
  "@ota-meshi/eslint-plugin": "^0.18.0",
86
86
  "@shikijs/vitepress-twoslash": "^3.0.0",
@@ -114,7 +114,7 @@
114
114
  "eslint-plugin-yml": "^1.17.0",
115
115
  "eslint-snapshot-rule-tester": "^0.1.0",
116
116
  "eslint-typegen": "^2.0.0",
117
- "espree": "^10.3.0",
117
+ "espree": "^11.0.0",
118
118
  "events": "^3.3.0",
119
119
  "globals": "^16.0.0",
120
120
  "mocha": "^11.1.0",
@@ -1,13 +0,0 @@
1
- //#region rolldown:runtime
2
- var __defProp = Object.defineProperty;
3
- var __export = (all) => {
4
- let target = {};
5
- for (var name in all) __defProp(target, name, {
6
- get: all[name],
7
- enumerable: true
8
- });
9
- return target;
10
- };
11
-
12
- //#endregion
13
- export { __export as t };