Add typings for Rule object to all Rule samples and examples.

This commit is contained in:
David Anson 2024-03-06 21:18:51 -08:00
parent cdc30b1279
commit c287e49eac
11 changed files with 34 additions and 9 deletions

View file

@ -54,6 +54,14 @@
"object-property-newline": "off"
}
},
{
"files": [
"test/rules/**/*.js"
],
"rules": {
"jsdoc/valid-types": "off"
}
},
{
"files": [
"**/*.mjs"

View file

@ -28,6 +28,7 @@ the parsed input and a function to log any violations.
A simple rule implementation looks like:
```javascript
/** @type import("markdownlint").Rule */
module.exports = {
"names": [ "any-blockquote" ],
"description": "Rule that reports an error for any blockquote",

View file

@ -109,7 +109,7 @@ markdownlint(options, assertLintResultsCallback);
assertLintResultsCallback(null, await markdownlint.promises.markdownlint(options));
})();
const testRule = {
const testRule: markdownlint.Rule = {
"names": [ "test-rule" ],
"description": "Test rule",
"information": new URL("https://example.com/rule-information"),

View file

@ -24,6 +24,7 @@ be useful to custom rule authors and may avoid duplicating code.
```javascript
const { forEachLine, getLineMetadata } = require("markdownlint-rule-helpers");
/** @type import("markdownlint").Rule */
module.exports = {
"names": [ "every-n-lines" ],
"description": "Rule that reports an error every N lines",

View file

@ -4,6 +4,10 @@
const { filterTokens } = require("markdownlint-rule-helpers");
/** @typedef {import("../../lib/markdownlint").MarkdownItToken} MarkdownItToken */
/** @typedef {(MarkdownItToken) => void} FilterTokensCallback */
/** @type import("../../lib/markdownlint").Rule */
module.exports = {
"names": [ "any-blockquote" ],
"description": "Rule that reports an error for any blockquote",
@ -13,13 +17,18 @@ module.exports = {
),
"tags": [ "test" ],
"function": (params, onError) => {
filterTokens(params, "blockquote_open", (blockquote) => {
filterTokens(
params,
"blockquote_open",
/** @type FilterTokensCallback */
(blockquote) => {
const lines = blockquote.map[1] - blockquote.map[0];
onError({
"lineNumber": blockquote.lineNumber,
"detail": "Blockquote spans " + lines + " line(s).",
"context": blockquote.line.substr(0, 7)
});
});
}
);
}
};

View file

@ -4,6 +4,7 @@
const { forEachLine, getLineMetadata } = require("markdownlint-rule-helpers");
/** @type import("../../lib/markdownlint").Rule */
module.exports = {
"names": [ "every-n-lines" ],
"description": "Rule that reports an error every N lines",

View file

@ -2,6 +2,7 @@
"use strict";
/** @type import("../../lib/markdownlint").Rule */
module.exports = {
"names": [ "first-line" ],
"description": "Rule that reports an error for the first line",

View file

@ -2,6 +2,7 @@
"use strict";
/** @type import("../../lib/markdownlint").Rule */
module.exports = {
"names": [ "letters-E-X", "letter-E-letter-X", "contains-ex" ],
"description": "Rule that reports an error for lines with the letters 'EX'",

View file

@ -24,6 +24,7 @@ function cleanJsdocRulesFromEslintConfig(config) {
return cleanedConfig;
}
/** @type import("../../lib/markdownlint").Rule */
module.exports = {
"names": [ "lint-javascript" ],
"description": "Rule that lints JavaScript code",

View file

@ -2,6 +2,7 @@
"use strict";
/** @type import("../../../lib/markdownlint").Rule */
module.exports = {
"names": [ "sample-rule" ],
"description": "Sample rule",

View file

@ -5,6 +5,7 @@
const { filterTokens } = require("markdownlint-rule-helpers");
const { parse, printParseErrorCode } = require("jsonc-parser");
/** @type import("../../lib/markdownlint").Rule */
module.exports = {
"names": [ "validate-json" ],
"description": "Rule that validates JSON code",