remark-lint-no-empty-sections
Advanced tools
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
+60
| const test = require('tape'); | ||
| const remark = require('remark'); | ||
| const lint = require('remark-lint'); | ||
| const noEmptySections = require('./'); | ||
| const processor = remark().use(lint).use(noEmptySections); | ||
| const empty = `# A | ||
| ## B (this section is empty!) | ||
| ## C | ||
| `; | ||
| const higher = `# A | ||
| ## B (this section is empty!) | ||
| # C | ||
| `; | ||
| const lower = `# A | ||
| ## B | ||
| ### C | ||
| `; | ||
| const ok = `# A | ||
| ## C | ||
| `; | ||
| test('remark-lint-no-empty-sections', (t) => { | ||
| t.deepEqual( | ||
| processor.processSync(empty).messages.map(String), | ||
| ['3:30-5:1: Remove empty section: "B (this section is empty!)"'], | ||
| 'should warn for empty sections' | ||
| ); | ||
| t.deepEqual( | ||
| processor.processSync(lower).messages.map(String), | ||
| [], | ||
| 'should work on lower headings' | ||
| ); | ||
| t.deepEqual( | ||
| processor.processSync(higher).messages.map(String), | ||
| [], | ||
| 'should work on higher headings' | ||
| ); | ||
| t.deepEqual( | ||
| processor.processSync(ok).messages.map(String), | ||
| [], | ||
| 'should work on valid fixtures' | ||
| ); | ||
| t.end(); | ||
| }); |
Sorry, the diff of this file is too big to display
+3
-0
@@ -6,3 +6,6 @@ { | ||
| "node": true | ||
| }, | ||
| "rules": { | ||
| "comma-dangle": "off" | ||
| } | ||
| } |
| 'use strict'; | ||
| var rule = require('unified-lint-rule'); | ||
| var visit = require('unist-util-visit'); | ||
| var toString = require('mdast-util-to-string'); | ||
| function noEmptySection(ast, file, preferred, done) { | ||
| visit(ast, function (node, index, parent) { | ||
| function noEmptySection(ast, file) { | ||
| visit(ast, 'heading', function (node, index, parent) { | ||
| var next = parent && parent.children[index + 1]; | ||
| var label = toString(node); | ||
| if (next && node.type === 'heading' && next.type === 'heading' && node.depth === next.depth) { | ||
| file.warn('Remove empty section' + (node.children.length ? ': "' + node.children[0].value + '"' : ''), next); | ||
| if (next && next.type === 'heading' && next.depth === node.depth) { | ||
| file.warn('Remove empty section: "' + label + '"', { | ||
| start: node.position.end, | ||
| end: next.position.start | ||
| }); | ||
| } | ||
| }); | ||
| done(); | ||
| } | ||
| module.exports = { | ||
| 'empty-sections': noEmptySection | ||
| }; | ||
| module.exports = rule('remark-lint:no-empty-sections', noEmptySection); |
+11
-14
@@ -0,22 +1,19 @@ | ||
| const rule = require('unified-lint-rule'); | ||
| const visit = require('unist-util-visit'); | ||
| const toString = require('mdast-util-to-string'); | ||
| function noEmptySection(ast, file, preferred, done) { | ||
| visit(ast, (node, index, parent) => { | ||
| function noEmptySection(ast, file) { | ||
| visit(ast, 'heading', (node, index, parent) => { | ||
| const next = parent && parent.children[index + 1]; | ||
| const label = toString(node); | ||
| if ( | ||
| next && | ||
| (node.type === 'heading') && | ||
| (next.type === 'heading') && | ||
| (node.depth === next.depth) | ||
| ) { | ||
| file.warn('Remove empty section' + (node.children.length ? ': "' + node.children[0].value + '"' : ''), next); | ||
| if (next && next.type === 'heading' && next.depth === node.depth) { | ||
| file.warn(`Remove empty section: "${label}"`, { | ||
| start: node.position.end, | ||
| end: next.position.start | ||
| }); | ||
| } | ||
| }); | ||
| done(); | ||
| } | ||
| module.exports = { | ||
| 'empty-sections': noEmptySection | ||
| }; | ||
| module.exports = rule('remark-lint:no-empty-sections', noEmptySection); |
+20
-6
| { | ||
| "name": "remark-lint-no-empty-sections", | ||
| "version": "1.0.0", | ||
| "version": "2.0.0", | ||
| "description": "Checks that all markdown titles have a content", | ||
@@ -12,14 +12,28 @@ "author": "Victor Felder <victorfelder@gmail.com>", | ||
| "dependencies": { | ||
| "mdast-util-to-string": "^1.0.2", | ||
| "unified-lint-rule": "^1.0.0", | ||
| "unist-util-visit": "^1.0.0" | ||
| }, | ||
| "devDependencies": { | ||
| "babel-cli": "^6.23.0", | ||
| "babel-core": "^6.3.17", | ||
| "babel-eslint": "^5.0.0-beta6", | ||
| "babel-eslint": "^7.1.1", | ||
| "babel-preset-es2015": "^6.3.13", | ||
| "eslint": "^1.10.3", | ||
| "eslint-config-airbnb": "^2.1.1", | ||
| "eslint-plugin-react": "^3.11.3" | ||
| "eslint": "^3.16.1", | ||
| "eslint-config-airbnb": "^14.1.0", | ||
| "eslint-plugin-import": "^2.2.0", | ||
| "eslint-plugin-jsx-a11y": "^4.0.0", | ||
| "eslint-plugin-react": "^6.10.0", | ||
| "remark": "^7.0.0", | ||
| "remark-cli": "^3.0.0", | ||
| "remark-lint": "^6.0.0", | ||
| "tape": "^4.6.3" | ||
| }, | ||
| "scripts": { | ||
| "build": "babel lib -d dist" | ||
| "lint": "eslint .", | ||
| "build-md": "remark . -qfo", | ||
| "build-lib": "babel lib -d dist", | ||
| "build": "npm run build-md && npm run build-lib", | ||
| "test-api": "node test", | ||
| "test": "npm run lint && npm run build && npm run test-api" | ||
| }, | ||
@@ -26,0 +40,0 @@ "bugs": { |
+11
-18
@@ -5,3 +5,3 @@ # remark-lint-no-empty-sections | ||
| 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 a n-level title without content followed by another n-level title. | ||
| 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. | ||
@@ -29,5 +29,4 @@ ```Text | ||
| ```bash | ||
| npm install -g remark | ||
| npm install -g remark-lint | ||
| npm install remark-lint-no-empty-sections # local install! | ||
| npm install -g remark-cli | ||
| npm install remark-lint remark-lint-no-empty-sections | ||
| ``` | ||
@@ -39,7 +38,6 @@ | ||
| { | ||
| "plugins": { | ||
| "remark-lint": { | ||
| "external": ["remark-lint-no-empty-sections"] | ||
| } | ||
| } | ||
| "plugins": [ | ||
| "lint", | ||
| "lint-no-empty-sections" | ||
| ] | ||
| } | ||
@@ -51,3 +49,3 @@ ``` | ||
| ```bash | ||
| remark --no-stdout xxx.md | ||
| remark xxx.md | ||
| ``` | ||
@@ -58,10 +56,5 @@ | ||
| ```bash | ||
| npm install -g remark | ||
| npm install -g remark-lint | ||
| npm install -g remark-lint-no-empty-sections # global install! | ||
| remark --no-stdout -u remark-lint="external:[\"remark-lint-no-empty-sections\"]" xxx.md | ||
| npm install -g remark-cli | ||
| npm install remark-lint remark-lint-no-empty-sections | ||
| remark -u lint -u lint-no-empty-sections xxx.md | ||
| ``` | ||
| Note that the `lint=<lint_options>` option only works with `remark >= 1.1.1`. | ||
| This `README.md` is based on [this one](https://github.com/chcokr/mdast-lint-sentence-newline/blob/250b106c9e19b387270099cf16f17a84643f8944/README.md) by [@chcokr](https://github.com/chcokr) (MIT). |
Sorry, the diff of this file is not supported yet
104341
2539.54%12
33.33%75
141.94%3
200%13
116.67%56
-11.11%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added