remark-lint-no-emphasis-as-heading
Advanced tools
+16
| export default remarkLintNoEmphasisAsHeading | ||
| export type Root = import('mdast').Root | ||
| declare const remarkLintNoEmphasisAsHeading: import('unified-lint-rule/node_modules/unified').Plugin< | ||
| | void[] | ||
| | [unknown] | ||
| | [ | ||
| ( | ||
| | boolean | ||
| | import('unified-lint-rule').Label | ||
| | import('unified-lint-rule').Severity | ||
| ), | ||
| unknown | ||
| ], | ||
| import('mdast').Root, | ||
| import('mdast').Root | ||
| > |
+42
-28
@@ -10,3 +10,4 @@ /** | ||
| * | ||
| * @example {"name": "ok.md"} | ||
| * @example | ||
| * {"name": "ok.md"} | ||
| * | ||
@@ -17,3 +18,4 @@ * # Foo | ||
| * | ||
| * @example {"name": "not-ok.md", "label": "input"} | ||
| * @example | ||
| * {"name": "not-ok.md", "label": "input"} | ||
| * | ||
@@ -28,3 +30,4 @@ * *Foo* | ||
| * | ||
| * @example {"name": "not-ok.md", "label": "output"} | ||
| * @example | ||
| * {"name": "not-ok.md", "label": "output"} | ||
| * | ||
@@ -35,31 +38,42 @@ * 1:1-1:6: Don’t use emphasis to introduce a section, use a heading | ||
| 'use strict' | ||
| /** | ||
| * @typedef {import('mdast').Root} Root | ||
| */ | ||
| var rule = require('unified-lint-rule') | ||
| var visit = require('unist-util-visit') | ||
| var generated = require('unist-util-generated') | ||
| import {lintRule} from 'unified-lint-rule' | ||
| import {visit} from 'unist-util-visit' | ||
| import {generated} from 'unist-util-generated' | ||
| module.exports = rule('remark-lint:no-emphasis-as-heading', noEmphasisAsHeading) | ||
| const remarkLintNoEmphasisAsHeading = lintRule( | ||
| 'remark-lint:no-emphasis-as-heading', | ||
| /** @type {import('unified-lint-rule').Rule<Root, void>} */ | ||
| (tree, file) => { | ||
| visit(tree, 'paragraph', (node, index, parent) => { | ||
| const head = node.children[0] | ||
| var reason = 'Don’t use emphasis to introduce a section, use a heading' | ||
| if ( | ||
| parent && | ||
| typeof index === 'number' && | ||
| !generated(node) && | ||
| node.children.length === 1 && | ||
| (head.type === 'emphasis' || head.type === 'strong') | ||
| ) { | ||
| const previous = parent.children[index - 1] | ||
| const next = parent.children[index + 1] | ||
| function noEmphasisAsHeading(tree, file) { | ||
| visit(tree, 'paragraph', visitor) | ||
| if ( | ||
| (!previous || previous.type !== 'heading') && | ||
| next && | ||
| next.type === 'paragraph' | ||
| ) { | ||
| file.message( | ||
| 'Don’t use emphasis to introduce a section, use a heading', | ||
| node | ||
| ) | ||
| } | ||
| } | ||
| }) | ||
| } | ||
| ) | ||
| function visitor(node, index, parent) { | ||
| var head = node.children[0] | ||
| var previous = parent.children[index - 1] | ||
| var next = parent.children[index + 1] | ||
| if ( | ||
| !generated(node) && | ||
| (!previous || previous.type !== 'heading') && | ||
| next && | ||
| next.type === 'paragraph' && | ||
| node.children.length === 1 && | ||
| (head.type === 'emphasis' || head.type === 'strong') | ||
| ) { | ||
| file.message(reason, node) | ||
| } | ||
| } | ||
| } | ||
| export default remarkLintNoEmphasisAsHeading |
+21
-5
| { | ||
| "name": "remark-lint-no-emphasis-as-heading", | ||
| "version": "2.0.1", | ||
| "version": "3.0.0", | ||
| "description": "remark-lint rule to warn when emphasis or importance is used instead of a heading", | ||
@@ -24,11 +24,27 @@ "license": "MIT", | ||
| ], | ||
| "sideEffects": false, | ||
| "type": "module", | ||
| "main": "index.js", | ||
| "types": "index.d.ts", | ||
| "files": [ | ||
| "index.d.ts", | ||
| "index.js" | ||
| ], | ||
| "dependencies": { | ||
| "unified-lint-rule": "^1.0.0", | ||
| "unist-util-generated": "^1.1.0", | ||
| "unist-util-visit": "^2.0.0" | ||
| "@types/mdast": "^3.0.0", | ||
| "unified": "^10.0.0", | ||
| "unified-lint-rule": "^2.0.0", | ||
| "unist-util-generated": "^2.0.0", | ||
| "unist-util-visit": "^4.0.0" | ||
| }, | ||
| "xo": false | ||
| "scripts": { | ||
| "build": "rimraf \"*.d.ts\" && tsc && type-coverage" | ||
| }, | ||
| "xo": false, | ||
| "typeCoverage": { | ||
| "atLeast": 100, | ||
| "detail": true, | ||
| "strict": true, | ||
| "ignoreCatch": true | ||
| } | ||
| } |
+21
-10
@@ -63,2 +63,5 @@ <!--This file is generated--> | ||
| This package is [ESM only][esm]: | ||
| Node 12+ is needed to use it and it must be `imported`ed instead of `required`d. | ||
| [npm][]: | ||
@@ -70,2 +73,5 @@ | ||
| This package exports no identifiers. | ||
| The default export is `remarkLintNoEmphasisAsHeading`. | ||
| ## Use | ||
@@ -97,10 +103,13 @@ | ||
| ```diff | ||
| var remark = require('remark') | ||
| var report = require('vfile-reporter') | ||
| import {remark} from 'remark' | ||
| import {reporter} from 'vfile-reporter' | ||
| import remarkLint from 'remark-lint' | ||
| import remarkLintNoEmphasisAsHeading from 'remark-lint-no-emphasis-as-heading' | ||
| remark() | ||
| .use(require('remark-lint')) | ||
| + .use(require('remark-lint-no-emphasis-as-heading')) | ||
| .process('_Emphasis_ and **importance**', function (err, file) { | ||
| console.error(report(err || file)) | ||
| .use(remarkLint) | ||
| + .use(remarkLintNoEmphasisAsHeading) | ||
| .process('_Emphasis_ and **importance**') | ||
| .then((file) => { | ||
| console.error(reporter(file)) | ||
| }) | ||
@@ -123,5 +132,5 @@ ``` | ||
| [build-badge]: https://img.shields.io/travis/remarkjs/remark-lint/main.svg | ||
| [build-badge]: https://github.com/remarkjs/remark-lint/workflows/main/badge.svg | ||
| [build]: https://travis-ci.org/remarkjs/remark-lint | ||
| [build]: https://github.com/remarkjs/remark-lint/actions | ||
@@ -146,6 +155,8 @@ [coverage-badge]: https://img.shields.io/codecov/c/github/remarkjs/remark-lint.svg | ||
| [chat-badge]: https://img.shields.io/badge/chat-spectrum.svg | ||
| [chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg | ||
| [chat]: https://spectrum.chat/unified/remark | ||
| [chat]: https://github.com/remarkjs/remark/discussions | ||
| [esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c | ||
| [npm]: https://docs.npmjs.com/cli/install | ||
@@ -152,0 +163,0 @@ |
7157
25.14%4
33.33%85
57.41%170
6.92%Yes
NaN5
66.67%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
Updated
Updated
Updated