remark-lint-no-emphasis-as-heading
Advanced tools
Comparing version 1.0.1 to 1.0.2
34
index.js
@@ -32,33 +32,31 @@ /** | ||
'use strict'; | ||
'use strict' | ||
var rule = require('unified-lint-rule'); | ||
var visit = require('unist-util-visit'); | ||
var generated = require('unist-util-generated'); | ||
var rule = require('unified-lint-rule') | ||
var visit = require('unist-util-visit') | ||
var generated = require('unist-util-generated') | ||
module.exports = rule('remark-lint:no-emphasis-as-heading', noEmphasisAsHeading); | ||
module.exports = rule('remark-lint:no-emphasis-as-heading', noEmphasisAsHeading) | ||
function noEmphasisAsHeading(ast, file) { | ||
visit(ast, 'paragraph', visitor); | ||
var reason = 'Don’t use emphasis to introduce a section, use a heading' | ||
function noEmphasisAsHeading(tree, file) { | ||
visit(tree, 'paragraph', visitor) | ||
function visitor(node, index, parent) { | ||
var children = node.children; | ||
var child = children[0]; | ||
var prev = parent.children[index - 1]; | ||
var next = parent.children[index + 1]; | ||
var head = node.children[0] | ||
var prev = parent.children[index - 1] | ||
var next = parent.children[index + 1] | ||
if (generated(node)) { | ||
return; | ||
} | ||
if ( | ||
!generated(node) && | ||
(!prev || prev.type !== 'heading') && | ||
next && | ||
next.type === 'paragraph' && | ||
children.length === 1 && | ||
(child.type === 'emphasis' || child.type === 'strong') | ||
node.children.length === 1 && | ||
(head.type === 'emphasis' || head.type === 'strong') | ||
) { | ||
file.message('Don’t use emphasis to introduce a section, use a heading', node); | ||
file.message(reason, node) | ||
} | ||
} | ||
} |
{ | ||
"name": "remark-lint-no-emphasis-as-heading", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "remark-lint rule to warn when emphasis or importance is used instead of a heading", | ||
@@ -13,4 +13,4 @@ "license": "MIT", | ||
], | ||
"repository": "https://github.com/wooorm/remark-lint/tree/master/packages/remark-lint-no-emphasis-as-heading", | ||
"bugs": "https://github.com/wooorm/remark-lint/issues", | ||
"repository": "https://github.com/remarkjs/remark-lint/tree/master/packages/remark-lint-no-emphasis-as-heading", | ||
"bugs": "https://github.com/remarkjs/remark-lint/issues", | ||
"author": "Titus Wormer <tituswormer@gmail.com> (http://wooorm.com)", | ||
@@ -17,0 +17,0 @@ "contributors": [ |
@@ -14,3 +14,3 @@ <!--This file is generated--> | ||
| ------ | ------- | | ||
| [`remark-preset-lint-markdown-style-guide`](https://github.com/wooorm/remark-lint/tree/master/packages/remark-preset-lint-markdown-style-guide) | | | ||
| [`remark-preset-lint-markdown-style-guide`](https://github.com/remarkjs/remark-lint/tree/master/packages/remark-preset-lint-markdown-style-guide) | | | ||
@@ -99,2 +99,2 @@ ## Example | ||
[MIT](https://github.com/wooorm/remark-lint/blob/master/LICENSE) © [Titus Wormer](http://wooorm.com) | ||
[MIT](https://github.com/remarkjs/remark-lint/blob/master/LICENSE) © [Titus Wormer](http://wooorm.com) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
3783
54