remark-lint-no-heading-indent
Advanced tools
Comparing version 1.0.1 to 1.0.2
59
index.js
@@ -9,2 +9,10 @@ /** | ||
* | ||
* ## Fix | ||
* | ||
* [`remark-stringify`](https://github.com/remarkjs/remark/tree/master/packages/remark-stringify) | ||
* removes all unneeded indentation around headings. | ||
* | ||
* See [Using remark to fix your markdown](https://github.com/remarkjs/remark-lint#using-remark-to-fix-your-markdown) | ||
* on how to automatically fix warnings for this rule. | ||
* | ||
* @example {"name": "valid.md"} | ||
@@ -42,45 +50,48 @@ * | ||
'use strict'; | ||
'use strict' | ||
var rule = require('unified-lint-rule'); | ||
var plural = require('plur'); | ||
var visit = require('unist-util-visit'); | ||
var position = require('unist-util-position'); | ||
var generated = require('unist-util-generated'); | ||
var rule = require('unified-lint-rule') | ||
var plural = require('plur') | ||
var visit = require('unist-util-visit') | ||
var position = require('unist-util-position') | ||
var generated = require('unist-util-generated') | ||
module.exports = rule('remark-lint:no-heading-indent', noHeadingIndent); | ||
module.exports = rule('remark-lint:no-heading-indent', noHeadingIndent) | ||
var start = position.start; | ||
var start = position.start | ||
function noHeadingIndent(ast, file) { | ||
var contents = file.toString(); | ||
var length = contents.length; | ||
function noHeadingIndent(tree, file) { | ||
var contents = String(file) | ||
var length = contents.length | ||
visit(ast, 'heading', visitor); | ||
visit(tree, 'heading', visitor) | ||
function visitor(node) { | ||
var initial = start(node); | ||
var begin = initial.offset; | ||
var index = begin - 1; | ||
var character; | ||
var diff; | ||
var initial | ||
var begin | ||
var index | ||
var character | ||
var diff | ||
if (generated(node)) { | ||
return; | ||
return | ||
} | ||
initial = start(node) | ||
begin = initial.offset | ||
index = begin - 1 | ||
while (++index < length) { | ||
character = contents.charAt(index); | ||
character = contents.charAt(index) | ||
if (character !== ' ' && character !== '\t') { | ||
break; | ||
break | ||
} | ||
} | ||
diff = index - begin; | ||
diff = index - begin | ||
if (diff) { | ||
file.message( | ||
'Remove ' + diff + ' ' + plural('space', diff) + | ||
' before this heading', | ||
'Remove ' + diff + ' ' + plural('space', diff) + ' before this heading', | ||
{ | ||
@@ -90,5 +101,5 @@ line: initial.line, | ||
} | ||
); | ||
) | ||
} | ||
} | ||
} |
{ | ||
"name": "remark-lint-no-heading-indent", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "remark-lint rule to warn when headings are indented", | ||
@@ -13,4 +13,4 @@ "license": "MIT", | ||
], | ||
"repository": "https://github.com/wooorm/remark-lint/tree/master/packages/remark-lint-no-heading-indent", | ||
"bugs": "https://github.com/wooorm/remark-lint/issues", | ||
"repository": "https://github.com/remarkjs/remark-lint/tree/master/packages/remark-lint-no-heading-indent", | ||
"bugs": "https://github.com/remarkjs/remark-lint/issues", | ||
"author": "Titus Wormer <tituswormer@gmail.com> (http://wooorm.com)", | ||
@@ -24,3 +24,3 @@ "contributors": [ | ||
"dependencies": { | ||
"plur": "^2.1.2", | ||
"plur": "^3.0.0", | ||
"unified-lint-rule": "^1.0.0", | ||
@@ -27,0 +27,0 @@ "unist-util-generated": "^1.1.0", |
@@ -7,2 +7,10 @@ <!--This file is generated--> | ||
## Fix | ||
[`remark-stringify`](https://github.com/remarkjs/remark/tree/master/packages/remark-stringify) | ||
removes all unneeded indentation around headings. | ||
See [Using remark to fix your markdown](https://github.com/remarkjs/remark-lint#using-remark-to-fix-your-markdown) | ||
on how to automatically fix warnings for this rule. | ||
## Presets | ||
@@ -108,2 +116,2 @@ | ||
[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
4744
89
116
+ Addedirregular-plurals@2.0.0(transitive)
+ Addedplur@3.1.1(transitive)
- Removedirregular-plurals@1.4.0(transitive)
- Removedplur@2.1.2(transitive)
Updatedplur@^3.0.0