Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

remark-lint-no-literal-urls

Package Overview
Dependencies
Maintainers
3
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

remark-lint-no-literal-urls - npm Package Compare versions

Comparing version 3.1.2 to 4.0.0

index.d.ts.map

14

index.d.ts

@@ -1,7 +0,7 @@

export default remarkLintNoLiteralUrls
export type Root = import('mdast').Root
declare const remarkLintNoLiteralUrls: import('unified').Plugin<
void[] | [unknown],
import('mdast').Root,
import('mdast').Root
>
export default remarkLintNoLiteralUrls;
export type Root = import('mdast').Root;
declare const remarkLintNoLiteralUrls: {
(config?: unknown): ((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 GFM autolink literals are used.
*
* ## What is this?
*
* This package checks that regular autolinks or full links are used.
* Literal autolinks is a GFM feature enabled with
* [`remark-gfm`][github-remark-gfm].
*
* ## When should I use this?
*
* You can use this package to check that autolink literal URLs are not used.
* You can use this package to check that links are consistent.
*
* ## API
*
* ### `unified().use(remarkLintNoLiteralUrls)`
*
* Warn when GFM autolink literals are used.
*
* ###### Parameters
*
* There are no options.
*
* ###### Returns
*
* Transform ([`Transformer` from `unified`][github-unified-transformer]).
*
* ## Recommendation
*
* Autolink literal URLs (just a URL) are a feature enabled by GFM.
* GFM autolink literals (just a raw URL) are a feature enabled by GFM.
* They don’t work everywhere.
* Due to this, it’s recommended to instead use normal autolinks
* (`<https://url>`) or links (`[text](url)`).
* So,
* it’s recommended to instead use regular autolinks (`<https://url>`) or full
* links (`[text](url)`).
*
* ## Fix
*
* [`remark-stringify`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify)
* never creates autolink literals and always uses normal autolinks (`<url>`).
* [`remark-stringify`][github-remark-stringify] never generates GFM autolink
* literals.
* It always generates regular autolinks or full links.
*
* [api-remark-lint-no-literal-urls]: #unifieduseremarklintnoliteralurls
* [github-remark-gfm]: https://github.com/remarkjs/remark-gfm
* [github-remark-stringify]: https://github.com/remarkjs/remark/tree/main/packages/remark-stringify
* [github-unified-transformer]: https://github.com/unifiedjs/unified#transformer
*
* @module no-literal-urls
* @summary
* remark-lint rule to warn for autolink literals.
* @author Titus Wormer
* @copyright 2015 Titus Wormer
* @license MIT
*
* @example
* {"name": "ok.md"}
* {"name": "ok.md", "gfm": true}
*
* <http://foo.bar/baz>
* <https://example.com/mercury/>
*
* ![Venus](http://example.com/venus/).
*
* @example
* {"name": "not-ok.md", "label": "input", "gfm": true}
*
* http://foo.bar/baz
* https://example.com/mercury/
*
* www.example.com/venus/
*
* earth@mars.planets
*
* @example
* {"name": "not-ok.md", "label": "output", "gfm": true}
*
* 1:1-1:19: Don’t use literal URLs without angle brackets
* 1:1-1:29: Unexpected GFM autolink literal, expected regular autolink, add `<` before and `>` after
* 3:1-3:23: Unexpected GFM autolink literal, expected regular autolink, add `<http://` before and `>` after
* 5:1-5:19: Unexpected GFM autolink literal, expected regular autolink, add `<mailto:` before and `>` after
*/

@@ -48,8 +80,11 @@

import {toString} from 'mdast-util-to-string'
import {asciiPunctuation} from 'micromark-util-character'
import {lintRule} from 'unified-lint-rule'
import {visit} from 'unist-util-visit'
import {pointStart, pointEnd} from 'unist-util-position'
import {generated} from 'unist-util-generated'
import {toString} from 'mdast-util-to-string'
import {pointStart} from 'unist-util-position'
import {visitParents} from 'unist-util-visit-parents'
const defaultHttp = 'http://'
const defaultMailto = 'mailto:'
const remarkLintNoLiteralUrls = lintRule(

@@ -60,15 +95,42 @@ {

},
/** @type {import('unified-lint-rule').Rule<Root, void>} */
(tree, file) => {
visit(tree, 'link', (node) => {
const value = toString(node)
/**
* @param {Root} tree
* Tree.
* @returns {undefined}
* Nothing.
*/
function (tree, file) {
const value = String(file)
visitParents(tree, 'link', function (node, parents) {
const start = pointStart(node)
if (!start || typeof start.offset !== 'number') return
const raw = toString(node)
/** @type {string | undefined} */
let protocol
let otherwiseFine = false
if (raw === node.url) {
otherwiseFine = true
} else if (defaultHttp + raw === node.url) {
protocol = defaultHttp
} else if (defaultMailto + raw === node.url) {
protocol = defaultMailto
}
if (
!generated(node) &&
pointStart(node).column === pointStart(node.children[0]).column &&
pointEnd(node).column ===
pointEnd(node.children[node.children.length - 1]).column &&
(node.url === 'mailto:' + value || node.url === value)
// If the url is the same as the content…
(protocol || otherwiseFine) &&
// …and it doesn’t start with a marker.
!asciiPunctuation(value.charCodeAt(start.offset))
) {
file.message('Don’t use literal URLs without angle brackets', node)
file.message(
'Unexpected GFM autolink literal, expected regular autolink, add ' +
(protocol ? '`<' + protocol + '`' : '`<`') +
' before and `>` after',
{ancestors: [...parents, node], place: node.position}
)
}

@@ -75,0 +137,0 @@ })

{
"name": "remark-lint-no-literal-urls",
"version": "3.1.2",
"version": "4.0.0",
"description": "remark-lint rule to warn when URLs without angle brackets are used",
"license": "MIT",
"keywords": [
"lint",
"literal",
"remark",
"lint",
"remark-lint",
"remark-lint-rule",
"rule",
"remark-lint-rule",
"literal",
"url"
],
"repository": {
"type": "git",
"url": "https://github.com/remarkjs/remark-lint",
"directory": "packages/remark-lint-no-literal-urls"
},
"repository": "https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-no-literal-urls",
"bugs": "https://github.com/remarkjs/remark-lint/issues",

@@ -26,29 +23,36 @@ "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",
"mdast-util-to-string": "^3.0.0",
"unified": "^10.0.0",
"unified-lint-rule": "^2.0.0",
"unist-util-generated": "^2.0.0",
"unist-util-position": "^4.0.0",
"unist-util-visit": "^4.0.0"
"@types/mdast": "^4.0.0",
"mdast-util-to-string": "^4.0.0",
"micromark-util-character": "^2.0.0",
"unified-lint-rule": "^3.0.0",
"unist-util-position": "^5.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",
"unicorn/prefer-at": "off",
"unicorn/prefer-code-point": "off",
"unicorn/prefer-switch": "off"
}
}
}

@@ -5,43 +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 for autolink literals.
[`remark-lint`][github-remark-lint] rule to warn when GFM autolink literals are 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(remarkLintNoLiteralUrls[, config])`](#unifieduseremarklintnoliteralurls-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(remarkLintNoLiteralUrls)`](#unifieduseremarklintnoliteralurls)
* [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 that regular autolinks or full links are used.
Literal autolinks is a GFM feature enabled with
[`remark-gfm`][github-remark-gfm].
## When should I use this?
You can use this package to check that autolink literal URLs are not used.
You can use this package to check that links are consistent.
## Presets
This rule is included in the following presets:
This plugin is included in the following presets:
| Preset | Setting |
| Preset | Options |
| - | - |

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

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]:

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

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

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

```js
import remarkLint from 'remark-lint'
import remarkLintNoLiteralUrls from 'remark-lint-no-literal-urls'
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 remarkLintNoLiteralUrls from 'remark-lint-no-literal-urls'
main()
const file = await read('example.md')
async function main() {
const file = await remark()
.use(remarkLint)
.use(remarkLintNoLiteralUrls)
.process(await read('example.md'))
await unified()
.use(remarkParse)
.use(remarkLint)
.use(remarkLintNoLiteralUrls)
.use(remarkStringify)
.process(file)
console.error(reporter(file))
}
console.error(reporter(file))
```

@@ -103,3 +106,3 @@

```sh
remark --use remark-lint --use remark-lint-no-literal-urls example.md
remark --frail --use remark-lint --use remark-lint-no-literal-urls .
```

@@ -125,22 +128,31 @@

This package exports no identifiers.
The default export is `remarkLintNoLiteralUrls`.
It exports no additional [TypeScript][typescript] types.
The default export is
[`remarkLintNoLiteralUrls`][api-remark-lint-no-literal-urls].
### `unified().use(remarkLintNoLiteralUrls[, config])`
### `unified().use(remarkLintNoLiteralUrls)`
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 GFM autolink literals are used.
###### Parameters
There are no options.
###### Returns
Transform ([`Transformer` from `unified`][github-unified-transformer]).
## Recommendation
Autolink literal URLs (just a URL) are a feature enabled by GFM.
GFM autolink literals (just a raw URL) are a feature enabled by GFM.
They don’t work everywhere.
Due to this, it’s recommended to instead use normal autolinks
(`<https://url>`) or links (`[text](url)`).
So,
it’s recommended to instead use regular autolinks (`<https://url>`) or full
links (`[text](url)`).
## Fix
[`remark-stringify`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify)
never creates autolink literals and always uses normal autolinks (`<url>`).
[`remark-stringify`][github-remark-stringify] never generates GFM autolink
literals.
It always generates regular autolinks or full links.

@@ -153,4 +165,9 @@ ## Examples

> 👉 **Note**: this example uses
> GFM ([`remark-gfm`][github-remark-gfm]).
```markdown
<http://foo.bar/baz>
<https://example.com/mercury/>
![Venus](http://example.com/venus/).
```

@@ -166,6 +183,11 @@

> 👉 **Note**: this example uses GFM ([`remark-gfm`][gfm]).
> 👉 **Note**: this example uses
> GFM ([`remark-gfm`][github-remark-gfm]).
```markdown
http://foo.bar/baz
https://example.com/mercury/
www.example.com/venus/
earth@mars.planets
```

@@ -176,3 +198,5 @@

```text
1:1-1:19: Don’t use literal URLs without angle brackets
1:1-1:29: Unexpected GFM autolink literal, expected regular autolink, add `<` before and `>` after
3:1-3:23: Unexpected GFM autolink literal, expected regular autolink, add `<http://` before and `>` after
5:1-5:19: Unexpected GFM autolink literal, expected regular autolink, add `<mailto:` before and `>` after
```

@@ -182,14 +206,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-no-literal-urls@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

@@ -200,54 +228,58 @@ 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-remark-lint-no-literal-urls]: #unifieduseremarklintnoliteralurls
[build]: https://github.com/remarkjs/remark-lint/actions
[author]: https://wooorm.com
[coverage-badge]: https://img.shields.io/codecov/c/github/remarkjs/remark-lint.svg
[badge-build-image]: https://github.com/remarkjs/remark-lint/workflows/main/badge.svg
[coverage]: https://codecov.io/github/remarkjs/remark-lint
[badge-build-url]: https://github.com/remarkjs/remark-lint/actions
[downloads-badge]: https://img.shields.io/npm/dm/remark-lint-no-literal-urls.svg
[badge-chat-image]: https://img.shields.io/badge/chat-discussions-success.svg
[downloads]: https://www.npmjs.com/package/remark-lint-no-literal-urls
[badge-chat-url]: https://github.com/remarkjs/remark/discussions
[size-badge]: https://img.shields.io/bundlephobia/minzip/remark-lint-no-literal-urls.svg
[badge-coverage-image]: https://img.shields.io/codecov/c/github/remarkjs/remark-lint.svg
[size]: https://bundlephobia.com/result?p=remark-lint-no-literal-urls
[badge-coverage-url]: https://codecov.io/github/remarkjs/remark-lint
[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg
[badge-downloads-image]: https://img.shields.io/npm/dm/remark-lint-no-literal-urls.svg
[backers-badge]: https://opencollective.com/unified/backers/badge.svg
[badge-downloads-url]: https://www.npmjs.com/package/remark-lint-no-literal-urls
[collective]: https://opencollective.com/unified
[badge-funding-backers-image]: https://opencollective.com/unified/backers/badge.svg
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg
[badge-funding-sponsors-image]: https://opencollective.com/unified/sponsors/badge.svg
[chat]: https://github.com/remarkjs/remark/discussions
[badge-funding-url]: https://opencollective.com/unified
[unified]: https://github.com/unifiedjs/unified
[badge-size-image]: https://img.shields.io/bundlejs/size/remark-lint-no-literal-urls
[remark]: https://github.com/remarkjs/remark
[badge-size-url]: https://bundlejs.com/?q=remark-lint-no-literal-urls
[mono]: https://github.com/remarkjs/remark-lint
[esm-sh]: https://esm.sh
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
[file-license]: https://github.com/remarkjs/remark-lint/blob/main/license
[esmsh]: https://esm.sh
[github-dotfiles-coc]: https://github.com/remarkjs/.github/blob/main/code-of-conduct.md
[npm]: https://docs.npmjs.com/cli/install
[github-dotfiles-contributing]: https://github.com/remarkjs/.github/blob/main/contributing.md
[health]: https://github.com/remarkjs/.github
[github-dotfiles-health]: https://github.com/remarkjs/.github
[contributing]: https://github.com/remarkjs/.github/blob/main/contributing.md
[github-dotfiles-support]: https://github.com/remarkjs/.github/blob/main/support.md
[support]: https://github.com/remarkjs/.github/blob/main/support.md
[github-gist-esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
[coc]: https://github.com/remarkjs/.github/blob/main/code-of-conduct.md
[github-remark-gfm]: https://github.com/remarkjs/remark-gfm
[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
[gfm]: https://github.com/remarkjs/remark-gfm
[github-unified-transformer]: https://github.com/unifiedjs/unified#transformer
[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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc