Add new rule no-heading-like-paragraph

Closes GH-107.
This commit is contained in:
Titus Wormer 2016-12-12 19:39:25 +01:00
parent e340c2c830
commit 3e4d99d438
3 changed files with 79 additions and 1 deletions

View File

@ -2,7 +2,7 @@
# List of Rules
This document describes all (59)
This document describes all (60)
available rules, what they check for, examples of
what they warn for, and how to fix their warnings.
@ -103,6 +103,7 @@ For example, as follows:
- [no-file-name-outer-dashes](#no-file-name-outer-dashes)
- [no-heading-content-indent](#no-heading-content-indent)
- [no-heading-indent](#no-heading-indent)
- [no-heading-like-paragraph](#no-heading-like-paragraph)
- [no-heading-punctuation](#no-heading-punctuation)
- [no-html](#no-html)
- [no-inline-padding](#no-inline-padding)
@ -1738,6 +1739,32 @@ When this rule is turned on, the following file
10:4: Remove 3 spaces before this heading
```
## `no-heading-like-paragraph`
Warn for h7+ “headings”.
When this rule is turned on, the following file
`valid.md` is ok:
```markdown
###### Alpha
Bravo.
```
When this rule is turned on, the following file
`invalid.md` is **not** ok:
```markdown
####### Charlie
Delta.
```
```text
1:1-1:16: This looks like a heading but has too many hashes
```
## `no-heading-punctuation`
Warn when a heading ends with a a group of characters.

View File

@ -38,6 +38,7 @@ module.exports = {
'no-file-name-outer-dashes': require('./rules/no-file-name-outer-dashes.js'),
'no-heading-content-indent': require('./rules/no-heading-content-indent.js'),
'no-heading-indent': require('./rules/no-heading-indent.js'),
'no-heading-like-paragraph': require('./rules/no-heading-like-paragraph.js'),
'no-heading-punctuation': require('./rules/no-heading-punctuation.js'),
'no-html': require('./rules/no-html.js'),
'no-inline-padding': require('./rules/no-inline-padding.js'),

View File

@ -0,0 +1,50 @@
/**
* @author Titus Wormer
* @copyright 2015 Titus Wormer
* @license MIT
* @module no-heading-like-paragraph
* @fileoverview
* Warn for h7+ headings.
*
* @example {"name": "valid.md"}
*
* ###### Alpha
*
* Bravo.
*
* @example {"name": "invalid.md", "label": "input"}
*
* ####### Charlie
*
* Delta.
*
* @example {"name": "invalid.md", "label": "output"}
*
* 1:1-1:16: This looks like a heading but has too many hashes
*/
'use strict';
var visit = require('unist-util-visit');
var generated = require('unist-util-generated');
module.exports = noHeadingLikeParagraph;
var fence = '#######';
function noHeadingLikeParagraph(tree, file) {
visit(tree, 'paragraph', visitor);
function visitor(node) {
var head = node.children[0];
if (
head &&
head.type === 'text' &&
head.value.slice(0, fence.length) === fence &&
!generated(node)
) {
file.message('This looks like a heading but has too many hashes', node);
}
}
}