Skip to content

Commit

Permalink
Incorporate markdownlint-rule-extended-ascii into tests, linting, and…
Browse files Browse the repository at this point in the history
… documentation.
  • Loading branch information
DavidAnson committed May 14, 2024
1 parent 4a1b355 commit 22f1f06
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 15 deletions.
3 changes: 3 additions & 0 deletions .markdownlint.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
"emphasis-style": {
"style": "asterisk"
},
"extended-ascii": {
"ascii-only": true
},
"fenced-code-language": {
"allowed_languages": [
"bash",
Expand Down
13 changes: 7 additions & 6 deletions doc/CustomRules.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 6 additions & 2 deletions test/markdownlint-test-custom-rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,16 +343,20 @@ 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
};
markdownlint(options, function callback(err, actualResult) {
t.falsy(err);
const expectedResult = {};
expectedResult.string = {
"extended-ascii": [ 5 ],
"sample-rule": [ 3 ]
};
// @ts-ignore
Expand Down
44 changes: 37 additions & 7 deletions test/markdownlint-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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 = {
Expand Down

0 comments on commit 22f1f06

Please sign in to comment.