remark-lint-no-heading-punctuation
Advanced tools
+17
| export default remarkLintNoHeadingPunctuation | ||
| export type Root = import('mdast').Root | ||
| export type Options = string | ||
| declare const remarkLintNoHeadingPunctuation: import('unified-lint-rule/node_modules/unified').Plugin< | ||
| | void[] | ||
| | [string | 0 | 1 | 2 | undefined] | ||
| | [ | ||
| ( | ||
| | boolean | ||
| | import('unified-lint-rule').Label | ||
| | import('unified-lint-rule').Severity | ||
| ), | ||
| string | undefined | ||
| ], | ||
| import('mdast').Root, | ||
| import('mdast').Root | ||
| > |
+31
-32
@@ -14,11 +14,14 @@ /** | ||
| * | ||
| * @example {"name": "ok.md"} | ||
| * @example | ||
| * {"name": "ok.md"} | ||
| * | ||
| * # Hello | ||
| * | ||
| * @example {"name": "ok.md", "setting": ",;:!?"} | ||
| * @example | ||
| * {"name": "ok.md", "setting": ",;:!?"} | ||
| * | ||
| * # Hello… | ||
| * | ||
| * @example {"name": "not-ok.md", "label": "input"} | ||
| * @example | ||
| * {"name": "not-ok.md", "label": "input"} | ||
| * | ||
@@ -35,3 +38,4 @@ * # Hello: | ||
| * | ||
| * @example {"name": "not-ok.md", "label": "output"} | ||
| * @example | ||
| * {"name": "not-ok.md", "label": "output"} | ||
| * | ||
@@ -45,36 +49,31 @@ * 1:1-1:9: Don’t add a trailing `:` to headings | ||
| 'use strict' | ||
| /** | ||
| * @typedef {import('mdast').Root} Root | ||
| * @typedef {string} Options | ||
| */ | ||
| var rule = require('unified-lint-rule') | ||
| var visit = require('unist-util-visit') | ||
| var generated = require('unist-util-generated') | ||
| var toString = require('mdast-util-to-string') | ||
| import {lintRule} from 'unified-lint-rule' | ||
| import {visit} from 'unist-util-visit' | ||
| import {generated} from 'unist-util-generated' | ||
| import {toString} from 'mdast-util-to-string' | ||
| module.exports = rule( | ||
| const remarkLintNoHeadingPunctuation = lintRule( | ||
| 'remark-lint:no-heading-punctuation', | ||
| noHeadingPunctuation | ||
| ) | ||
| /** @type {import('unified-lint-rule').Rule<Root, Options>} */ | ||
| (tree, file, option = '\\.,;:!?') => { | ||
| const expression = new RegExp('[' + option + ']') | ||
| var defaults = '\\.,;:!?' | ||
| visit(tree, 'heading', (node) => { | ||
| if (!generated(node)) { | ||
| const value = toString(node) | ||
| const tail = value.charAt(value.length - 1) | ||
| function noHeadingPunctuation(tree, file, option) { | ||
| var expression = new RegExp( | ||
| '[' + (typeof option === 'string' ? option : defaults) + ']' | ||
| ) | ||
| visit(tree, 'heading', visitor) | ||
| function visitor(node) { | ||
| var value | ||
| var tail | ||
| if (!generated(node)) { | ||
| value = toString(node) | ||
| tail = value.charAt(value.length - 1) | ||
| if (expression.test(tail)) { | ||
| file.message('Don’t add a trailing `' + tail + '` to headings', node) | ||
| if (expression.test(tail)) { | ||
| file.message('Don’t add a trailing `' + tail + '` to headings', node) | ||
| } | ||
| } | ||
| } | ||
| }) | ||
| } | ||
| } | ||
| ) | ||
| export default remarkLintNoHeadingPunctuation |
+22
-6
| { | ||
| "name": "remark-lint-no-heading-punctuation", | ||
| "version": "2.0.1", | ||
| "version": "3.0.0", | ||
| "description": "remark-lint rule to warn when headings end in illegal characters", | ||
@@ -24,12 +24,28 @@ "license": "MIT", | ||
| ], | ||
| "sideEffects": false, | ||
| "type": "module", | ||
| "main": "index.js", | ||
| "types": "index.d.ts", | ||
| "files": [ | ||
| "index.d.ts", | ||
| "index.js" | ||
| ], | ||
| "dependencies": { | ||
| "unified-lint-rule": "^1.0.0", | ||
| "mdast-util-to-string": "^1.0.2", | ||
| "unist-util-generated": "^1.1.0", | ||
| "unist-util-visit": "^2.0.0" | ||
| "@types/mdast": "^3.0.0", | ||
| "mdast-util-to-string": "^3.0.0", | ||
| "unified": "^10.0.0", | ||
| "unified-lint-rule": "^2.0.0", | ||
| "unist-util-generated": "^2.0.0", | ||
| "unist-util-visit": "^4.0.0" | ||
| }, | ||
| "xo": false | ||
| "scripts": { | ||
| "build": "rimraf \"*.d.ts\" && tsc && type-coverage" | ||
| }, | ||
| "xo": false, | ||
| "typeCoverage": { | ||
| "atLeast": 100, | ||
| "detail": true, | ||
| "strict": true, | ||
| "ignoreCatch": true | ||
| } | ||
| } |
+21
-10
@@ -84,2 +84,5 @@ <!--This file is generated--> | ||
| This package is [ESM only][esm]: | ||
| Node 12+ is needed to use it and it must be `imported`ed instead of `required`d. | ||
| [npm][]: | ||
@@ -91,2 +94,5 @@ | ||
| This package exports no identifiers. | ||
| The default export is `remarkLintNoHeadingPunctuation`. | ||
| ## Use | ||
@@ -118,10 +124,13 @@ | ||
| ```diff | ||
| var remark = require('remark') | ||
| var report = require('vfile-reporter') | ||
| import {remark} from 'remark' | ||
| import {reporter} from 'vfile-reporter' | ||
| import remarkLint from 'remark-lint' | ||
| import remarkLintNoHeadingPunctuation from 'remark-lint-no-heading-punctuation' | ||
| remark() | ||
| .use(require('remark-lint')) | ||
| + .use(require('remark-lint-no-heading-punctuation')) | ||
| .process('_Emphasis_ and **importance**', function (err, file) { | ||
| console.error(report(err || file)) | ||
| .use(remarkLint) | ||
| + .use(remarkLintNoHeadingPunctuation) | ||
| .process('_Emphasis_ and **importance**') | ||
| .then((file) => { | ||
| console.error(reporter(file)) | ||
| }) | ||
@@ -144,5 +153,5 @@ ``` | ||
| [build-badge]: https://img.shields.io/travis/remarkjs/remark-lint/main.svg | ||
| [build-badge]: https://github.com/remarkjs/remark-lint/workflows/main/badge.svg | ||
| [build]: https://travis-ci.org/remarkjs/remark-lint | ||
| [build]: https://github.com/remarkjs/remark-lint/actions | ||
@@ -167,6 +176,8 @@ [coverage-badge]: https://img.shields.io/codecov/c/github/remarkjs/remark-lint.svg | ||
| [chat-badge]: https://img.shields.io/badge/chat-spectrum.svg | ||
| [chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg | ||
| [chat]: https://spectrum.chat/unified/remark | ||
| [chat]: https://github.com/remarkjs/remark/discussions | ||
| [esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c | ||
| [npm]: https://docs.npmjs.com/cli/install | ||
@@ -173,0 +184,0 @@ |
7730
20.72%4
33.33%87
27.94%191
6.11%Yes
NaN6
50%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
Updated
Updated
Updated
Updated