From 22f1f064fdb5442e08aeb601cf8a2ec3f13182f3 Mon Sep 17 00:00:00 2001 From: David Anson Date: Mon, 13 May 2024 22:57:47 -0700 Subject: [PATCH] Incorporate markdownlint-rule-extended-ascii into tests, linting, and documentation. --- .markdownlint.json | 3 ++ doc/CustomRules.md | 13 ++++---- package.json | 1 + test/markdownlint-test-custom-rules.js | 8 +++-- test/markdownlint-test.js | 44 ++++++++++++++++++++++---- 5 files changed, 54 insertions(+), 15 deletions(-) diff --git a/.markdownlint.json b/.markdownlint.json index c6b8b1ea..8de265a1 100644 --- a/.markdownlint.json +++ b/.markdownlint.json @@ -8,6 +8,9 @@ "emphasis-style": { "style": "asterisk" }, + "extended-ascii": { + "ascii-only": true + }, "fenced-code-language": { "allowed_languages": [ "bash", diff --git a/doc/CustomRules.md b/doc/CustomRules.md index c7366d55..2a5d1221 100644 --- a/doc/CustomRules.md +++ b/doc/CustomRules.md @@ -1,11 +1,13 @@ # Custom Rules In addition to its built-in rules, `markdownlint` lets you enhance the linting -experience by passing a list of custom rules using the [`options.customRules` +experience by passing an array of custom rules using the [`options.customRules` property][options-custom-rules]. Custom rules can do everything the built-in rules can and are defined inline or imported from another package ([keyword -`markdownlint-rule` on npm][markdownlint-rule]). Custom rules can be disabled, -enabled, and customized using the same syntax as built-in rules. +`markdownlint-rule` on npm][markdownlint-rule]). When defined by a file or +package, the export can be a single rule object (see below) or an array of them. +Custom rules can be disabled, enabled, and customized using the same syntax as +built-in rules. ## Implementing Simple Rules @@ -129,8 +131,7 @@ exception. - [Simple rules used by the project's test cases][test-rules] - [Code for all `markdownlint` built-in rules][lib] -- [Package configuration for publishing to npm][test-rules-npm] - - Packages should export a single rule object or an `Array` of rule objects +- [Complete example rule including npm configuration][extended-ascii] - [Custom rules from the webhintio/hint repository][hint] ## References @@ -372,6 +373,7 @@ Yields the `params` object: ``` [commonmark]: https://commonmark.org/ +[extended-ascii]: https://github.com/DavidAnson/markdownlint-rule-extended-ascii [hint]: https://github.com/webhintio/hint/blob/main/scripts/lint-markdown.js [lib]: ../lib [markdown-it]: https://github.com/markdown-it/markdown-it @@ -380,4 +382,3 @@ Yields the `params` object: [rule-helpers]: https://www.npmjs.com/package/markdownlint-rule-helpers [options-custom-rules]: ../README.md#optionscustomrules [test-rules]: ../test/rules -[test-rules-npm]: ../test/rules/npm diff --git a/package.json b/package.json index d111d1d4..656a1b4f 100644 --- a/package.json +++ b/package.json @@ -87,6 +87,7 @@ "markdown-it-for-inline": "2.0.1", "markdown-it-sub": "2.0.0", "markdown-it-sup": "2.0.0", + "markdownlint-rule-extended-ascii": "0.1.0", "npm-run-all": "4.1.5", "terser-webpack-plugin": "5.3.10", "toml": "3.0.0", diff --git a/test/markdownlint-test-custom-rules.js b/test/markdownlint-test-custom-rules.js index a4a527eb..e3cb1117 100644 --- a/test/markdownlint-test-custom-rules.js +++ b/test/markdownlint-test-custom-rules.js @@ -343,9 +343,12 @@ test("customRulesNpmPackage", (t) => new Promise((resolve) => { // eslint-disable-next-line jsdoc/valid-types /** @type import("../lib/markdownlint").Options */ const options = { - "customRules": [ require("./rules/npm") ], + "customRules": [ + require("./rules/npm"), + require("markdownlint-rule-extended-ascii") + ], "strings": { - "string": "# Text\n\n---\n\nText\n" + "string": "# Text\n\n---\n\nText ✅\n" }, "resultVersion": 0 }; @@ -353,6 +356,7 @@ test("customRulesNpmPackage", (t) => new Promise((resolve) => { t.falsy(err); const expectedResult = {}; expectedResult.string = { + "extended-ascii": [ 5 ], "sample-rule": [ 3 ] }; // @ts-ignore diff --git a/test/markdownlint-test.js b/test/markdownlint-test.js index 159d4b6d..7fb9ab37 100644 --- a/test/markdownlint-test.js +++ b/test/markdownlint-test.js @@ -73,16 +73,18 @@ test("simplePromise", (t) => { }); }); +const projectFiles = [ + "*.md", + "doc/*.md", + "helpers/*.md", + "micromark/*.md", + "schema/*.md" +]; + test("projectFiles", (t) => { t.plan(2); return import("globby") - .then((module) => module.globby([ - "*.md", - "doc/*.md", - "helpers/*.md", - "micromark/*.md", - "schema/*.md" - ])) + .then((module) => module.globby(projectFiles)) .then((files) => { t.is(files.length, 60); const options = { @@ -100,6 +102,34 @@ test("projectFiles", (t) => { }); }); +test("projectFilesExtendedAscii", (t) => { + t.plan(2); + return import("globby") + .then((module) => module.globby([ + ...projectFiles, + "!doc/Rules.md", + "!doc/md010.md", + "!doc/md026.md", + "!doc/md036.md" + ])) + .then((files) => { + t.is(files.length, 56); + const options = { + files, + "config": require("../.markdownlint.json"), + "customRules": [ require("markdownlint-rule-extended-ascii") ] + }; + // @ts-ignore + return markdownlint.promises.markdownlint(options).then((actual) => { + const expected = {}; + for (const file of files) { + expected[file] = []; + } + t.deepEqual(actual, expected, "Issue(s) with project files."); + }); + }); +}); + test("stringInputLineEndings", (t) => new Promise((resolve) => { t.plan(2); const options = {