remark-lint-no-literal-urls
Advanced tools
Comparing version 1.0.1 to 1.0.2
53
index.js
@@ -9,2 +9,10 @@ /** | ||
* | ||
* ## Fix | ||
* | ||
* [`remark-stringify`](https://github.com/remarkjs/remark/tree/master/packages/remark-stringify) | ||
* never creates literal URLs and always uses angle-brackets. | ||
* | ||
* See [Using remark to fix your markdown](https://github.com/remarkjs/remark-lint#using-remark-to-fix-your-markdown) | ||
* on how to automatically fix warnings for this rule. | ||
* | ||
* @example {"name": "valid.md"} | ||
@@ -23,38 +31,33 @@ * | ||
'use strict'; | ||
'use strict' | ||
var rule = require('unified-lint-rule'); | ||
var visit = require('unist-util-visit'); | ||
var position = require('unist-util-position'); | ||
var generated = require('unist-util-generated'); | ||
var toString = require('mdast-util-to-string'); | ||
var rule = require('unified-lint-rule') | ||
var visit = require('unist-util-visit') | ||
var position = require('unist-util-position') | ||
var generated = require('unist-util-generated') | ||
var toString = require('mdast-util-to-string') | ||
module.exports = rule('remark-lint:no-literal-urls', noLiteralURLs); | ||
module.exports = rule('remark-lint:no-literal-urls', noLiteralURLs) | ||
var start = position.start; | ||
var end = position.end; | ||
var MAILTO = 'mailto:'; | ||
var start = position.start | ||
var end = position.end | ||
var mailto = 'mailto:' | ||
var reason = 'Don’t use literal URLs without angle brackets' | ||
function noLiteralURLs(ast, file) { | ||
visit(ast, 'link', visitor); | ||
function noLiteralURLs(tree, file) { | ||
visit(tree, 'link', visitor) | ||
function visitor(node) { | ||
var head = start(node.children[0]).column; | ||
var tail = end(node.children[node.children.length - 1]).column; | ||
var initial = start(node).column; | ||
var final = end(node).column; | ||
var value = toString(node); | ||
var children = node.children | ||
var value = toString(node) | ||
if (generated(node)) { | ||
return; | ||
} | ||
if ( | ||
initial === head && | ||
final === tail && | ||
(node.url === MAILTO + value || node.url === value) | ||
!generated(node) && | ||
start(node).column === start(children[0]).column && | ||
end(node).column === end(children[children.length - 1]).column && | ||
(node.url === mailto + value || node.url === value) | ||
) { | ||
file.message('Don’t use literal URLs without angle brackets', node); | ||
file.message(reason, node) | ||
} | ||
} | ||
} |
{ | ||
"name": "remark-lint-no-literal-urls", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "remark-lint rule to warn when URLs without angle-brackets are used", | ||
@@ -13,4 +13,4 @@ "license": "MIT", | ||
], | ||
"repository": "https://github.com/wooorm/remark-lint/tree/master/packages/remark-lint-no-literal-urls", | ||
"bugs": "https://github.com/wooorm/remark-lint/issues", | ||
"repository": "https://github.com/remarkjs/remark-lint/tree/master/packages/remark-lint-no-literal-urls", | ||
"bugs": "https://github.com/remarkjs/remark-lint/issues", | ||
"author": "Titus Wormer <tituswormer@gmail.com> (http://wooorm.com)", | ||
@@ -17,0 +17,0 @@ "contributors": [ |
@@ -7,2 +7,10 @@ <!--This file is generated--> | ||
## Fix | ||
[`remark-stringify`](https://github.com/remarkjs/remark/tree/master/packages/remark-stringify) | ||
never creates literal URLs and always uses angle-brackets. | ||
See [Using remark to fix your markdown](https://github.com/remarkjs/remark-lint#using-remark-to-fix-your-markdown) | ||
on how to automatically fix warnings for this rule. | ||
## Presets | ||
@@ -14,4 +22,4 @@ | ||
| ------ | ------- | | ||
| [`remark-preset-lint-markdown-style-guide`](https://github.com/wooorm/remark-lint/tree/master/packages/remark-preset-lint-markdown-style-guide) | | | ||
| [`remark-preset-lint-recommended`](https://github.com/wooorm/remark-lint/tree/master/packages/remark-preset-lint-recommended) | | | ||
| [`remark-preset-lint-markdown-style-guide`](https://github.com/remarkjs/remark-lint/tree/master/packages/remark-preset-lint-markdown-style-guide) | | | ||
| [`remark-preset-lint-recommended`](https://github.com/remarkjs/remark-lint/tree/master/packages/remark-preset-lint-recommended) | | | ||
@@ -91,2 +99,2 @@ ## Example | ||
[MIT](https://github.com/wooorm/remark-lint/blob/master/LICENSE) © [Titus Wormer](http://wooorm.com) | ||
[MIT](https://github.com/remarkjs/remark-lint/blob/master/LICENSE) © [Titus Wormer](http://wooorm.com) |
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
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
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
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
4406
54
98