remark-lint-no-html
Advanced tools
Comparing version
@@ -1,7 +0,16 @@ | ||
export default remarkLintNoHtml | ||
export type Root = import('mdast').Root | ||
declare const remarkLintNoHtml: import('unified').Plugin< | ||
void[] | [unknown], | ||
import('mdast').Root, | ||
import('mdast').Root | ||
> | ||
export default remarkLintNoHtml; | ||
export type Root = import('mdast').Root; | ||
/** | ||
* Configuration. | ||
*/ | ||
export type Options = { | ||
/** | ||
* Allow comments or not (default: `true`). | ||
*/ | ||
allowComments?: boolean | null | undefined; | ||
}; | ||
declare const remarkLintNoHtml: { | ||
(config?: import("../../node_modules/unified-lint-rule/lib/index.js").Label | import("../../node_modules/unified-lint-rule/lib/index.js").Severity | Readonly<Options> | [level: import("../../node_modules/unified-lint-rule/lib/index.js").Label | import("../../node_modules/unified-lint-rule/lib/index.js").Severity, option?: Readonly<Options> | 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 |
96
index.js
/** | ||
* remark-lint rule to warn when HTML is used. | ||
* | ||
* ## What is this? | ||
* | ||
* This package checks HTML. | ||
* | ||
* ## When should I use this? | ||
* | ||
* You can use this package to check that no HTML (other than comments) is used. | ||
* You can use this package to check that no HTML is used. | ||
* | ||
* ## API | ||
* | ||
* There are no options. | ||
* ### `unified().use(remarkLintNoHtml[, options])` | ||
* | ||
* Warn when HTML is used. | ||
* | ||
* ###### Parameters | ||
* | ||
* * `options` ([`Options`][api-options], optional) | ||
* — configuration | ||
* | ||
* ###### Returns | ||
* | ||
* Transform ([`Transformer` from `unified`][github-unified-transformer]). | ||
* | ||
* ### `Options` | ||
* | ||
* Configuration (TypeScript type). | ||
* | ||
* ###### Fields | ||
* | ||
* * `allowComments` (`boolean`, default: `true`) | ||
* — allow comments or not | ||
* | ||
* [api-options]: #options | ||
* [api-remark-lint-no-html]: #unifieduseremarklintnohtml-options | ||
* [github-unified-transformer]: https://github.com/unifiedjs/unified#transformer | ||
* | ||
* @module no-html | ||
* @summary | ||
* remark-lint rule to warn when HTML is used. | ||
* @author Titus Wormer | ||
@@ -20,15 +48,23 @@ * @copyright 2015 Titus Wormer | ||
* | ||
* # Hello | ||
* # Mercury | ||
* | ||
* <!--Comments are also OK--> | ||
* <!--Venus--> | ||
* | ||
* @example | ||
* {"name": "not-ok.md", "label": "input"} | ||
* {"label": "input", "name": "not-ok.md"} | ||
* | ||
* <h1>Hello</h1> | ||
* <h1>Mercury</h1> | ||
* @example | ||
* {"label": "output", "name": "not-ok.md"} | ||
* | ||
* 1:1-1:17: Unexpected HTML, use markdown instead | ||
* | ||
* @example | ||
* {"name": "not-ok.md", "label": "output"} | ||
* {"config": {"allowComments": false}, "label": "input", "name": "not-ok.md"} | ||
* | ||
* 1:1-1:15: Do not use HTML in markdown | ||
* <!--Mercury--> | ||
* @example | ||
* {"config": {"allowComments": false}, "label": "output", "name": "not-ok.md"} | ||
* | ||
* 1:1-1:15: Unexpected HTML, use markdown instead | ||
*/ | ||
@@ -40,5 +76,11 @@ | ||
/** | ||
* @typedef Options | ||
* Configuration. | ||
* @property {boolean | null | undefined} [allowComments=true] | ||
* Allow comments or not (default: `true`). | ||
*/ | ||
import {lintRule} from 'unified-lint-rule' | ||
import {visit} from 'unist-util-visit' | ||
import {generated} from 'unist-util-generated' | ||
import {visitParents} from 'unist-util-visit-parents' | ||
@@ -50,8 +92,26 @@ const remarkLintNoHtml = lintRule( | ||
}, | ||
/** @type {import('unified-lint-rule').Rule<Root, void>} */ | ||
(tree, file) => { | ||
visit(tree, 'html', (node) => { | ||
if (!generated(node) && !/^\s*<!--/.test(node.value)) { | ||
file.message('Do not use HTML in markdown', node) | ||
} | ||
/** | ||
* @param {Root} tree | ||
* Tree. | ||
* @param {Readonly<Options> | null | undefined} [options] | ||
* Configuration (optional). | ||
* @returns {undefined} | ||
* Nothing. | ||
*/ | ||
function (tree, file, options) { | ||
let allowComments = true | ||
if (options && typeof options.allowComments === 'boolean') { | ||
allowComments = options.allowComments | ||
} | ||
visitParents(tree, 'html', function (node, parents) { | ||
if (!node.position) return | ||
if (allowComments && /^[\t ]*<!--/.test(node.value)) return | ||
file.message('Unexpected HTML, use markdown instead', { | ||
ancestors: [...parents, node], | ||
place: node.position | ||
}) | ||
}) | ||
@@ -58,0 +118,0 @@ } |
{ | ||
"name": "remark-lint-no-html", | ||
"version": "3.1.2", | ||
"version": "4.0.0", | ||
"description": "remark-lint rule to warn when HTML nodes are used", | ||
"license": "MIT", | ||
"keywords": [ | ||
"html", | ||
"lint", | ||
"remark", | ||
"lint", | ||
"rule", | ||
"remark-lint", | ||
"remark-lint-rule", | ||
"html" | ||
"rule" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/remarkjs/remark-lint", | ||
"directory": "packages/remark-lint-no-html" | ||
}, | ||
"repository": "https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-no-html", | ||
"bugs": "https://github.com/remarkjs/remark-lint/issues", | ||
@@ -25,27 +22,30 @@ "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-generated": "^2.0.0", | ||
"unist-util-visit": "^4.0.0" | ||
"@types/mdast": "^4.0.0", | ||
"unified-lint-rule": "^3.0.0", | ||
"unist-util-visit-parents": "^6.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" | ||
} | ||
} | ||
} |
210
readme.md
@@ -5,44 +5,44 @@ <!--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 HTML is used. | ||
[`remark-lint`][github-remark-lint] rule to warn when HTML is used. | ||
## 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(remarkLintNoHtml[, config])`](#unifieduseremarklintnohtml-config) | ||
* [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(remarkLintNoHtml[, options])`](#unifieduseremarklintnohtml-options) | ||
* [`Options`](#options) | ||
* [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 HTML. | ||
## When should I use this? | ||
You can use this package to check that no HTML (other than comments) is used. | ||
You can use this package to check that no HTML is used. | ||
## Presets | ||
This rule is not included in a preset maintained here. | ||
This plugin is not included in presets maintained here. | ||
## Install | ||
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]: | ||
@@ -53,13 +53,13 @@ ```sh | ||
In Deno with [`esm.sh`][esmsh]: | ||
In Deno with [`esm.sh`][esm-sh]: | ||
```js | ||
import remarkLintNoHtml from 'https://esm.sh/remark-lint-no-html@3' | ||
import remarkLintNoHtml from 'https://esm.sh/remark-lint-no-html@4' | ||
``` | ||
In browsers with [`esm.sh`][esmsh]: | ||
In browsers with [`esm.sh`][esm-sh]: | ||
```html | ||
<script type="module"> | ||
import remarkLintNoHtml from 'https://esm.sh/remark-lint-no-html@3?bundle' | ||
import remarkLintNoHtml from 'https://esm.sh/remark-lint-no-html@4?bundle' | ||
</script> | ||
@@ -73,18 +73,20 @@ ``` | ||
```js | ||
import remarkLint from 'remark-lint' | ||
import remarkLintNoHtml from 'remark-lint-no-html' | ||
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 remarkLintNoHtml from 'remark-lint-no-html' | ||
main() | ||
const file = await read('example.md') | ||
async function main() { | ||
const file = await remark() | ||
.use(remarkLint) | ||
.use(remarkLintNoHtml) | ||
.process(await read('example.md')) | ||
await unified() | ||
.use(remarkParse) | ||
.use(remarkLint) | ||
.use(remarkLintNoHtml) | ||
.use(remarkStringify) | ||
.process(file) | ||
console.error(reporter(file)) | ||
} | ||
console.error(reporter(file)) | ||
``` | ||
@@ -95,3 +97,3 @@ | ||
```sh | ||
remark --use remark-lint --use remark-lint-no-html example.md | ||
remark --frail --use remark-lint --use remark-lint-no-html . | ||
``` | ||
@@ -117,11 +119,29 @@ | ||
This package exports no identifiers. | ||
The default export is `remarkLintNoHtml`. | ||
It exports the [TypeScript][typescript] type | ||
[`Options`][api-options]. | ||
The default export is | ||
[`remarkLintNoHtml`][api-remark-lint-no-html]. | ||
### `unified().use(remarkLintNoHtml[, config])` | ||
### `unified().use(remarkLintNoHtml[, 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 HTML is used. | ||
There are no options. | ||
###### Parameters | ||
* `options` ([`Options`][api-options], optional) | ||
— configuration | ||
###### Returns | ||
Transform ([`Transformer` from `unified`][github-unified-transformer]). | ||
### `Options` | ||
Configuration (TypeScript type). | ||
###### Fields | ||
* `allowComments` (`boolean`, default: `true`) | ||
— allow comments or not | ||
## Examples | ||
@@ -134,5 +154,5 @@ | ||
```markdown | ||
# Hello | ||
# Mercury | ||
<!--Comments are also OK--> | ||
<!--Venus--> | ||
``` | ||
@@ -149,3 +169,3 @@ | ||
```markdown | ||
<h1>Hello</h1> | ||
<h1>Mercury</h1> | ||
``` | ||
@@ -156,19 +176,39 @@ | ||
```text | ||
1:1-1:15: Do not use HTML in markdown | ||
1:1-1:17: Unexpected HTML, use markdown instead | ||
``` | ||
##### `not-ok.md` | ||
When configured with `{ allowComments: false }`. | ||
###### In | ||
```markdown | ||
<!--Mercury--> | ||
``` | ||
###### Out | ||
```text | ||
1:1-1:15: Unexpected HTML, use markdown instead | ||
``` | ||
## Compatibility | ||
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-no-html@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 | ||
@@ -179,52 +219,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-no-html]: #unifieduseremarklintnohtml-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-no-html.svg | ||
[badge-build-url]: https://github.com/remarkjs/remark-lint/actions | ||
[downloads]: https://www.npmjs.com/package/remark-lint-no-html | ||
[badge-chat-image]: https://img.shields.io/badge/chat-discussions-success.svg | ||
[size-badge]: https://img.shields.io/bundlephobia/minzip/remark-lint-no-html.svg | ||
[badge-chat-url]: https://github.com/remarkjs/remark/discussions | ||
[size]: https://bundlephobia.com/result?p=remark-lint-no-html | ||
[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-no-html.svg | ||
[collective]: https://opencollective.com/unified | ||
[badge-downloads-url]: https://www.npmjs.com/package/remark-lint-no-html | ||
[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-no-html | ||
[mono]: https://github.com/remarkjs/remark-lint | ||
[badge-size-url]: https://bundlejs.com/?q=remark-lint-no-html | ||
[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-unified-transformer]: https://github.com/unifiedjs/unified#transformer | ||
[npm-install]: https://docs.npmjs.com/cli/install | ||
[typescript]: https://www.typescriptlang.org |
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
10783
43.72%3
-40%5
25%125
104.92%266
19.82%1
Infinity%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
Updated
Updated