🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

remark-lint-no-reference-like-url

Package Overview
Dependencies
Maintainers
2
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

remark-lint-no-reference-like-url - npm Package Compare versions

Comparing version

to
3.0.0

index.d.ts

77

index.js

@@ -9,3 +9,4 @@ /**

*
* @example {"name": "ok.md"}
* @example
* {"name": "ok.md"}
*

@@ -16,3 +17,4 @@ * [Alpha](http://example.com).

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

@@ -23,3 +25,4 @@ * [Charlie](delta).

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

@@ -29,40 +32,42 @@ * 1:1-1:17: Did you mean to use `[delta]` instead of `(delta)`, a reference?

'use strict'
/**
* @typedef {import('mdast').Root} Root
*/
var rule = require('unified-lint-rule')
var generated = require('unist-util-generated')
var visit = require('unist-util-visit')
import {lintRule} from 'unified-lint-rule'
import {generated} from 'unist-util-generated'
import {visit} from 'unist-util-visit'
module.exports = rule('remark-lint:no-reference-like-url', noReferenceLikeURL)
const remarkLintNoReferenceLikeUrl = lintRule(
'remark-lint:no-reference-like-url',
/** @type {import('unified-lint-rule').Rule<Root, void>} */
(tree, file) => {
/** @type {string[]} */
const identifiers = []
function noReferenceLikeURL(tree, file) {
var identifiers = []
visit(tree, 'definition', (node) => {
if (!generated(node)) {
identifiers.push(node.identifier.toLowerCase())
}
})
visit(tree, 'definition', find)
visit(tree, ['image', 'link'], check)
// Find identifiers.
function find(node) {
if (!generated(node)) {
identifiers.push(node.identifier.toLowerCase())
}
visit(tree, (node) => {
if (
(node.type === 'image' || node.type === 'link') &&
identifiers.includes(node.url.toLowerCase())
) {
file.message(
'Did you mean to use `[' +
node.url +
']` instead of ' +
'`(' +
node.url +
')`, a reference?',
node
)
}
})
}
)
// Check `node`.
function check(node) {
var url = node.url
var reason
if (identifiers.indexOf(url.toLowerCase()) !== -1) {
reason =
'Did you mean to use `[' +
url +
']` instead of ' +
'`(' +
url +
')`, a reference?'
file.message(reason, node)
}
}
}
export default remarkLintNoReferenceLikeUrl
{
"name": "remark-lint-no-reference-like-url",
"version": "2.0.1",
"version": "3.0.0",
"description": "remark-lint rule to warn when URLs are also defined identifiers",

@@ -25,11 +25,27 @@ "license": "MIT",

],
"sideEffects": false,
"type": "module",
"main": "index.js",
"types": "index.d.ts",
"files": [
"index.d.ts",
"index.js"
],
"dependencies": {
"unified-lint-rule": "^1.0.0",
"unist-util-generated": "^1.1.0",
"unist-util-visit": "^2.0.0"
"@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"
},
"xo": false
"scripts": {
"build": "rimraf \"*.d.ts\" && tsc && type-coverage"
},
"xo": false,
"typeCoverage": {
"atLeast": 100,
"detail": true,
"strict": true,
"ignoreCatch": true
}
}

@@ -53,2 +53,5 @@ <!--This file is generated-->

This package is [ESM only][esm]:
Node 12+ is needed to use it and it must be `imported`ed instead of `required`d.
[npm][]:

@@ -60,2 +63,5 @@

This package exports no identifiers.
The default export is `remarkLintNoReferenceLikeUrl`.
## Use

@@ -87,10 +93,13 @@

```diff
var remark = require('remark')
var report = require('vfile-reporter')
import {remark} from 'remark'
import {reporter} from 'vfile-reporter'
import remarkLint from 'remark-lint'
import remarkLintNoReferenceLikeUrl from 'remark-lint-no-reference-like-url'
remark()
.use(require('remark-lint'))
+ .use(require('remark-lint-no-reference-like-url'))
.process('_Emphasis_ and **importance**', function (err, file) {
console.error(report(err || file))
.use(remarkLint)
+ .use(remarkLintNoReferenceLikeUrl)
.process('_Emphasis_ and **importance**')
.then((file) => {
console.error(reporter(file))
})

@@ -113,5 +122,5 @@ ```

[build-badge]: https://img.shields.io/travis/remarkjs/remark-lint/main.svg
[build-badge]: https://github.com/remarkjs/remark-lint/workflows/main/badge.svg
[build]: https://travis-ci.org/remarkjs/remark-lint
[build]: https://github.com/remarkjs/remark-lint/actions

@@ -136,6 +145,8 @@ [coverage-badge]: https://img.shields.io/codecov/c/github/remarkjs/remark-lint.svg

[chat-badge]: https://img.shields.io/badge/chat-spectrum.svg
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg
[chat]: https://spectrum.chat/unified/remark
[chat]: https://github.com/remarkjs/remark/discussions
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
[npm]: https://docs.npmjs.com/cli/install

@@ -142,0 +153,0 @@