Add new rule no-empty-url

Closes GH-109.
This commit is contained in:
Titus Wormer 2016-12-12 19:53:49 +01:00
parent 3e4d99d438
commit 995d529157
3 changed files with 74 additions and 1 deletions

View File

@ -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: Dont 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: Dont use links without URL
3:1-3:11: Dont use images without URL
```
## `no-file-name-articles`
Warn when file name start with an article.

View File

@ -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'),

View 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: Dont use links without URL
* 3:1-3:11: Dont 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('Dont use ' + node.type + 's without URL', node);
}
}
}