remark-lint-no-empty-sections
Advanced tools
Comparing version 2.0.0 to 3.0.0
@@ -18,2 +18,8 @@ 'use strict'; | ||
} | ||
if (parent.children.length - 1 === index) { | ||
file.warn('Remove empty section: "' + label + '"', { | ||
start: node.position.start, | ||
end: node.position.end | ||
}); | ||
} | ||
}); | ||
@@ -20,0 +26,0 @@ } |
@@ -16,2 +16,8 @@ const rule = require('unified-lint-rule'); | ||
} | ||
if (parent.children.length - 1 === index) { | ||
file.warn(`Remove empty section: "${label}"`, { | ||
start: node.position.start, | ||
end: node.position.end | ||
}); | ||
} | ||
}); | ||
@@ -18,0 +24,0 @@ } |
{ | ||
"name": "remark-lint-no-empty-sections", | ||
"version": "2.0.0", | ||
"version": "3.0.0", | ||
"description": "Checks that all markdown titles have a content", | ||
@@ -20,3 +20,3 @@ "author": "Victor Felder <victorfelder@gmail.com>", | ||
"babel-eslint": "^7.1.1", | ||
"babel-preset-es2015": "^6.3.13", | ||
"babel-preset-env": "^1.7.0", | ||
"eslint": "^3.16.1", | ||
@@ -27,4 +27,4 @@ "eslint-config-airbnb": "^14.1.0", | ||
"eslint-plugin-react": "^6.10.0", | ||
"remark": "^7.0.0", | ||
"remark-cli": "^3.0.0", | ||
"remark": "^9.0.0", | ||
"remark-cli": "^5.0.0", | ||
"remark-lint": "^6.0.0", | ||
@@ -31,0 +31,0 @@ "tape": "^4.6.3" |
@@ -1,8 +0,11 @@ | ||
# remark-lint-no-empty-sections | ||
# remark-lint-no-empty-sections [](https://travis-ci.org/vhf/remark-lint-no-empty-sections) | ||
This [remark-lint](https://github.com/wooorm/remark-lint) rule was created for [free-programming-books-lint](https://github.com/vhf/free-programming-books-lint) to enforce [free-programming-books](https://github.com/vhf/free-programming-books) [formatting guidelines](https://github.com/vhf/free-programming-books/blob/master/CONTRIBUTING.md#formatting). | ||
This rule checks that every `([#]+)title` has some content. This content can be anything: a lower-level title, a higher-level title, text, list, etc. It will only complain if you have an n-level title without content followed by another n-level title. | ||
This rule checks that every `([#]+)heading` has some content. This content can be anything: a lower-level heading, a higher-level heading, text, list, etc. It will warn when it detects an `n`-level heading without content followed by another `n`-level heading. | ||
```Text | ||
## Examples | ||
```markdown | ||
<!-- Invalid --> | ||
@@ -13,5 +16,17 @@ | ||
## B (this section is empty!) | ||
``` | ||
```markdown | ||
<!-- Invalid --> | ||
# A | ||
## B (this section is empty!) | ||
## C | ||
Some content. | ||
``` | ||
```markdown | ||
<!-- Valid --> | ||
@@ -22,2 +37,4 @@ | ||
## C | ||
Some content. | ||
``` | ||
@@ -24,0 +41,0 @@ |
39
test.js
@@ -13,4 +13,22 @@ const test = require('tape'); | ||
## C | ||
This one is not. | ||
`; | ||
const emptySectionAsLastNode = `# A | ||
## B | ||
It should warn when the last section is empty! | ||
## C (this section is empty!) | ||
`; | ||
const twoEmptySections = `# A | ||
## B (empty!) | ||
## C (empty and last!) | ||
`; | ||
const higher = `# A | ||
@@ -21,2 +39,4 @@ | ||
# C | ||
This one is not. | ||
`; | ||
@@ -29,2 +49,4 @@ | ||
### C | ||
Not empty. | ||
`; | ||
@@ -35,2 +57,4 @@ | ||
## C | ||
Not empty. | ||
`; | ||
@@ -46,2 +70,17 @@ | ||
t.deepEqual( | ||
processor.processSync(emptySectionAsLastNode).messages.map(String), | ||
['7:1-7:30: Remove empty section: "C (this section is empty!)"'], | ||
'should warn on empty section when it is the last section' | ||
); | ||
t.deepEqual( | ||
processor.processSync(twoEmptySections).messages.map(String), | ||
[ | ||
'3:14-5:1: Remove empty section: "B (empty!)"', | ||
'5:1-5:23: Remove empty section: "C (empty and last!)"' | ||
], | ||
'should warn on all empty sections, including last' | ||
); | ||
t.deepEqual( | ||
processor.processSync(lower).messages.map(String), | ||
@@ -48,0 +87,0 @@ [], |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
109592
113
73