1.0.1 • Published 5 months ago

remark-lint-directive-quote-style v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

remark-lint-directive-quote-style

Build Coverage Downloads Size Sponsors Backers Chat

remark-lint rule to warn when directive attribute value markers violate a given style.

Contents

What is this?

This package checks the style of directive attribute value markers.

When should I use this?

You can use this package to check that the style of directive attribute value markers is consistent.

Presets

This plugin is not included in presets maintained here.

Install

This package is ESM only. In Node.js (version 16+), install with npm:

npm install remark-lint-directive-quote-style

In Deno with esm.sh:

import remarkLintDirectiveQuoteStyle, {inferAttributes} from 'https://esm.sh/remark-lint-directive-quote-style@1'

In browsers with esm.sh:

<script type="module">
  import remarkLintDirectiveQuoteStyle, {inferAttributes} from 'https://esm.sh/remark-lint-directive-quote-style@1?bundle'
</script>

Use

On the API:

import remarkLint from 'remark-lint'
import remarkLintDirectiveQuoteStyle from 'remark-lint-directive-quote-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'

const file = await read('example.md')

await unified()
  .use(remarkParse)
  .use(remarkLint)
  .use(remarkLintDirectiveQuoteStyle)
  .use(remarkStringify)
  .process(file)

console.error(reporter(file))

On the CLI:

remark --frail --use remark-lint --use remark-lint-directive-quote-style .

On the CLI in a config file (here a package.json):

 …
 "remarkConfig": {
   "plugins": [
     …
     "remark-lint",
+    "remark-lint-directive-quote-style",
     …
   ]
 }
 …

API

This package exports the identifier inferAttributes. It exports the TypeScript types Attribute, Options, Style, and Token. The default export is remarkLintDirectiveQuoteStyle.

inferAttributes(node, document)

Internal API to get offsets of where attributes occur. Shared with other lint rules to work with attributes.

Parameters
Returns

Array<Attribute>.

unified().use(remarkLintDirectiveQuoteStyle[, options])

Warn when directive attribute value markers violate a given style.

Parameters
  • options (Options, default: 'consistent') — configuration
Returns

Transform (Transformer from unified).

Attribute

Internal attribute tokens (TypeScript type).

Type
export interface Attribute {
  key: Token
  value: Token | undefined
}

Options

Configuration (TypeScript type).

Properties
  • allowUnquoted (boolean, default: true) — whether to allow unquoted attributes; otherwise attribute values must be quoted
  • quote (Style or 'consistent', default: 'consistent') — quote

Style

Style (TypeScript type).

Type
type Style = '"' | '\''

Token

Info on an internal token (TypeScript type).

Type
type Token = [value: string, start: number, end: number]

Recommendation

In HTML, attributes are commonly written with double quotes. It’s recommended to go with that. To configure this rule with '"'.

Fix

remark-directive typically formats attributes with double quotes. It can be passed several options to influence which quote it uses. The options quote and quoteSmart can be used together with this lint rule.

Examples

ok-consistent.md
In

👉 Note: this example uses directives (remark-directive).

:planet[Venus]{aphelion="0.728213" perihelion="0.718440" symbol=♀︎}
Out

No messages.

not-ok-consistent.md
In

👉 Note: this example uses directives (remark-directive).

:planet[Venus]{aphelion="0.728213" perihelion='0.718440' symbol=♀︎}
Out
1:47-1:57: Unexpected directive attribute quote markers `'`, expected `"`
double-quote.md

When configured with '"'.

In

👉 Note: this example uses directives (remark-directive).

:planet[Venus]{aphelion="0.728213" perihelion='0.718440' symbol=♀︎}
Out
1:47-1:57: Unexpected directive attribute quote markers `'`, expected `"`
single-quote.md

When configured with "'".

In

👉 Note: this example uses directives (remark-directive).

:planet[Venus]{aphelion="0.728213" perihelion='0.718440' symbol=♀︎}
Out
1:25-1:35: Unexpected directive attribute quote markers `"`, expected `'`
other-attributes.md

When configured with '"'.

In

👉 Note: this example uses directives (remark-directive).

:planet[Jupiter]{#jupiter.fifth.gas-giant symbol=♃ .zeus}
Out

No messages.

whitespace.md

When configured with '"'.

In

👉 Note: this example uses directives (remark-directive).

:planet[Mars]{ aphelion = "249261000" perihelion = '206650000' symbol = ♂ }.
Out
1:52-1:63: Unexpected directive attribute quote markers `'`, expected `"`
text-directive.md

When configured with '"'.

In

👉 Note: this example uses directives (remark-directive).

:planet{}

:planet[Venus]{aphelion="0.728213" perihelion='0.718440'}

:planet{symbol='♂'}

:planet[]
Out
3:47-3:57: Unexpected directive attribute quote markers `'`, expected `"`
5:16-5:19: Unexpected directive attribute quote markers `'`, expected `"`
leaf-directive.md

When configured with '"'.

In

👉 Note: this example uses directives (remark-directive).

::planet{}

::planet[Venus]{aphelion="0.728213" perihelion='0.718440'}

::planet{symbol='♂'}

::planet[]
Out
3:48-3:58: Unexpected directive attribute quote markers `'`, expected `"`
5:17-5:20: Unexpected directive attribute quote markers `'`, expected `"`
container-directive.md

When configured with '"'.

In

👉 Note: this example uses directives (remark-directive).

:::planet{}
:::

:::planet[Venus]{aphelion="0.728213" perihelion='0.718440'}
:::

:::planet{symbol='♃'}
Jupiter
:::

:::planet{symbol='🜨'}
:::

:::planet[]
:::
Out
4:49-4:59: Unexpected directive attribute quote markers `'`, expected `"`
7:18-7:21: Unexpected directive attribute quote markers `'`, expected `"`
11:18-11:22: Unexpected directive attribute quote markers `'`, expected `"`
allow-unquoted.md

When configured with { allowUnquoted: false }.

In

👉 Note: this example uses directives (remark-directive).

:planet[Venus]{aphelion=0.728213}

:planet[Mars]{aphelion="249261000" symbol=♂}.
Out
1:25-1:33: Unexpected unquoted directive attribute, expected quote around value
3:43-3:44: Unexpected unquoted directive attribute, expected `"` around value
not-ok.md

When configured with '🌍'.

Out
1:1: Unexpected value `🌍` for `options`, expected `'"'`, `"'"`, or `'consistent'`

Compatibility

Projects maintained by the unified collective are compatible with maintained versions of Node.js.

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-directive-quote-style@1, compatible with Node.js 16.

Contribute

See contributing.md in remarkjs/.github for ways to get started. See support.md for ways to get help.

This project has a code of conduct. By interacting with this repository, organization, or community you agree to abide by its terms.

License

MIT © Titus Wormer