Skip to content

Commit

Permalink
Add new rule no-heading-like-paragraph
Browse files Browse the repository at this point in the history
Closes GH-107.
  • Loading branch information
wooorm committed Dec 12, 2016
1 parent e340c2c commit 3e4d99d
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 1 deletion.
29 changes: 28 additions & 1 deletion doc/rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions packages/remark-lint/lib/rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
50 changes: 50 additions & 0 deletions packages/remark-lint/lib/rules/no-heading-like-paragraph.js
Original file line number Diff line number Diff line change
@@ -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);
}
}
}

0 comments on commit 3e4d99d

Please sign in to comment.