Skip to content

Commit

Permalink
Remove : requirement for no-emphasis-as-heading
Browse files Browse the repository at this point in the history
Closes GH-48.
  • Loading branch information
benbalter authored and wooorm committed Feb 29, 2016
1 parent 0c78a52 commit d54441e
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 27 deletions.
7 changes: 2 additions & 5 deletions doc/rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -754,22 +754,19 @@ Options: `boolean`, default: `false`.

```md
<!-- Valid: -->
# Foo:
# Foo

Bar.

<!-- Invalid: -->
*Foo:*
*Foo*

Bar.
```

Warn when emphasis (including strong), instead of a heading, introduces
a paragraph.

Currently, only warns when a colon (`:`) is also included, maybe that
could be omitted.

### no-file-name-articles

```md
Expand Down
20 changes: 3 additions & 17 deletions lib/rules/no-emphasis-as-heading.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,14 @@
* @fileoverview
* Warn when emphasis (including strong), instead of a heading, introduces
* a paragraph.
*
* Currently, only warns when a colon (`:`) is also included, maybe that
* could be omitted.
* @example
* <!-- Valid: -->
* # Foo:
* # Foo
*
* Bar.
*
* <!-- Invalid: -->
* *Foo:*
* *Foo*
*
* Bar.
*/
Expand All @@ -30,7 +27,6 @@
*/

var visit = require('unist-util-visit');
var toString = require('mdast-util-to-string');
var position = require('mdast-util-position');

/**
Expand All @@ -48,7 +44,6 @@ function noEmphasisAsHeading(ast, file, preferred, done) {
var child = children[0];
var prev = parent.children[index - 1];
var next = parent.children[index + 1];
var value;

if (position.generated(node)) {
return;
Expand All @@ -61,16 +56,7 @@ function noEmphasisAsHeading(ast, file, preferred, done) {
children.length === 1 &&
(child.type === 'emphasis' || child.type === 'strong')
) {
value = toString(child);

/*
* TODO: See if removing the punctuation
* necessity is possible?
*/

if (value.charAt(value.length - 1) === ':') {
file.warn('Don’t use emphasis to introduce a section, use a heading', node);
}
file.warn('Don’t use emphasis to introduce a section, use a heading', node);
}
});

Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
Ensuring the markdown you (and contributors) write is of great quality will
provide better rendering in all the different markdown parsers, and makes
sure less refactoring is needed afterwards. What is quality? That’s up to you,
but the defaults are sensible :ok\_hand:.
but the defaults are sensible :ok_hand:.

**remark-lint** has lots of tests. Supports Node, io.js, and the browser.
100% coverage. 50+ rules. It’s built on [**remark**][remark],
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/no-emphasis-as-heading-invalid.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
**How to make omelets:**
**How to make omelets**

Break an egg.

*How to bake bread:*
*How to bake bread*

Open the flour sack.
3 changes: 3 additions & 0 deletions test/fixtures/no-emphasis-as-heading-valid.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ Open the flour sack.

*And this is valid*

* One
* Two

This is also valid:

foo
Expand Down
4 changes: 2 additions & 2 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -703,8 +703,8 @@ describe('Rules', function () {
describeRule('no-emphasis-as-heading', function () {
describeSetting(true, function () {
assertFile('no-emphasis-as-heading-invalid.md', [
'no-emphasis-as-heading-invalid.md:1:1-1:25: Don’t use emphasis to introduce a section, use a heading',
'no-emphasis-as-heading-invalid.md:5:1-5:21: Don’t use emphasis to introduce a section, use a heading'
'no-emphasis-as-heading-invalid.md:1:1-1:24: Don’t use emphasis to introduce a section, use a heading',
'no-emphasis-as-heading-invalid.md:5:1-5:20: Don’t use emphasis to introduce a section, use a heading'
]);

assertFile('no-emphasis-as-heading-valid.md', []);
Expand Down

0 comments on commit d54441e

Please sign in to comment.