mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-16 14:00:13 +01:00
Add Rule.parser property for custom rules to specify which Markdown parser output they use, honor it strictly, and add full type support.
This commit is contained in:
parent
d2acc168d2
commit
d5994ae4de
68 changed files with 635 additions and 115 deletions
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
const { filterTokens } = require("markdownlint-rule-helpers");
|
||||
const { filterTokens } = require("../../helpers");
|
||||
|
||||
/** @typedef {import("../../lib/markdownlint").MarkdownItToken} MarkdownItToken */
|
||||
/** @typedef {(MarkdownItToken) => void} FilterTokensCallback */
|
||||
|
|
@ -16,6 +16,7 @@ module.exports = {
|
|||
"/blob/main/test/rules/any-blockquote.js"
|
||||
),
|
||||
"tags": [ "test" ],
|
||||
"parser": "markdownit",
|
||||
"function": (params, onError) => {
|
||||
filterTokens(
|
||||
params,
|
||||
|
|
|
|||
|
|
@ -2,13 +2,14 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
const { forEachLine, getLineMetadata } = require("markdownlint-rule-helpers");
|
||||
const { forEachLine, getLineMetadata } = require("../../helpers");
|
||||
|
||||
/** @type import("../../lib/markdownlint").Rule */
|
||||
module.exports = {
|
||||
"names": [ "every-n-lines" ],
|
||||
"description": "Rule that reports an error every N lines",
|
||||
"tags": [ "test" ],
|
||||
"parser": "markdownit",
|
||||
"function": (params, onError) => {
|
||||
const n = params.config.n || 2;
|
||||
forEachLine(getLineMetadata(params), (line, lineIndex) => {
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ module.exports = {
|
|||
"names": [ "first-line" ],
|
||||
"description": "Rule that reports an error for the first line",
|
||||
"tags": [ "test" ],
|
||||
"parser": "none",
|
||||
"function": function rule(params, onError) {
|
||||
// Unconditionally report an error for line 1
|
||||
onError({
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ module.exports = {
|
|||
"/blob/main/test/rules/letters-E-X.js"
|
||||
),
|
||||
"tags": [ "test" ],
|
||||
"parser": "markdownit",
|
||||
"function": (params, onError) => {
|
||||
for (const inline of params.parsers.markdownit.tokens.filter(
|
||||
(token) => token.type === "inline"
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
const { filterTokens } = require("markdownlint-rule-helpers");
|
||||
const { filterTokens } = require("../../helpers");
|
||||
const eslint = require("eslint");
|
||||
const eslintInstance = new eslint.ESLint();
|
||||
const linter = new eslint.Linter();
|
||||
|
|
@ -29,6 +29,7 @@ module.exports = {
|
|||
"names": [ "lint-javascript" ],
|
||||
"description": "Rule that lints JavaScript code",
|
||||
"tags": [ "test", "lint", "javascript" ],
|
||||
"parser": "markdownit",
|
||||
"asynchronous": true,
|
||||
"function": (params, onError) => {
|
||||
filterTokens(params, "fence", (fence) => {
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ module.exports = {
|
|||
"names": [ "sample-rule" ],
|
||||
"description": "Sample rule",
|
||||
"tags": [ "sample" ],
|
||||
"parser": "markdownit",
|
||||
"function": function rule(params, onError) {
|
||||
for (const token of params.parsers.markdownit.tokens) {
|
||||
if (token.type === "hr") {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
const { filterTokens } = require("markdownlint-rule-helpers");
|
||||
const { filterTokens } = require("../../helpers");
|
||||
const { parse, printParseErrorCode } = require("jsonc-parser");
|
||||
|
||||
/** @type import("../../lib/markdownlint").Rule */
|
||||
|
|
@ -10,6 +10,7 @@ module.exports = {
|
|||
"names": [ "validate-json" ],
|
||||
"description": "Rule that validates JSON code",
|
||||
"tags": [ "test", "validate", "json" ],
|
||||
"parser": "markdownit",
|
||||
"asynchronous": true,
|
||||
"function": (params, onError) => {
|
||||
filterTokens(params, "fence", (fence) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue