mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-16 22:10:13 +01:00
Add typings for Rule object to all Rule samples and examples.
This commit is contained in:
parent
cdc30b1279
commit
c287e49eac
11 changed files with 34 additions and 9 deletions
|
|
@ -54,6 +54,14 @@
|
||||||
"object-property-newline": "off"
|
"object-property-newline": "off"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"files": [
|
||||||
|
"test/rules/**/*.js"
|
||||||
|
],
|
||||||
|
"rules": {
|
||||||
|
"jsdoc/valid-types": "off"
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"files": [
|
"files": [
|
||||||
"**/*.mjs"
|
"**/*.mjs"
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ the parsed input and a function to log any violations.
|
||||||
A simple rule implementation looks like:
|
A simple rule implementation looks like:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
|
/** @type import("markdownlint").Rule */
|
||||||
module.exports = {
|
module.exports = {
|
||||||
"names": [ "any-blockquote" ],
|
"names": [ "any-blockquote" ],
|
||||||
"description": "Rule that reports an error for any blockquote",
|
"description": "Rule that reports an error for any blockquote",
|
||||||
|
|
|
||||||
|
|
@ -109,7 +109,7 @@ markdownlint(options, assertLintResultsCallback);
|
||||||
assertLintResultsCallback(null, await markdownlint.promises.markdownlint(options));
|
assertLintResultsCallback(null, await markdownlint.promises.markdownlint(options));
|
||||||
})();
|
})();
|
||||||
|
|
||||||
const testRule = {
|
const testRule: markdownlint.Rule = {
|
||||||
"names": [ "test-rule" ],
|
"names": [ "test-rule" ],
|
||||||
"description": "Test rule",
|
"description": "Test rule",
|
||||||
"information": new URL("https://example.com/rule-information"),
|
"information": new URL("https://example.com/rule-information"),
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ be useful to custom rule authors and may avoid duplicating code.
|
||||||
```javascript
|
```javascript
|
||||||
const { forEachLine, getLineMetadata } = require("markdownlint-rule-helpers");
|
const { forEachLine, getLineMetadata } = require("markdownlint-rule-helpers");
|
||||||
|
|
||||||
|
/** @type import("markdownlint").Rule */
|
||||||
module.exports = {
|
module.exports = {
|
||||||
"names": [ "every-n-lines" ],
|
"names": [ "every-n-lines" ],
|
||||||
"description": "Rule that reports an error every N lines",
|
"description": "Rule that reports an error every N lines",
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,10 @@
|
||||||
|
|
||||||
const { filterTokens } = require("markdownlint-rule-helpers");
|
const { filterTokens } = require("markdownlint-rule-helpers");
|
||||||
|
|
||||||
|
/** @typedef {import("../../lib/markdownlint").MarkdownItToken} MarkdownItToken */
|
||||||
|
/** @typedef {(MarkdownItToken) => void} FilterTokensCallback */
|
||||||
|
|
||||||
|
/** @type import("../../lib/markdownlint").Rule */
|
||||||
module.exports = {
|
module.exports = {
|
||||||
"names": [ "any-blockquote" ],
|
"names": [ "any-blockquote" ],
|
||||||
"description": "Rule that reports an error for any blockquote",
|
"description": "Rule that reports an error for any blockquote",
|
||||||
|
|
@ -13,13 +17,18 @@ module.exports = {
|
||||||
),
|
),
|
||||||
"tags": [ "test" ],
|
"tags": [ "test" ],
|
||||||
"function": (params, onError) => {
|
"function": (params, onError) => {
|
||||||
filterTokens(params, "blockquote_open", (blockquote) => {
|
filterTokens(
|
||||||
const lines = blockquote.map[1] - blockquote.map[0];
|
params,
|
||||||
onError({
|
"blockquote_open",
|
||||||
"lineNumber": blockquote.lineNumber,
|
/** @type FilterTokensCallback */
|
||||||
"detail": "Blockquote spans " + lines + " line(s).",
|
(blockquote) => {
|
||||||
"context": blockquote.line.substr(0, 7)
|
const lines = blockquote.map[1] - blockquote.map[0];
|
||||||
});
|
onError({
|
||||||
});
|
"lineNumber": blockquote.lineNumber,
|
||||||
|
"detail": "Blockquote spans " + lines + " line(s).",
|
||||||
|
"context": blockquote.line.substr(0, 7)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
const { forEachLine, getLineMetadata } = require("markdownlint-rule-helpers");
|
const { forEachLine, getLineMetadata } = require("markdownlint-rule-helpers");
|
||||||
|
|
||||||
|
/** @type import("../../lib/markdownlint").Rule */
|
||||||
module.exports = {
|
module.exports = {
|
||||||
"names": [ "every-n-lines" ],
|
"names": [ "every-n-lines" ],
|
||||||
"description": "Rule that reports an error every N lines",
|
"description": "Rule that reports an error every N lines",
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
/** @type import("../../lib/markdownlint").Rule */
|
||||||
module.exports = {
|
module.exports = {
|
||||||
"names": [ "first-line" ],
|
"names": [ "first-line" ],
|
||||||
"description": "Rule that reports an error for the first line",
|
"description": "Rule that reports an error for the first line",
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
/** @type import("../../lib/markdownlint").Rule */
|
||||||
module.exports = {
|
module.exports = {
|
||||||
"names": [ "letters-E-X", "letter-E-letter-X", "contains-ex" ],
|
"names": [ "letters-E-X", "letter-E-letter-X", "contains-ex" ],
|
||||||
"description": "Rule that reports an error for lines with the letters 'EX'",
|
"description": "Rule that reports an error for lines with the letters 'EX'",
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ function cleanJsdocRulesFromEslintConfig(config) {
|
||||||
return cleanedConfig;
|
return cleanedConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @type import("../../lib/markdownlint").Rule */
|
||||||
module.exports = {
|
module.exports = {
|
||||||
"names": [ "lint-javascript" ],
|
"names": [ "lint-javascript" ],
|
||||||
"description": "Rule that lints JavaScript code",
|
"description": "Rule that lints JavaScript code",
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
/** @type import("../../../lib/markdownlint").Rule */
|
||||||
module.exports = {
|
module.exports = {
|
||||||
"names": [ "sample-rule" ],
|
"names": [ "sample-rule" ],
|
||||||
"description": "Sample rule",
|
"description": "Sample rule",
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
const { filterTokens } = require("markdownlint-rule-helpers");
|
const { filterTokens } = require("markdownlint-rule-helpers");
|
||||||
const { parse, printParseErrorCode } = require("jsonc-parser");
|
const { parse, printParseErrorCode } = require("jsonc-parser");
|
||||||
|
|
||||||
|
/** @type import("../../lib/markdownlint").Rule */
|
||||||
module.exports = {
|
module.exports = {
|
||||||
"names": [ "validate-json" ],
|
"names": [ "validate-json" ],
|
||||||
"description": "Rule that validates JSON code",
|
"description": "Rule that validates JSON code",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue