remark-lint/packages/remark-lint-no-inline-padding/index.js
2023-12-13 16:54:41 +01:00

74 lines
1.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* Deprecated.
*
* ## API
*
* to do: remove.
*
* [api-remark-lint-no-inline-padding]: #api
*
* @module no-inline-padding
* @author Titus Wormer
* @copyright 2015 Titus Wormer
* @license MIT
* @deprecated
* **Stability: Legacy**.
* This rule is no longer recommended for use.
* With CommonMark, inlines can no longer be padded.
* Otherwise they dont parse.
*
* @example
* {"name": "ok.md"}
*
* Alpha [bravo](http://echo.fox/trot)
*
* @example
* {"name": "not-ok.md", "label": "input"}
*
* Alpha [ bravo ](http://echo.fox/trot)
*
* @example
* {"name": "not-ok.md", "label": "output"}
*
* 1:7-1:38: Dont pad `link` with inner spaces
*/
/**
* @typedef {import('mdast').Root} Root
*/
import {toString} from 'mdast-util-to-string'
import {lintRule} from 'unified-lint-rule'
import {position} from 'unist-util-position'
import {visit} from 'unist-util-visit'
const remarkLintNoInlinePadding = lintRule(
{
origin: 'remark-lint:no-inline-padding',
url: 'https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-no-inline-padding#readme'
},
/**
* @param {Root} tree
* Tree.
* @returns {undefined}
* Nothing.
*/
function (tree, file) {
// Note: `emphasis`, `strong`, `delete` (GFM) cant have padding anymore
// since CM.
visit(tree, function (node) {
const place = position(node)
if ((node.type === 'link' || node.type === 'linkReference') && place) {
const value = toString(node)
if (value.charAt(0) === ' ' || value.charAt(value.length - 1) === ' ') {
file.message('Dont pad `' + node.type + '` with inner spaces', place)
}
}
})
}
)
export default remarkLintNoInlinePadding