mirror of
https://github.com/remarkjs/remark-lint.git
synced 2024-09-11 19:57:15 +03:00
Add remark-lint-strikethrough-marker
Closes GH-259. Closes GH-260. Reviewed-by: Christian Murphy <christian.murphy.42@gmail.com> Reviewed-by: Titus Wormer <tituswormer@gmail.com>
This commit is contained in:
parent
718e94d758
commit
06b11893b0
@ -132,6 +132,7 @@ Rules][external].
|
||||
* [`ordered-list-marker-style`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-ordered-list-marker-style) — warn when the markers of ordered lists violate a given style
|
||||
* [`ordered-list-marker-value`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-ordered-list-marker-value) — warn when the marker value of ordered lists violates a given style
|
||||
* [`rule-style`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-rule-style) — warn when horizontal rules violate a given style
|
||||
* [`strikethrough-marker`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-strikethrough-marker) — warn when strikethrough markers violate the given style
|
||||
* [`strong-marker`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-strong-marker) — warn when importance (strong) markers violate the given style
|
||||
* [`table-cell-padding`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-table-cell-padding) — warn when table cells are incorrectly padded
|
||||
* [`table-pipe-alignment`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-table-pipe-alignment) — warn when table pipes are not aligned
|
||||
|
@ -28,7 +28,8 @@
|
||||
"David Clark <dclark@mapbox.com>",
|
||||
"Саша Черных <SashaChernykhEmpressOfUniverse@kristinita.ru>",
|
||||
"Bob “Wombat” Hogg <wombat@rwhogg.site>",
|
||||
"David Chambers <dc@davidchambers.me>"
|
||||
"David Chambers <dc@davidchambers.me>",
|
||||
"Denis Augsburger <denis.augsburger@simpleen.io> (https://simpleen.io)"
|
||||
],
|
||||
"devDependencies": {
|
||||
"browserify": "^17.0.0",
|
||||
|
105
packages/remark-lint-strikethrough-marker/index.js
Normal file
105
packages/remark-lint-strikethrough-marker/index.js
Normal file
@ -0,0 +1,105 @@
|
||||
/**
|
||||
* @author Denis Augsburger
|
||||
* @copyright 2021 Denis Augsburger
|
||||
* @license MIT
|
||||
* @module strikethrough-marker
|
||||
* @fileoverview
|
||||
* Warn for violating strikethrough markers.
|
||||
*
|
||||
* Options: `'consistent'`, `'~'`, or `'~~'`, default: `'consistent'`.
|
||||
*
|
||||
* `'consistent'` detects the first used strikethrough style and warns when
|
||||
* subsequent strikethrough use different styles.
|
||||
*
|
||||
* ## Fix
|
||||
*
|
||||
* See [Using remark to fix your Markdown](https://github.com/remarkjs/remark-lint#using-remark-to-fix-your-markdown)
|
||||
* on how to automatically fix warnings for this rule.
|
||||
*
|
||||
* @example {"setting": "~", "name": "ok.md", "gfm": true}
|
||||
*
|
||||
* ~foo~
|
||||
*
|
||||
* @example {"setting": "~", "name": "not-ok.md", "label": "input", "gfm": true}
|
||||
*
|
||||
* ~~foo~~
|
||||
*
|
||||
* @example {"setting": "~", "name": "not-ok.md", "label": "output", "gfm": true}
|
||||
*
|
||||
* 1:1-1:8: Strikethrough should use `~` as a marker
|
||||
*
|
||||
* @example {"setting": "~~", "name": "ok.md", "gfm": true}
|
||||
*
|
||||
* ~~foo~~
|
||||
*
|
||||
* @example {"setting": "~~", "name": "not-ok.md", "label": "input", "gfm": true}
|
||||
*
|
||||
* ~foo~
|
||||
*
|
||||
* @example {"setting": "~~", "name": "not-ok.md", "label": "output", "gfm": true}
|
||||
*
|
||||
* 1:1-1:6: Strikethrough should use `~~` as a marker
|
||||
*
|
||||
* @example {"name": "not-ok.md", "label": "input", "gfm": true}
|
||||
*
|
||||
* ~~foo~~
|
||||
* ~bar~
|
||||
*
|
||||
* @example {"name": "not-ok.md", "label": "output", "gfm": true}
|
||||
*
|
||||
* 2:1-2:6: Strikethrough should use `~~` as a marker
|
||||
*
|
||||
* @example {"setting": "💩", "name": "not-ok.md", "label": "output", "positionless": true, "gfm": true}
|
||||
*
|
||||
* 1:1: Incorrect strikethrough marker `💩`: use either `'consistent'`, `'~'`, or `'~~'`
|
||||
*/
|
||||
|
||||
'use strict'
|
||||
|
||||
var rule = require('unified-lint-rule')
|
||||
var visit = require('unist-util-visit')
|
||||
var position = require('unist-util-position')
|
||||
var generated = require('unist-util-generated')
|
||||
|
||||
module.exports = rule('remark-lint:strikethrough-marker', strikethroughMarker)
|
||||
|
||||
var markers = {null: true, '~': true, '~~': true}
|
||||
|
||||
function strikethroughMarker(tree, file, option) {
|
||||
var contents = String(file)
|
||||
var preferred =
|
||||
typeof option === 'string' && option !== 'consistent' ? option : null
|
||||
|
||||
if (markers[preferred] !== true) {
|
||||
file.fail(
|
||||
'Incorrect strikethrough marker `' +
|
||||
preferred +
|
||||
"`: use either `'consistent'`, `'~'`, or `'~~'`"
|
||||
)
|
||||
}
|
||||
|
||||
visit(tree, 'delete', visitor)
|
||||
|
||||
function visitor(node) {
|
||||
var marker
|
||||
|
||||
if (!generated(node)) {
|
||||
var offset = position.start(node).offset
|
||||
marker =
|
||||
contents.slice(offset, offset + 2) === '~~'
|
||||
? contents.slice(offset, offset + 2)
|
||||
: contents.slice(offset, offset + 1)
|
||||
|
||||
if (preferred) {
|
||||
if (marker !== preferred) {
|
||||
file.message(
|
||||
'Strikethrough should use `' + preferred + '` as a marker',
|
||||
node
|
||||
)
|
||||
}
|
||||
} else {
|
||||
preferred = marker
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
35
packages/remark-lint-strikethrough-marker/package.json
Normal file
35
packages/remark-lint-strikethrough-marker/package.json
Normal file
@ -0,0 +1,35 @@
|
||||
{
|
||||
"name": "remark-lint-strikethrough-marker",
|
||||
"version": "2.0.1",
|
||||
"description": "remark-lint rule to warn when strikethrough markers violate the given style",
|
||||
"license": "MIT",
|
||||
"keywords": [
|
||||
"remark",
|
||||
"lint",
|
||||
"rule",
|
||||
"remark-lint-rule",
|
||||
"strikethrough",
|
||||
"marker"
|
||||
],
|
||||
"repository": "https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-strikethrough-marker",
|
||||
"bugs": "https://github.com/remarkjs/remark-lint/issues",
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/unified"
|
||||
},
|
||||
"author": "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)",
|
||||
"contributors": [
|
||||
"Denis Augsburger <denis.augsburger@simpleen.io> (https://simpleen.io)",
|
||||
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
|
||||
],
|
||||
"files": [
|
||||
"index.js"
|
||||
],
|
||||
"dependencies": {
|
||||
"unified-lint-rule": "^1.0.0",
|
||||
"unist-util-generated": "^1.1.0",
|
||||
"unist-util-position": "^3.0.0",
|
||||
"unist-util-visit": "^2.0.0"
|
||||
},
|
||||
"xo": false
|
||||
}
|
225
packages/remark-lint-strikethrough-marker/readme.md
Normal file
225
packages/remark-lint-strikethrough-marker/readme.md
Normal file
@ -0,0 +1,225 @@
|
||||
<!--This file is generated-->
|
||||
|
||||
# remark-lint-strikethrough-marker
|
||||
|
||||
[![Build][build-badge]][build]
|
||||
[![Coverage][coverage-badge]][coverage]
|
||||
[![Downloads][downloads-badge]][downloads]
|
||||
[![Size][size-badge]][size]
|
||||
[![Sponsors][sponsors-badge]][collective]
|
||||
[![Backers][backers-badge]][collective]
|
||||
[![Chat][chat-badge]][chat]
|
||||
|
||||
Warn for violating strikethrough markers.
|
||||
|
||||
Options: `'consistent'`, `'~'`, or `'~~'`, default: `'consistent'`.
|
||||
|
||||
`'consistent'` detects the first used strikethrough style and warns when
|
||||
subsequent strikethrough use different styles.
|
||||
|
||||
## Fix
|
||||
|
||||
See [Using remark to fix your Markdown](https://github.com/remarkjs/remark-lint#using-remark-to-fix-your-markdown)
|
||||
on how to automatically fix warnings for this rule.
|
||||
|
||||
## Presets
|
||||
|
||||
This rule is not included in any default preset
|
||||
|
||||
## Example
|
||||
|
||||
##### `ok.md`
|
||||
|
||||
When configured with `'~'`.
|
||||
|
||||
###### In
|
||||
|
||||
Note: this example uses [GFM][].
|
||||
|
||||
```markdown
|
||||
~foo~
|
||||
```
|
||||
|
||||
###### Out
|
||||
|
||||
No messages.
|
||||
|
||||
##### `not-ok.md`
|
||||
|
||||
When configured with `'~'`.
|
||||
|
||||
###### In
|
||||
|
||||
Note: this example uses [GFM][].
|
||||
|
||||
```markdown
|
||||
~~foo~~
|
||||
```
|
||||
|
||||
###### Out
|
||||
|
||||
```text
|
||||
1:1-1:8: Strikethrough should use `~` as a marker
|
||||
```
|
||||
|
||||
##### `ok.md`
|
||||
|
||||
When configured with `'~~'`.
|
||||
|
||||
###### In
|
||||
|
||||
Note: this example uses [GFM][].
|
||||
|
||||
```markdown
|
||||
~~foo~~
|
||||
```
|
||||
|
||||
###### Out
|
||||
|
||||
No messages.
|
||||
|
||||
##### `not-ok.md`
|
||||
|
||||
When configured with `'~~'`.
|
||||
|
||||
###### In
|
||||
|
||||
Note: this example uses [GFM][].
|
||||
|
||||
```markdown
|
||||
~foo~
|
||||
```
|
||||
|
||||
###### Out
|
||||
|
||||
```text
|
||||
1:1-1:6: Strikethrough should use `~~` as a marker
|
||||
```
|
||||
|
||||
##### `not-ok.md`
|
||||
|
||||
###### In
|
||||
|
||||
Note: this example uses [GFM][].
|
||||
|
||||
```markdown
|
||||
~~foo~~
|
||||
~bar~
|
||||
```
|
||||
|
||||
###### Out
|
||||
|
||||
```text
|
||||
2:1-2:6: Strikethrough should use `~~` as a marker
|
||||
```
|
||||
|
||||
##### `not-ok.md`
|
||||
|
||||
When configured with `'💩'`.
|
||||
|
||||
###### Out
|
||||
|
||||
```text
|
||||
1:1: Incorrect strikethrough marker `💩`: use either `'consistent'`, `'~'`, or `'~~'`
|
||||
```
|
||||
|
||||
## Install
|
||||
|
||||
[npm][]:
|
||||
|
||||
```sh
|
||||
npm install remark-lint-strikethrough-marker
|
||||
```
|
||||
|
||||
## Use
|
||||
|
||||
You probably want to use it on the CLI through a config file:
|
||||
|
||||
```diff
|
||||
…
|
||||
"remarkConfig": {
|
||||
"plugins": [
|
||||
…
|
||||
"lint",
|
||||
+ "lint-strikethrough-marker",
|
||||
…
|
||||
]
|
||||
}
|
||||
…
|
||||
```
|
||||
|
||||
Or use it on the CLI directly
|
||||
|
||||
```sh
|
||||
remark -u lint -u lint-strikethrough-marker readme.md
|
||||
```
|
||||
|
||||
Or use this on the API:
|
||||
|
||||
```diff
|
||||
var remark = require('remark')
|
||||
var report = require('vfile-reporter')
|
||||
|
||||
remark()
|
||||
.use(require('remark-lint'))
|
||||
+ .use(require('remark-lint-strikethrough-marker'))
|
||||
.process('_Emphasis_ and **importance**', function (err, file) {
|
||||
console.error(report(err || file))
|
||||
})
|
||||
```
|
||||
|
||||
## Contribute
|
||||
|
||||
See [`contributing.md`][contributing] in [`remarkjs/.github`][health] for ways
|
||||
to get started.
|
||||
See [`support.md`][support] for ways to get help.
|
||||
|
||||
This project has a [code of conduct][coc].
|
||||
By interacting with this repository, organization, or community you agree to
|
||||
abide by its terms.
|
||||
|
||||
## License
|
||||
|
||||
[MIT][license] © [Titus Wormer][author]
|
||||
|
||||
[build-badge]: https://github.com/remarkjs/remark-lint/workflows/main/badge.svg
|
||||
|
||||
[build]: https://github.com/remarkjs/remark-lint/actions
|
||||
|
||||
[coverage-badge]: https://img.shields.io/codecov/c/github/remarkjs/remark-lint.svg
|
||||
|
||||
[coverage]: https://codecov.io/github/remarkjs/remark-lint
|
||||
|
||||
[downloads-badge]: https://img.shields.io/npm/dm/remark-lint-strikethrough-marker.svg
|
||||
|
||||
[downloads]: https://www.npmjs.com/package/remark-lint-strikethrough-marker
|
||||
|
||||
[size-badge]: https://img.shields.io/bundlephobia/minzip/remark-lint-strikethrough-marker.svg
|
||||
|
||||
[size]: https://bundlephobia.com/result?p=remark-lint-strikethrough-marker
|
||||
|
||||
[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg
|
||||
|
||||
[backers-badge]: https://opencollective.com/unified/backers/badge.svg
|
||||
|
||||
[collective]: https://opencollective.com/unified
|
||||
|
||||
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg
|
||||
|
||||
[chat]: https://github.com/remarkjs/remark/discussions
|
||||
|
||||
[npm]: https://docs.npmjs.com/cli/install
|
||||
|
||||
[health]: https://github.com/remarkjs/.github
|
||||
|
||||
[contributing]: https://github.com/remarkjs/.github/blob/HEAD/contributing.md
|
||||
|
||||
[support]: https://github.com/remarkjs/.github/blob/HEAD/support.md
|
||||
|
||||
[coc]: https://github.com/remarkjs/.github/blob/HEAD/code-of-conduct.md
|
||||
|
||||
[license]: https://github.com/remarkjs/remark-lint/blob/main/license
|
||||
|
||||
[author]: https://wooorm.com
|
||||
|
||||
[gfm]: https://github.com/remarkjs/remark-gfm
|
Loading…
Reference in New Issue
Block a user