eslint-plugin-markdown-preferences 0.26.1 → 0.28.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 +47 -2
- package/lib/index.d.ts +177 -7
- package/lib/index.js +882 -111
- package/package.json +11 -1
package/README.md
CHANGED
|
@@ -58,17 +58,18 @@ Example **eslint.config.js**:
|
|
|
58
58
|
import { defineConfig } from "eslint/config";
|
|
59
59
|
// import markdown from "@eslint/markdown";
|
|
60
60
|
import markdownPreferences from "eslint-plugin-markdown-preferences";
|
|
61
|
-
export default [
|
|
61
|
+
export default defineConfig([
|
|
62
62
|
// add more generic rule sets here, such as:
|
|
63
63
|
// markdown.configs.recommended,
|
|
64
64
|
markdownPreferences.configs.recommended,
|
|
65
65
|
{
|
|
66
|
+
files: ["**/*.md", "*.md"],
|
|
66
67
|
rules: {
|
|
67
68
|
// override/add rules settings here, such as:
|
|
68
69
|
// 'markdown-preferences/prefer-linked-words': 'error'
|
|
69
70
|
},
|
|
70
71
|
},
|
|
71
|
-
];
|
|
72
|
+
]);
|
|
72
73
|
```
|
|
73
74
|
|
|
74
75
|
This plugin provides configs:
|
|
@@ -78,6 +79,49 @@ This plugin provides configs:
|
|
|
78
79
|
|
|
79
80
|
See [the rule list](https://ota-meshi.github.io/eslint-plugin-markdown-preferences/rules/) to get the `rules` that this plugin provides.
|
|
80
81
|
|
|
82
|
+
##### Using Extended Syntax
|
|
83
|
+
|
|
84
|
+
This plugin experimentally supports some extended Markdown syntax.\
|
|
85
|
+
To use these extended syntaxes, set the `markdown-preferences/extended-syntax` language option.
|
|
86
|
+
|
|
87
|
+
```js
|
|
88
|
+
import { defineConfig } from "eslint/config";
|
|
89
|
+
import markdownPreferences from "eslint-plugin-markdown-preferences";
|
|
90
|
+
export default defineConfig([
|
|
91
|
+
{
|
|
92
|
+
extends: [markdownPreferences.configs.recommended],
|
|
93
|
+
language: "markdown-preferences/extended-syntax",
|
|
94
|
+
},
|
|
95
|
+
]);
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
The following syntaxes are supported:
|
|
99
|
+
|
|
100
|
+
- [Custom Containers](https://vitepress.dev/guide/markdown#custom-containers)\
|
|
101
|
+
Example:
|
|
102
|
+
|
|
103
|
+
```md
|
|
104
|
+
::: warning
|
|
105
|
+
This is a warning box.
|
|
106
|
+
:::
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
- [Mathematical Expressions](https://docs.github.com/get-started/writing-on-github/working-with-advanced-formatting/writing-mathematical-expressions)\
|
|
110
|
+
Example:
|
|
111
|
+
|
|
112
|
+
```md
|
|
113
|
+
$$
|
|
114
|
+
E = mc^2
|
|
115
|
+
$$
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
- [VitePress-style Import Code Snippets](https://vitepress.dev/guide/markdown#import-code-snippets) syntax using triple left angle brackets\
|
|
119
|
+
Example:
|
|
120
|
+
|
|
121
|
+
```md
|
|
122
|
+
<<< @/filepath
|
|
123
|
+
```
|
|
124
|
+
|
|
81
125
|
#### Legacy Config (`.eslintrc`)
|
|
82
126
|
|
|
83
127
|
Is not supported.
|
|
@@ -131,6 +175,7 @@ The rules with the following 💄 are included in the `standard` config.
|
|
|
131
175
|
| [markdown-preferences/level2-heading-style](https://ota-meshi.github.io/eslint-plugin-markdown-preferences/rules/level2-heading-style.html) | enforce consistent style for level 2 headings | 🔧 | 💄 |
|
|
132
176
|
| [markdown-preferences/link-destination-style](https://ota-meshi.github.io/eslint-plugin-markdown-preferences/rules/link-destination-style.html) | enforce a consistent style for link destinations | 🔧 | 💄 |
|
|
133
177
|
| [markdown-preferences/link-title-style](https://ota-meshi.github.io/eslint-plugin-markdown-preferences/rules/link-title-style.html) | enforce a consistent style for link titles | 🔧 | 💄 |
|
|
178
|
+
| [markdown-preferences/no-implicit-block-closing](https://ota-meshi.github.io/eslint-plugin-markdown-preferences/rules/no-implicit-block-closing.html) | disallow implicit block closing for fenced code blocks, math blocks, and custom blocks | 🔧 | ⭐💄 |
|
|
134
179
|
| [markdown-preferences/no-text-backslash-linebreak](https://ota-meshi.github.io/eslint-plugin-markdown-preferences/rules/no-text-backslash-linebreak.html) | disallow text backslash at the end of a line. | | ⭐💄 |
|
|
135
180
|
| [markdown-preferences/ordered-list-marker-style](https://ota-meshi.github.io/eslint-plugin-markdown-preferences/rules/ordered-list-marker-style.html) | enforce consistent ordered list marker style | 🔧 | 💄 |
|
|
136
181
|
| [markdown-preferences/prefer-autolinks](https://ota-meshi.github.io/eslint-plugin-markdown-preferences/rules/prefer-autolinks.html) | enforce the use of autolinks for URLs | 🔧 | ⭐💄 |
|
package/lib/index.d.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import markdown from "@eslint/markdown";
|
|
2
|
+
import * as math from "mdast-util-math";
|
|
2
3
|
import * as _eslint_core0 from "@eslint/core";
|
|
3
|
-
import { RuleDefinition } from "@eslint/core";
|
|
4
|
+
import { File, Language, OkParseResult, ParseResult, RuleDefinition, SourceLocation } from "@eslint/core";
|
|
4
5
|
import { ESLint, Linter } from "eslint";
|
|
6
|
+
import * as eslint from "@eslint/markdown/types";
|
|
7
|
+
import { MarkdownLanguageContext, MarkdownLanguageOptions } from "@eslint/markdown/types";
|
|
8
|
+
import * as mdast from "mdast";
|
|
9
|
+
import { TextSourceCodeBase } from "@eslint/plugin-kit";
|
|
5
10
|
|
|
6
11
|
//#region src/rule-types.d.ts
|
|
7
12
|
declare module 'eslint' {
|
|
@@ -120,6 +125,11 @@ interface RuleOptions {
|
|
|
120
125
|
* @see https://ota-meshi.github.io/eslint-plugin-markdown-preferences/rules/list-marker-alignment.html
|
|
121
126
|
*/
|
|
122
127
|
'markdown-preferences/list-marker-alignment'?: Linter.RuleEntry<MarkdownPreferencesListMarkerAlignment>;
|
|
128
|
+
/**
|
|
129
|
+
* disallow implicit block closing for fenced code blocks, math blocks, and custom blocks
|
|
130
|
+
* @see https://ota-meshi.github.io/eslint-plugin-markdown-preferences/rules/no-implicit-block-closing.html
|
|
131
|
+
*/
|
|
132
|
+
'markdown-preferences/no-implicit-block-closing'?: Linter.RuleEntry<[]>;
|
|
123
133
|
/**
|
|
124
134
|
* disallow laziness in blockquotes
|
|
125
135
|
* @see https://ota-meshi.github.io/eslint-plugin-markdown-preferences/rules/no-laziness-blockquotes.html
|
|
@@ -380,12 +390,12 @@ type MarkdownPreferencesOrderedListMarkerStyle = [] | [{
|
|
|
380
390
|
}[];
|
|
381
391
|
}];
|
|
382
392
|
type MarkdownPreferencesPaddingLineBetweenBlocks = {
|
|
383
|
-
prev: (("blockquote" | "code" | "heading" | "html" | "list" | "paragraph" | "thematic-break" | "table" | "link-definition" | "footnote-definition" | "frontmatter" | "*") | [("blockquote" | "code" | "heading" | "html" | "list" | "paragraph" | "thematic-break" | "table" | "link-definition" | "footnote-definition" | "frontmatter" | "*"), ...(("blockquote" | "code" | "heading" | "html" | "list" | "paragraph" | "thematic-break" | "table" | "link-definition" | "footnote-definition" | "frontmatter" | "*"))[]] | {
|
|
384
|
-
type: (("blockquote" | "code" | "heading" | "html" | "list" | "paragraph" | "thematic-break" | "table" | "link-definition" | "footnote-definition" | "frontmatter" | "*") | [("blockquote" | "code" | "heading" | "html" | "list" | "paragraph" | "thematic-break" | "table" | "link-definition" | "footnote-definition" | "frontmatter" | "*"), ...(("blockquote" | "code" | "heading" | "html" | "list" | "paragraph" | "thematic-break" | "table" | "link-definition" | "footnote-definition" | "frontmatter" | "*"))[]]);
|
|
393
|
+
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" | "*"))[]] | {
|
|
394
|
+
type: (("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" | "*"))[]]);
|
|
385
395
|
in?: ("list" | "blockquote" | "footnote-definition");
|
|
386
396
|
});
|
|
387
|
-
next: (("blockquote" | "code" | "heading" | "html" | "list" | "paragraph" | "thematic-break" | "table" | "link-definition" | "footnote-definition" | "frontmatter" | "*") | [("blockquote" | "code" | "heading" | "html" | "list" | "paragraph" | "thematic-break" | "table" | "link-definition" | "footnote-definition" | "frontmatter" | "*"), ...(("blockquote" | "code" | "heading" | "html" | "list" | "paragraph" | "thematic-break" | "table" | "link-definition" | "footnote-definition" | "frontmatter" | "*"))[]] | {
|
|
388
|
-
type: (("blockquote" | "code" | "heading" | "html" | "list" | "paragraph" | "thematic-break" | "table" | "link-definition" | "footnote-definition" | "frontmatter" | "*") | [("blockquote" | "code" | "heading" | "html" | "list" | "paragraph" | "thematic-break" | "table" | "link-definition" | "footnote-definition" | "frontmatter" | "*"), ...(("blockquote" | "code" | "heading" | "html" | "list" | "paragraph" | "thematic-break" | "table" | "link-definition" | "footnote-definition" | "frontmatter" | "*"))[]]);
|
|
397
|
+
next: (("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" | "*"))[]] | {
|
|
398
|
+
type: (("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" | "*"))[]]);
|
|
389
399
|
in?: ("list" | "blockquote" | "footnote-definition");
|
|
390
400
|
});
|
|
391
401
|
blankLine: ("any" | "never" | "always");
|
|
@@ -498,7 +508,161 @@ declare namespace meta_d_exports {
|
|
|
498
508
|
export { name, version };
|
|
499
509
|
}
|
|
500
510
|
declare const name: "eslint-plugin-markdown-preferences";
|
|
501
|
-
declare const version: "0.
|
|
511
|
+
declare const version: "0.28.0";
|
|
512
|
+
//#endregion
|
|
513
|
+
//#region src/language/ast-types.d.ts
|
|
514
|
+
type Node = mdast.Node;
|
|
515
|
+
type Root = ExtendChildren<mdast.Root, RootContent>;
|
|
516
|
+
type Blockquote = ExtendChildren<mdast.Blockquote, CustomContainer>;
|
|
517
|
+
type Break = mdast.Break;
|
|
518
|
+
type Code = mdast.Code;
|
|
519
|
+
type Definition = mdast.Definition;
|
|
520
|
+
type Delete = mdast.Delete;
|
|
521
|
+
type Emphasis = mdast.Emphasis;
|
|
522
|
+
type FootnoteDefinition = ExtendChildren<mdast.FootnoteDefinition, CustomContainer>;
|
|
523
|
+
type FootnoteReference = mdast.FootnoteReference;
|
|
524
|
+
type Heading = mdast.Heading;
|
|
525
|
+
type Html = mdast.Html;
|
|
526
|
+
type Image = mdast.Image;
|
|
527
|
+
type ImageReference = mdast.ImageReference;
|
|
528
|
+
type InlineCode = mdast.InlineCode;
|
|
529
|
+
type Link = mdast.Link;
|
|
530
|
+
type LinkReference = mdast.LinkReference;
|
|
531
|
+
type List = mdast.List;
|
|
532
|
+
type ListItem = ExtendChildren<mdast.ListItem, CustomContainer>;
|
|
533
|
+
type Paragraph = mdast.Paragraph;
|
|
534
|
+
type Strong = mdast.Strong;
|
|
535
|
+
type Table = mdast.Table;
|
|
536
|
+
type TableCell = mdast.TableCell;
|
|
537
|
+
type TableRow = mdast.TableRow;
|
|
538
|
+
type Text = mdast.Text;
|
|
539
|
+
type ThematicBreak = mdast.ThematicBreak;
|
|
540
|
+
type Yaml = mdast.Yaml;
|
|
541
|
+
type Math = math.Math;
|
|
542
|
+
type InlineMath = math.InlineMath;
|
|
543
|
+
type Toml = eslint.Toml;
|
|
544
|
+
type Json = eslint.Json;
|
|
545
|
+
interface CustomContainer extends ExtendChildren<mdast.Parent, CustomContainer | ImportCodeSnippet> {
|
|
546
|
+
/**
|
|
547
|
+
* Node type of mdast custom container.
|
|
548
|
+
*/
|
|
549
|
+
type: "customContainer";
|
|
550
|
+
/**
|
|
551
|
+
* Info string (e.g., "warning" in ::: warning ... :::).
|
|
552
|
+
*/
|
|
553
|
+
info: string | null;
|
|
554
|
+
/**
|
|
555
|
+
* Children of custom container.
|
|
556
|
+
*/
|
|
557
|
+
children: (CustomContainer | BlockContent | DefinitionContent)[];
|
|
558
|
+
}
|
|
559
|
+
interface ImportCodeSnippet extends mdast.Literal {
|
|
560
|
+
/**
|
|
561
|
+
* Node type of mdast import code snippet.
|
|
562
|
+
*/
|
|
563
|
+
type: "importCodeSnippet";
|
|
564
|
+
}
|
|
565
|
+
type RootContent = RootContentMap[keyof RootContentMap];
|
|
566
|
+
type BlockContent = RootContentMap[keyof mdast.BlockContentMap] | ImportCodeSnippet;
|
|
567
|
+
type DefinitionContent = RootContentMap[keyof mdast.DefinitionContentMap];
|
|
568
|
+
type ExtendChildren<N extends mdast.Node & {
|
|
569
|
+
children: mdast.Node[];
|
|
570
|
+
}, C extends mdast.Node> = Omit<N, "children"> & {
|
|
571
|
+
children: (MapChild<N["children"][number]> | C)[];
|
|
572
|
+
};
|
|
573
|
+
type MapChild<N extends mdast.Node> = N["type"] extends RootContent["type"] ? RootContentMap[N["type"]] : N;
|
|
574
|
+
interface RootContentMap {
|
|
575
|
+
blockquote: Blockquote;
|
|
576
|
+
break: Break;
|
|
577
|
+
code: Code;
|
|
578
|
+
definition: Definition;
|
|
579
|
+
delete: Delete;
|
|
580
|
+
emphasis: Emphasis;
|
|
581
|
+
footnoteDefinition: FootnoteDefinition;
|
|
582
|
+
footnoteReference: FootnoteReference;
|
|
583
|
+
heading: Heading;
|
|
584
|
+
html: Html;
|
|
585
|
+
image: Image;
|
|
586
|
+
imageReference: ImageReference;
|
|
587
|
+
inlineCode: InlineCode;
|
|
588
|
+
link: Link;
|
|
589
|
+
linkReference: LinkReference;
|
|
590
|
+
list: List;
|
|
591
|
+
listItem: ListItem;
|
|
592
|
+
paragraph: Paragraph;
|
|
593
|
+
strong: Strong;
|
|
594
|
+
table: Table;
|
|
595
|
+
tableCell: TableCell;
|
|
596
|
+
tableRow: TableRow;
|
|
597
|
+
text: Text;
|
|
598
|
+
thematicBreak: ThematicBreak;
|
|
599
|
+
yaml: Yaml;
|
|
600
|
+
toml: Toml;
|
|
601
|
+
json: Json;
|
|
602
|
+
customContainer: CustomContainer;
|
|
603
|
+
inlineMath: InlineMath;
|
|
604
|
+
math: Math;
|
|
605
|
+
importCodeSnippet: ImportCodeSnippet;
|
|
606
|
+
}
|
|
607
|
+
//#endregion
|
|
608
|
+
//#region src/language/extended-markdown-language.d.ts
|
|
609
|
+
type ExtendedMarkdownSourceCode = TextSourceCodeBase<{
|
|
610
|
+
LangOptions: MarkdownLanguageOptions;
|
|
611
|
+
RootNode: Root;
|
|
612
|
+
SyntaxElementWithLoc: Node;
|
|
613
|
+
ConfigNode: {
|
|
614
|
+
value: string;
|
|
615
|
+
position: SourceLocation;
|
|
616
|
+
};
|
|
617
|
+
}>;
|
|
618
|
+
declare class ExtendedMarkdownLanguage implements Language {
|
|
619
|
+
/**
|
|
620
|
+
* The type of file to read.
|
|
621
|
+
* @type {"text"}
|
|
622
|
+
*/
|
|
623
|
+
readonly fileType: "text";
|
|
624
|
+
/**
|
|
625
|
+
* The line number at which the parser starts counting.
|
|
626
|
+
* @type {0|1}
|
|
627
|
+
*/
|
|
628
|
+
readonly lineStart: 0 | 1;
|
|
629
|
+
/**
|
|
630
|
+
* The column number at which the parser starts counting.
|
|
631
|
+
* @type {0|1}
|
|
632
|
+
*/
|
|
633
|
+
readonly columnStart: 0 | 1;
|
|
634
|
+
/**
|
|
635
|
+
* The name of the key that holds the type of the node.
|
|
636
|
+
* @type {string}
|
|
637
|
+
*/
|
|
638
|
+
readonly nodeTypeKey: string;
|
|
639
|
+
/**
|
|
640
|
+
* Default language options. User-defined options are merged with this object.
|
|
641
|
+
* @type {MarkdownLanguageOptions}
|
|
642
|
+
*/
|
|
643
|
+
readonly defaultLanguageOptions: MarkdownLanguageOptions;
|
|
644
|
+
/**
|
|
645
|
+
* Validates the language options.
|
|
646
|
+
* @param {MarkdownLanguageOptions} languageOptions The language options to validate.
|
|
647
|
+
* @returns {void}
|
|
648
|
+
* @throws {Error} When the language options are invalid.
|
|
649
|
+
*/
|
|
650
|
+
validateLanguageOptions(languageOptions: MarkdownLanguageOptions): void;
|
|
651
|
+
/**
|
|
652
|
+
* Parses the given file into an AST.
|
|
653
|
+
* @param {File} file The virtual file to parse.
|
|
654
|
+
* @param {MarkdownLanguageContext} _context The options to use for parsing.
|
|
655
|
+
* @returns {ParseResult<Root>} The result of parsing.
|
|
656
|
+
*/
|
|
657
|
+
parse(file: File, _context: MarkdownLanguageContext): ParseResult<Root>;
|
|
658
|
+
/**
|
|
659
|
+
* Creates a new `MarkdownSourceCode` object from the given information.
|
|
660
|
+
* @param {File} file The virtual file to create a `MarkdownSourceCode` object from.
|
|
661
|
+
* @param {OkParseResult<Root>} parseResult The result returned from `parse()`.
|
|
662
|
+
* @returns {MarkdownSourceCode} The new `MarkdownSourceCode` object.
|
|
663
|
+
*/
|
|
664
|
+
createSourceCode(file: File, parseResult: OkParseResult<Root>): ExtendedMarkdownSourceCode;
|
|
665
|
+
}
|
|
502
666
|
//#endregion
|
|
503
667
|
//#region src/index.d.ts
|
|
504
668
|
declare const configs: {
|
|
@@ -510,8 +674,14 @@ declare const resources: {
|
|
|
510
674
|
defaultPreserveWords: string[];
|
|
511
675
|
defaultMinorWords: string[];
|
|
512
676
|
};
|
|
677
|
+
declare const languages: {
|
|
678
|
+
"extended-syntax": ExtendedMarkdownLanguage;
|
|
679
|
+
};
|
|
513
680
|
declare const _default: {
|
|
514
681
|
meta: typeof meta_d_exports;
|
|
682
|
+
languages: {
|
|
683
|
+
"extended-syntax": ExtendedMarkdownLanguage;
|
|
684
|
+
};
|
|
515
685
|
configs: {
|
|
516
686
|
recommended: typeof recommended_d_exports;
|
|
517
687
|
standard: typeof standard_d_exports;
|
|
@@ -523,4 +693,4 @@ declare const _default: {
|
|
|
523
693
|
};
|
|
524
694
|
};
|
|
525
695
|
//#endregion
|
|
526
|
-
export { RuleOptions, configs, _default as default, meta_d_exports as meta, resources, rules };
|
|
696
|
+
export { RuleOptions, configs, _default as default, languages, meta_d_exports as meta, resources, rules };
|