mirror of
https://github.com/remarkjs/remark-lint.git
synced 2024-10-26 19:31:42 +03:00
Add new rule no-empty-url
Closes GH-109.
This commit is contained in:
parent
3e4d99d438
commit
995d529157
30
doc/rules.md
30
doc/rules.md
@ -2,7 +2,7 @@
|
||||
|
||||
# List of Rules
|
||||
|
||||
This document describes all (60)
|
||||
This document describes all (61)
|
||||
available rules, what they check for, examples of
|
||||
what they warn for, and how to fix their warnings.
|
||||
|
||||
@ -96,6 +96,7 @@ For example, as follows:
|
||||
- [no-duplicate-headings-in-section](#no-duplicate-headings-in-section)
|
||||
- [no-duplicate-headings](#no-duplicate-headings)
|
||||
- [no-emphasis-as-heading](#no-emphasis-as-heading)
|
||||
- [no-empty-url](#no-empty-url)
|
||||
- [no-file-name-articles](#no-file-name-articles)
|
||||
- [no-file-name-consecutive-dashes](#no-file-name-consecutive-dashes)
|
||||
- [no-file-name-irregular-characters](#no-file-name-irregular-characters)
|
||||
@ -1492,6 +1493,33 @@ Bar.
|
||||
1:1-1:6: Don’t use emphasis to introduce a section, use a heading
|
||||
```
|
||||
|
||||
## `no-empty-url`
|
||||
|
||||
Warn for empty URLs in links and images.
|
||||
|
||||
When this rule is turned on, the following file
|
||||
`valid.md` is ok:
|
||||
|
||||
```markdown
|
||||
[alpha](http://bravo.com).
|
||||
|
||||
![charlie](http://delta.com/echo.png "foxtrott").
|
||||
```
|
||||
|
||||
When this rule is turned on, the following file
|
||||
`invalid.md` is **not** ok:
|
||||
|
||||
```markdown
|
||||
[golf]().
|
||||
|
||||
![hotel]().
|
||||
```
|
||||
|
||||
```text
|
||||
1:1-1:9: Don’t use links without URL
|
||||
3:1-3:11: Don’t use images without URL
|
||||
```
|
||||
|
||||
## `no-file-name-articles`
|
||||
|
||||
Warn when file name start with an article.
|
||||
|
@ -31,6 +31,7 @@ module.exports = {
|
||||
'no-duplicate-headings-in-section': require('./rules/no-duplicate-headings-in-section.js'),
|
||||
'no-duplicate-headings': require('./rules/no-duplicate-headings.js'),
|
||||
'no-emphasis-as-heading': require('./rules/no-emphasis-as-heading.js'),
|
||||
'no-empty-url': require('./rules/no-empty-url.js'),
|
||||
'no-file-name-articles': require('./rules/no-file-name-articles.js'),
|
||||
'no-file-name-consecutive-dashes': require('./rules/no-file-name-consecutive-dashes.js'),
|
||||
'no-file-name-irregular-characters': require('./rules/no-file-name-irregular-characters.js'),
|
||||
|
44
packages/remark-lint/lib/rules/no-empty-url.js
Normal file
44
packages/remark-lint/lib/rules/no-empty-url.js
Normal file
@ -0,0 +1,44 @@
|
||||
/**
|
||||
* @author Titus Wormer
|
||||
* @copyright 2015 Titus Wormer
|
||||
* @license MIT
|
||||
* @module no-empty-url
|
||||
* @fileoverview
|
||||
* Warn for empty URLs in links and images.
|
||||
*
|
||||
* @example {"name": "valid.md"}
|
||||
*
|
||||
* [alpha](http://bravo.com).
|
||||
*
|
||||
* ![charlie](http://delta.com/echo.png "foxtrott").
|
||||
*
|
||||
* @example {"name": "invalid.md", "label": "input"}
|
||||
*
|
||||
* [golf]().
|
||||
*
|
||||
* ![hotel]().
|
||||
*
|
||||
* @example {"name": "invalid.md", "label": "output"}
|
||||
*
|
||||
* 1:1-1:9: Don’t use links without URL
|
||||
* 3:1-3:11: Don’t use images without URL
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
var visit = require('unist-util-visit');
|
||||
var generated = require('unist-util-generated');
|
||||
|
||||
module.exports = noEmptyLinkURL;
|
||||
|
||||
var types = ['link', 'image'];
|
||||
|
||||
function noEmptyLinkURL(tree, file) {
|
||||
visit(tree, visitor);
|
||||
|
||||
function visitor(node) {
|
||||
if (types.indexOf(node.type) !== -1 && !generated(node) && !node.url) {
|
||||
file.message('Don’t use ' + node.type + 's without URL', node);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user