remark-lint-no-duplicate-headings-in-section
Advanced tools
Comparing version 2.0.2 to 3.0.0
82
index.js
@@ -10,3 +10,4 @@ /** | ||
* | ||
* @example {"name": "ok.md"} | ||
* @example | ||
* {"name": "ok.md"} | ||
* | ||
@@ -29,3 +30,4 @@ * ## Alpha | ||
* | ||
* @example {"name": "not-ok.md", "label": "input"} | ||
* @example | ||
* {"name": "not-ok.md", "label": "input"} | ||
* | ||
@@ -38,7 +40,9 @@ * ## Foxtrot | ||
* | ||
* @example {"name": "not-ok.md", "label": "output"} | ||
* @example | ||
* {"name": "not-ok.md", "label": "output"} | ||
* | ||
* 5:1-5:9: Do not use headings with similar content per section (3:1) | ||
* | ||
* @example {"name": "not-ok-tolerant-heading-increment.md", "label": "input"} | ||
* @example | ||
* {"name": "not-ok-tolerant-heading-increment.md", "label": "input"} | ||
* | ||
@@ -55,3 +59,4 @@ * # Alpha | ||
* | ||
* @example {"name": "not-ok-tolerant-heading-increment.md", "label": "output"} | ||
* @example | ||
* {"name": "not-ok-tolerant-heading-increment.md", "label": "output"} | ||
* | ||
@@ -61,40 +66,43 @@ * 7:1-7:11: Do not use headings with similar content per section (3:1) | ||
'use strict' | ||
/** | ||
* @typedef {import('mdast').Root} Root | ||
* @typedef {import('mdast').Heading} Heading | ||
*/ | ||
var rule = require('unified-lint-rule') | ||
var position = require('unist-util-position') | ||
var generated = require('unist-util-generated') | ||
var visit = require('unist-util-visit') | ||
var stringify = require('unist-util-stringify-position') | ||
var toString = require('mdast-util-to-string') | ||
import {lintRule} from 'unified-lint-rule' | ||
import {pointStart} from 'unist-util-position' | ||
import {generated} from 'unist-util-generated' | ||
import {visit} from 'unist-util-visit' | ||
import {stringifyPosition} from 'unist-util-stringify-position' | ||
import {toString} from 'mdast-util-to-string' | ||
module.exports = rule( | ||
const remarkLintNoDuplicateHeadingsInSection = lintRule( | ||
'remark-lint:no-duplicate-headings-in-section', | ||
noDuplicateHeadingsInSection | ||
) | ||
/** @type {import('unified-lint-rule').Rule<Root, void>} */ | ||
(tree, file) => { | ||
/** @type {Array.<Record<string, Heading>>} */ | ||
let stack = [] | ||
var reason = 'Do not use headings with similar content per section' | ||
visit(tree, 'heading', (node) => { | ||
const depth = node.depth | ||
const value = toString(node).toUpperCase() | ||
const index = depth - 1 | ||
const scope = stack[index] || (stack[index] = {}) | ||
const duplicate = scope[value] | ||
function noDuplicateHeadingsInSection(tree, file) { | ||
var stack = [] | ||
if (!generated(node) && duplicate) { | ||
file.message( | ||
'Do not use headings with similar content per section (' + | ||
stringifyPosition(pointStart(duplicate)) + | ||
')', | ||
node | ||
) | ||
} | ||
visit(tree, 'heading', visitor) | ||
scope[value] = node | ||
stack = stack.slice(0, depth) | ||
}) | ||
} | ||
) | ||
function visitor(node) { | ||
var depth = node.depth | ||
var value = toString(node).toUpperCase() | ||
var index = depth - 1 | ||
var scope = stack[index] || (stack[index] = {}) | ||
var duplicate = scope[value] | ||
if (!generated(node) && duplicate) { | ||
file.message( | ||
reason + ' (' + stringify(position.start(duplicate)) + ')', | ||
node | ||
) | ||
} | ||
scope[value] = node | ||
stack = stack.slice(0, depth) | ||
} | ||
} | ||
export default remarkLintNoDuplicateHeadingsInSection |
{ | ||
"name": "remark-lint-no-duplicate-headings-in-section", | ||
"version": "2.0.2", | ||
"version": "3.0.0", | ||
"description": "remark-lint rule to warn on duplicate headings in a section", | ||
@@ -25,14 +25,30 @@ "license": "MIT", | ||
], | ||
"sideEffects": false, | ||
"type": "module", | ||
"main": "index.js", | ||
"types": "index.d.ts", | ||
"files": [ | ||
"index.d.ts", | ||
"index.js" | ||
], | ||
"dependencies": { | ||
"mdast-util-to-string": "^1.0.2", | ||
"unified-lint-rule": "^1.0.0", | ||
"unist-util-generated": "^1.1.0", | ||
"unist-util-position": "^3.0.0", | ||
"unist-util-stringify-position": "^2.0.0", | ||
"unist-util-visit": "^2.0.0" | ||
"@types/mdast": "^3.0.0", | ||
"mdast-util-to-string": "^3.0.0", | ||
"unified": "^10.0.0", | ||
"unified-lint-rule": "^2.0.0", | ||
"unist-util-generated": "^2.0.0", | ||
"unist-util-position": "^4.0.0", | ||
"unist-util-stringify-position": "^3.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 | ||
} | ||
} |
@@ -90,2 +90,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][]: | ||
@@ -97,2 +100,5 @@ | ||
This package exports no identifiers. | ||
The default export is `remarkLintNoDuplicateHeadingsInSection`. | ||
## Use | ||
@@ -124,10 +130,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 remarkLintNoDuplicateHeadingsInSection from 'remark-lint-no-duplicate-headings-in-section' | ||
remark() | ||
.use(require('remark-lint')) | ||
+ .use(require('remark-lint-no-duplicate-headings-in-section')) | ||
.process('_Emphasis_ and **importance**', function (err, file) { | ||
console.error(report(err || file)) | ||
.use(remarkLint) | ||
+ .use(remarkLintNoDuplicateHeadingsInSection) | ||
.process('_Emphasis_ and **importance**') | ||
.then((file) => { | ||
console.error(reporter(file)) | ||
}) | ||
@@ -150,5 +159,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 | ||
@@ -173,6 +182,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 | ||
@@ -179,0 +190,0 @@ |
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
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
8138
4
113
197
Yes
8
+ Added@types/mdast@^3.0.0
+ Addedunified@^10.0.0
+ Added@types/mdast@3.0.15(transitive)
+ Addedbail@2.0.2(transitive)
+ Addedextend@3.0.2(transitive)
+ Addedis-buffer@2.0.5(transitive)
+ Addedis-plain-obj@4.1.0(transitive)
+ Addedmdast-util-to-string@3.2.0(transitive)
+ Addedtrough@2.2.0(transitive)
+ Addedunified@10.1.2(transitive)
+ Addedunified-lint-rule@2.1.2(transitive)
+ Addedunist-util-generated@2.0.1(transitive)
+ Addedunist-util-is@5.2.1(transitive)
+ Addedunist-util-position@4.0.4(transitive)
+ Addedunist-util-stringify-position@3.0.3(transitive)
+ Addedunist-util-visit@4.1.2(transitive)
+ Addedunist-util-visit-parents@5.1.3(transitive)
+ Addedvfile@5.3.7(transitive)
+ Addedvfile-message@3.1.4(transitive)
- Removedco@3.1.0(transitive)
- Removedmdast-util-to-string@1.1.0(transitive)
- Removedsliced@1.0.1(transitive)
- Removedunified-lint-rule@1.0.6(transitive)
- Removedunist-util-generated@1.1.6(transitive)
- Removedunist-util-is@4.1.0(transitive)
- Removedunist-util-position@3.1.0(transitive)
- Removedunist-util-stringify-position@2.0.3(transitive)
- Removedunist-util-visit@2.0.3(transitive)
- Removedunist-util-visit-parents@3.1.1(transitive)
- Removedwrapped@1.0.1(transitive)
Updatedmdast-util-to-string@^3.0.0
Updatedunified-lint-rule@^2.0.0
Updatedunist-util-generated@^2.0.0
Updatedunist-util-position@^4.0.0
Updatedunist-util-visit@^4.0.0