Socket
Socket
Sign inDemoInstall

remark-lint-rule-style

Package Overview
Dependencies
17
Maintainers
3
Versions
13
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.1.2 to 4.0.0

index.d.ts.map

30

index.d.ts

@@ -1,23 +0,11 @@

export default remarkLintRuleStyle
export type Root = import('mdast').Root
export default remarkLintRuleStyle;
export type Root = import('mdast').Root;
/**
* Options.
* Configuration.
*/
export type Options = string
declare const remarkLintRuleStyle: import('unified').Plugin<
| void[]
| [
| string
| [
(
| boolean
| import('unified-lint-rule/lib/index.js').Label
| import('unified-lint-rule/lib/index.js').Severity
),
(string | undefined)?
]
| undefined
],
import('mdast').Root,
import('mdast').Root
>
export type Options = string;
declare const remarkLintRuleStyle: {
(config?: string | 0 | 1 | 2 | [level: import("../../node_modules/unified-lint-rule/lib/index.js").Label | import("../../node_modules/unified-lint-rule/lib/index.js").Severity, option?: string | null | undefined] | null | undefined): ((tree: import("mdast").Root, file: import("vfile").VFile, next: import("unified").TransformCallback<import("mdast").Root>) => undefined) | undefined;
readonly name: string;
};
//# sourceMappingURL=index.d.ts.map
/**
* remark-lint rule to warn when thematic breaks (horizontal rules) are
* inconsistent.
*
* ## What is this?
*
* This package checks markers and whitespace of thematic rules.
*
* ## When should I use this?
*
* You can use this package to check that rules (thematic breaks, horizontal
* rules) are consistent.
* You can use this package to check that thematic breaks are consistent.
*
* ## API
*
* The following options (default: `'consistent'`) are accepted:
* ### `unified().use(remarkLintRuleStyle[, options])`
*
* * `string` (example: `'** * **'`, `'___'`)
* β€” thematic break to prefer
* * `'consistent'`
* β€” detect the first used style and warn when further rules differ
* Warn when thematic breaks (horizontal rules) are inconsistent.
*
* ###### Parameters
*
* * `options` ([`Options`][api-options], default: `'consistent'`)
* β€” preferred style or whether to detect the first style and warn for
* further differences
*
* ### `Options`
*
* Configuration (TypeScript type).
*
* * `'consistent'`
* β€” detect the first used style and warn when further rules differ
* * `string` (example: `'** * **'`, `'___'`)
* β€” thematic break to prefer
*
* ###### Type
*
* ```ts
* type Options = string | 'consistent'
* ```
*
* ## Recommendation
*
* Rules consist of a `*`, `-`, or `_` character, which occurs at least three
* times with nothing else except for arbitrary spaces or tabs on a single line.
* Using spaces, tabs, and more than three markers seems unnecessary work to
* type out.
* Because asterisks can be used as a marker for more markdown constructs,
* Rules consist of a `*`, `-`, or `_` character,
* which occurs at least three times with nothing else except for arbitrary
* spaces or tabs on a single line.
* Using spaces, tabs, or more than three markers is unnecessary work to type
* out.
* As asterisks can be used as a marker for more markdown constructs,
* it’s recommended to use that for rules (and lists, emphasis, strong) too.
* Due to this, it’s recommended to pass `'***'`.
* So it’s recommended to pass `'***'`.
*
* ## Fix
*
* [`remark-stringify`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify)
* formats rules with `***` by default.
* [`remark-stringify`][github-remark-stringify] formats rules with `***` by
* default.
* There are three settings to control rules:
*
* * [`rule`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#optionsrule)
* (default: `'*'`) β€” marker
* * [`ruleRepetition`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#optionsrulerepetition)
* (default: `3`) β€” repetitions
* * [`ruleSpaces`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#optionsrulespaces)
* (default: `false`) β€” use spaces between markers
* * `rule` (default: `'*'`) β€” marker
* * `ruleRepetition` (default: `3`) β€” repetitions
* * `ruleSpaces` (default: `false`) β€” use spaces between markers
*
* [api-options]: #options
* [api-remark-lint-rule-style]: #unifieduseremarklintrulestyle-options
* [github-remark-stringify]: https://github.com/remarkjs/remark/tree/main/packages/remark-stringify
* [github-unified-transformer]: https://github.com/unifiedjs/unified#transformer
*
* @module rule-style
* @summary
* remark-lint rule to warn when rule markers are inconsistent.
* @author Titus Wormer
* @copyright 2015 Titus Wormer
* @license MIT
*
* @example
* {"name": "ok.md", "config": "* * *"}
* {"name": "ok.md"}
*
* Two rules:
*
* * * *

@@ -53,3 +81,3 @@ *

* @example
* {"name": "ok.md", "config": "_______"}
* {"config": "_______", "name": "ok.md"}
*

@@ -61,3 +89,3 @@ * _______

* @example
* {"name": "not-ok.md", "label": "input"}
* {"label": "input", "name": "not-ok.md"}
*

@@ -67,12 +95,11 @@ * ***

* * * *
*
* @example
* {"name": "not-ok.md", "label": "output"}
* {"label": "output", "name": "not-ok.md"}
*
* 3:1-3:6: Rules should use `***`
* 3:1-3:6: Unexpected thematic rule `* * *`, expected `***`
*
* @example
* {"name": "not-ok.md", "label": "output", "config": "πŸ’©", "positionless": true}
* {"config": "🌍", "label": "output", "name": "not-ok.md", "positionless": true}
*
* 1:1: Incorrect preferred rule style: provide a correct markdown rule or `'consistent'`
* 1:1: Unexpected value `🌍` for `options`, expected thematic rule or `'consistent'`
*/

@@ -86,8 +113,10 @@

* @typedef {string} Options
* Options.
* Configuration.
*/
import {phrasing} from 'mdast-util-phrasing'
import {lintRule} from 'unified-lint-rule'
import {visit} from 'unist-util-visit'
import {pointStart, pointEnd} from 'unist-util-position'
import {pointEnd, pointStart} from 'unist-util-position'
import {SKIP, visitParents} from 'unist-util-visit-parents'
import {VFileMessage} from 'vfile-message'

@@ -99,23 +128,78 @@ const remarkLintRuleStyle = lintRule(

},
/** @type {import('unified-lint-rule').Rule<Root, Options>} */
(tree, file, option = 'consistent') => {
/**
* @param {Root} tree
* Tree.
* @param {Options | null | undefined} [options='consistent']
* Configuration (default: `'consistent'`).
* @returns {undefined}
* Nothing.
*/
function (tree, file, options) {
const value = String(file)
/** @type {string | undefined} */
let expected
/** @type {VFileMessage | undefined} */
let cause
if (option !== 'consistent' && /[^-_* ]/.test(option)) {
if (options === null || options === undefined || options === 'consistent') {
// Empty.
} else if (
/[^-_* ]/.test(options) ||
options.at(0) === ' ' ||
options.at(-1) === ' ' ||
options.replaceAll(' ', '').length < 3
) {
file.fail(
"Incorrect preferred rule style: provide a correct markdown rule or `'consistent'`"
'Unexpected value `' +
options +
"` for `options`, expected thematic rule or `'consistent'`"
)
} else {
expected = options
}
visit(tree, 'thematicBreak', (node) => {
const initial = pointStart(node).offset
const final = pointEnd(node).offset
visitParents(tree, function (node, parents) {
// Do not walk into phrasing.
if (phrasing(node)) {
return SKIP
}
if (typeof initial === 'number' && typeof final === 'number') {
const rule = value.slice(initial, final)
if (node.type !== 'thematicBreak') return
if (option === 'consistent') {
option = rule
} else if (rule !== option) {
file.message('Rules should use `' + option + '`', node)
const end = pointEnd(node)
const start = pointStart(node)
if (
start &&
end &&
typeof start.offset === 'number' &&
typeof end.offset === 'number'
) {
const place = {start, end}
const actual = value.slice(start.offset, end.offset)
if (expected) {
if (actual !== expected) {
file.message(
'Unexpected thematic rule `' +
actual +
'`, expected `' +
expected +
'`',
{ancestors: [...parents, node], cause, place}
)
}
} else {
expected = actual
cause = new VFileMessage(
'Thematic rule style `' +
expected +
"` first defined for `'consistent'` here",
{
ancestors: [...parents, node],
place,
ruleId: 'rule-style',
source: 'remark-lint'
}
)
}

@@ -122,0 +206,0 @@ }

{
"name": "remark-lint-rule-style",
"version": "3.1.2",
"version": "4.0.0",
"description": "remark-lint rule to warn when horizontal rules violate a given style",
"license": "MIT",
"keywords": [
"break",
"horizontal",
"lint",
"remark",
"lint",
"remark-lint",
"remark-lint-rule",
"rule",
"remark-lint-rule",
"horizontal",
"thematic",
"break"
"thematic"
],
"repository": {
"type": "git",
"url": "https://github.com/remarkjs/remark-lint",
"directory": "packages/remark-lint-rule-style"
},
"repository": "https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-rule-style",
"bugs": "https://github.com/remarkjs/remark-lint/issues",

@@ -27,27 +24,33 @@ "funding": {

"contributors": [
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
"Titus Wormer <tituswormer@gmail.com>"
],
"sideEffects": false,
"type": "module",
"main": "index.js",
"types": "index.d.ts",
"exports": "./index.js",
"files": [
"index.d.ts",
"index.d.ts.map",
"index.js"
],
"dependencies": {
"@types/mdast": "^3.0.0",
"unified": "^10.0.0",
"unified-lint-rule": "^2.0.0",
"unist-util-position": "^4.0.0",
"unist-util-visit": "^4.0.0"
"@types/mdast": "^4.0.0",
"mdast-util-phrasing": "^4.0.0",
"unified-lint-rule": "^3.0.0",
"unist-util-position": "^5.0.0",
"unist-util-visit-parents": "^6.0.0",
"vfile-message": "^4.0.0"
},
"scripts": {},
"xo": false,
"typeCoverage": {
"atLeast": 100,
"detail": true,
"strict": true,
"ignoreCatch": true
"ignoreCatch": true,
"strict": true
},
"xo": {
"prettier": true,
"rules": {
"capitalized-comments": "off"
}
}
}

@@ -5,44 +5,43 @@ <!--This file is generated-->

[![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]
[![Build][badge-build-image]][badge-build-url]
[![Coverage][badge-coverage-image]][badge-coverage-url]
[![Downloads][badge-downloads-image]][badge-downloads-url]
[![Size][badge-size-image]][badge-size-url]
[![Sponsors][badge-funding-sponsors-image]][badge-funding-url]
[![Backers][badge-funding-backers-image]][badge-funding-url]
[![Chat][badge-chat-image]][badge-chat-url]
[`remark-lint`][mono] rule to warn when rule markers are inconsistent.
[`remark-lint`][github-remark-lint] rule to warn when thematic breaks (horizontal rules) are
inconsistent.
## Contents
* [What is this?](#what-is-this)
* [When should I use this?](#when-should-i-use-this)
* [Presets](#presets)
* [Install](#install)
* [Use](#use)
* [API](#api)
* [`unified().use(remarkLintRuleStyle[, config])`](#unifieduseremarklintrulestyle-config)
* [Recommendation](#recommendation)
* [Fix](#fix)
* [Examples](#examples)
* [Compatibility](#compatibility)
* [Contribute](#contribute)
* [License](#license)
* [What is this?](#what-is-this)
* [When should I use this?](#when-should-i-use-this)
* [Presets](#presets)
* [Install](#install)
* [Use](#use)
* [API](#api)
* [`unified().use(remarkLintRuleStyle[, options])`](#unifieduseremarklintrulestyle-options)
* [`Options`](#options)
* [Recommendation](#recommendation)
* [Fix](#fix)
* [Examples](#examples)
* [Compatibility](#compatibility)
* [Contribute](#contribute)
* [License](#license)
## What is this?
This package is a [unified][] ([remark][]) plugin, specifically a `remark-lint`
rule.
Lint rules check markdown code style.
This package checks markers and whitespace of thematic rules.
## When should I use this?
You can use this package to check that rules (thematic breaks, horizontal
rules) are consistent.
You can use this package to check that thematic breaks are consistent.
## Presets
This rule is included in the following presets:
This plugin is included in the following presets:
| Preset | Setting |
| Preset | Options |
| - | - |

@@ -54,4 +53,5 @@ | [`remark-preset-lint-consistent`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-preset-lint-consistent) | `'consistent'` |

This package is [ESM only][esm].
In Node.js (version 12.20+, 14.14+, or 16.0+), install with [npm][]:
This package is [ESM only][github-gist-esm].
In Node.js (version 16+),
install with [npm][npm-install]:

@@ -62,13 +62,13 @@ ```sh

In Deno with [`esm.sh`][esmsh]:
In Deno with [`esm.sh`][esm-sh]:
```js
import remarkLintRuleStyle from 'https://esm.sh/remark-lint-rule-style@3'
import remarkLintRuleStyle from 'https://esm.sh/remark-lint-rule-style@4'
```
In browsers with [`esm.sh`][esmsh]:
In browsers with [`esm.sh`][esm-sh]:
```html
<script type="module">
import remarkLintRuleStyle from 'https://esm.sh/remark-lint-rule-style@3?bundle'
import remarkLintRuleStyle from 'https://esm.sh/remark-lint-rule-style@4?bundle'
</script>

@@ -82,18 +82,20 @@ ```

```js
import remarkLint from 'remark-lint'
import remarkLintRuleStyle from 'remark-lint-rule-style'
import remarkParse from 'remark-parse'
import remarkStringify from 'remark-stringify'
import {read} from 'to-vfile'
import {unified} from 'unified'
import {reporter} from 'vfile-reporter'
import {remark} from 'remark'
import remarkLint from 'remark-lint'
import remarkLintRuleStyle from 'remark-lint-rule-style'
main()
const file = await read('example.md')
async function main() {
const file = await remark()
.use(remarkLint)
.use(remarkLintRuleStyle)
.process(await read('example.md'))
await unified()
.use(remarkParse)
.use(remarkLint)
.use(remarkLintRuleStyle)
.use(remarkStringify)
.process(file)
console.error(reporter(file))
}
console.error(reporter(file))
```

@@ -104,3 +106,3 @@

```sh
remark --use remark-lint --use remark-lint-rule-style example.md
remark --frail --use remark-lint --use remark-lint-rule-style .
```

@@ -126,38 +128,52 @@

This package exports no identifiers.
The default export is `remarkLintRuleStyle`.
It exports the [TypeScript][typescript] type
[`Options`][api-options].
The default export is
[`remarkLintRuleStyle`][api-remark-lint-rule-style].
### `unified().use(remarkLintRuleStyle[, config])`
### `unified().use(remarkLintRuleStyle[, options])`
This rule supports standard configuration that all remark lint rules accept
(such as `false` to turn it off or `[1, options]` to configure it).
Warn when thematic breaks (horizontal rules) are inconsistent.
The following options (default: `'consistent'`) are accepted:
###### Parameters
* `string` (example: `'** * **'`, `'___'`)
β€” thematic break to prefer
* `'consistent'`
β€” detect the first used style and warn when further rules differ
* `options` ([`Options`][api-options], default: `'consistent'`)
β€” preferred style or whether to detect the first style and warn for
further differences
### `Options`
Configuration (TypeScript type).
* `'consistent'`
β€” detect the first used style and warn when further rules differ
* `string` (example: `'** * **'`, `'___'`)
β€” thematic break to prefer
###### Type
```ts
type Options = string | 'consistent'
```
## Recommendation
Rules consist of a `*`, `-`, or `_` character, which occurs at least three
times with nothing else except for arbitrary spaces or tabs on a single line.
Using spaces, tabs, and more than three markers seems unnecessary work to
type out.
Because asterisks can be used as a marker for more markdown constructs,
Rules consist of a `*`, `-`, or `_` character,
which occurs at least three times with nothing else except for arbitrary
spaces or tabs on a single line.
Using spaces, tabs, or more than three markers is unnecessary work to type
out.
As asterisks can be used as a marker for more markdown constructs,
it’s recommended to use that for rules (and lists, emphasis, strong) too.
Due to this, it’s recommended to pass `'***'`.
So it’s recommended to pass `'***'`.
## Fix
[`remark-stringify`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify)
formats rules with `***` by default.
[`remark-stringify`][github-remark-stringify] formats rules with `***` by
default.
There are three settings to control rules:
* [`rule`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#optionsrule)
(default: `'*'`) β€” marker
* [`ruleRepetition`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#optionsrulerepetition)
(default: `3`) β€” repetitions
* [`ruleSpaces`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#optionsrulespaces)
(default: `false`) β€” use spaces between markers
* `rule` (default: `'*'`) β€” marker
* `ruleRepetition` (default: `3`) β€” repetitions
* `ruleSpaces` (default: `false`) β€” use spaces between markers

@@ -168,7 +184,7 @@ ## Examples

When configured with `'* * *'`.
###### In
```markdown
Two rules:
* * *

@@ -212,3 +228,3 @@

```text
3:1-3:6: Rules should use `***`
3:1-3:6: Unexpected thematic rule `* * *`, expected `***`
```

@@ -218,3 +234,3 @@

When configured with `'πŸ’©'`.
When configured with `'🌍'`.

@@ -224,3 +240,3 @@ ###### Out

```text
1:1: Incorrect preferred rule style: provide a correct markdown rule or `'consistent'`
1:1: Unexpected value `🌍` for `options`, expected thematic rule or `'consistent'`
```

@@ -230,14 +246,18 @@

Projects maintained by the unified collective are compatible with all maintained
Projects maintained by the unified collective are compatible with maintained
versions of Node.js.
As of now, that is Node.js 12.20+, 14.14+, and 16.0+.
Our projects sometimes work with older versions, but this is not guaranteed.
When we cut a new major release, we drop support for unmaintained versions of
Node.
This means we try to keep the current release line,
`remark-lint-rule-style@4`,
compatible with Node.js 16.
## Contribute
See [`contributing.md`][contributing] in [`remarkjs/.github`][health] for ways
See [`contributing.md`][github-dotfiles-contributing] in [`remarkjs/.github`][github-dotfiles-health] for ways
to get started.
See [`support.md`][support] for ways to get help.
See [`support.md`][github-dotfiles-support] for ways to get help.
This project has a [code of conduct][coc].
This project has a [code of conduct][github-dotfiles-coc].
By interacting with this repository, organization, or community you agree to

@@ -248,52 +268,56 @@ abide by its terms.

[MIT][license] Β© [Titus Wormer][author]
[MIT][file-license] Β© [Titus Wormer][author]
[build-badge]: https://github.com/remarkjs/remark-lint/workflows/main/badge.svg
[api-options]: #options
[build]: https://github.com/remarkjs/remark-lint/actions
[api-remark-lint-rule-style]: #unifieduseremarklintrulestyle-options
[coverage-badge]: https://img.shields.io/codecov/c/github/remarkjs/remark-lint.svg
[author]: https://wooorm.com
[coverage]: https://codecov.io/github/remarkjs/remark-lint
[badge-build-image]: https://github.com/remarkjs/remark-lint/workflows/main/badge.svg
[downloads-badge]: https://img.shields.io/npm/dm/remark-lint-rule-style.svg
[badge-build-url]: https://github.com/remarkjs/remark-lint/actions
[downloads]: https://www.npmjs.com/package/remark-lint-rule-style
[badge-chat-image]: https://img.shields.io/badge/chat-discussions-success.svg
[size-badge]: https://img.shields.io/bundlephobia/minzip/remark-lint-rule-style.svg
[badge-chat-url]: https://github.com/remarkjs/remark/discussions
[size]: https://bundlephobia.com/result?p=remark-lint-rule-style
[badge-coverage-image]: https://img.shields.io/codecov/c/github/remarkjs/remark-lint.svg
[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg
[badge-coverage-url]: https://codecov.io/github/remarkjs/remark-lint
[backers-badge]: https://opencollective.com/unified/backers/badge.svg
[badge-downloads-image]: https://img.shields.io/npm/dm/remark-lint-rule-style.svg
[collective]: https://opencollective.com/unified
[badge-downloads-url]: https://www.npmjs.com/package/remark-lint-rule-style
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg
[badge-funding-backers-image]: https://opencollective.com/unified/backers/badge.svg
[chat]: https://github.com/remarkjs/remark/discussions
[badge-funding-sponsors-image]: https://opencollective.com/unified/sponsors/badge.svg
[unified]: https://github.com/unifiedjs/unified
[badge-funding-url]: https://opencollective.com/unified
[remark]: https://github.com/remarkjs/remark
[badge-size-image]: https://img.shields.io/bundlejs/size/remark-lint-rule-style
[mono]: https://github.com/remarkjs/remark-lint
[badge-size-url]: https://bundlejs.com/?q=remark-lint-rule-style
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
[esm-sh]: https://esm.sh
[esmsh]: https://esm.sh
[file-license]: https://github.com/remarkjs/remark-lint/blob/main/license
[npm]: https://docs.npmjs.com/cli/install
[github-dotfiles-coc]: https://github.com/remarkjs/.github/blob/main/code-of-conduct.md
[health]: https://github.com/remarkjs/.github
[github-dotfiles-contributing]: https://github.com/remarkjs/.github/blob/main/contributing.md
[contributing]: https://github.com/remarkjs/.github/blob/main/contributing.md
[github-dotfiles-health]: https://github.com/remarkjs/.github
[support]: https://github.com/remarkjs/.github/blob/main/support.md
[github-dotfiles-support]: https://github.com/remarkjs/.github/blob/main/support.md
[coc]: https://github.com/remarkjs/.github/blob/main/code-of-conduct.md
[github-gist-esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
[license]: https://github.com/remarkjs/remark-lint/blob/main/license
[github-remark-lint]: https://github.com/remarkjs/remark-lint
[author]: https://wooorm.com
[github-remark-stringify]: https://github.com/remarkjs/remark/tree/main/packages/remark-stringify
[npm-install]: https://docs.npmjs.com/cli/install
[typescript]: https://www.typescriptlang.org
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚑️ by Socket Inc