remark-lint-list-item-indent
Advanced tools
Comparing version 2.0.1 to 3.0.0
144
index.js
@@ -25,3 +25,4 @@ /** | ||
* | ||
* @example {"name": "ok.md"} | ||
* @example | ||
* {"name": "ok.md"} | ||
* | ||
@@ -44,3 +45,4 @@ * *···List | ||
* | ||
* @example {"name": "ok.md", "setting": "mixed"} | ||
* @example | ||
* {"name": "ok.md", "setting": "mixed"} | ||
* | ||
@@ -61,3 +63,4 @@ * *·List item. | ||
* | ||
* @example {"name": "ok.md", "setting": "space"} | ||
* @example | ||
* {"name": "ok.md", "setting": "space"} | ||
* | ||
@@ -78,3 +81,4 @@ * *·List item. | ||
* | ||
* @example {"name": "not-ok.md", "setting": "space", "label": "input"} | ||
* @example | ||
* {"name": "not-ok.md", "setting": "space", "label": "input"} | ||
* | ||
@@ -84,7 +88,9 @@ * *···List | ||
* | ||
* @example {"name": "not-ok.md", "setting": "space", "label": "output"} | ||
* @example | ||
* {"name": "not-ok.md", "setting": "space", "label": "output"} | ||
* | ||
* 1:5: Incorrect list-item indent: remove 2 spaces | ||
* | ||
* @example {"name": "not-ok.md", "setting": "tab-size", "label": "input"} | ||
* @example | ||
* {"name": "not-ok.md", "setting": "tab-size", "label": "input"} | ||
* | ||
@@ -94,15 +100,19 @@ * *·List | ||
* | ||
* @example {"name": "not-ok.md", "setting": "tab-size", "label": "output"} | ||
* @example | ||
* {"name": "not-ok.md", "setting": "tab-size", "label": "output"} | ||
* | ||
* 1:3: Incorrect list-item indent: add 2 spaces | ||
* | ||
* @example {"name": "not-ok.md", "setting": "mixed", "label": "input"} | ||
* @example | ||
* {"name": "not-ok.md", "setting": "mixed", "label": "input"} | ||
* | ||
* *···List item. | ||
* | ||
* @example {"name": "not-ok.md", "setting": "mixed", "label": "output"} | ||
* @example | ||
* {"name": "not-ok.md", "setting": "mixed", "label": "output"} | ||
* | ||
* 1:5: Incorrect list-item indent: remove 2 spaces | ||
* | ||
* @example {"name": "not-ok.md", "setting": "💩", "label": "output", "config": {"positionless": true}} | ||
* @example | ||
* {"name": "not-ok.md", "setting": "💩", "label": "output", "positionless": true} | ||
* | ||
@@ -112,74 +122,68 @@ * 1:1: Incorrect list-item indent style `💩`: use either `'tab-size'`, `'space'`, or `'mixed'` | ||
'use strict' | ||
/** | ||
* @typedef {import('mdast').Root} Root | ||
* @typedef {'tab-size'|'space'|'mixed'} Options | ||
*/ | ||
var rule = require('unified-lint-rule') | ||
var plural = require('pluralize') | ||
var visit = require('unist-util-visit') | ||
var position = require('unist-util-position') | ||
var generated = require('unist-util-generated') | ||
import {lintRule} from 'unified-lint-rule' | ||
import plural from 'pluralize' | ||
import {visit} from 'unist-util-visit' | ||
import {pointStart} from 'unist-util-position' | ||
import {generated} from 'unist-util-generated' | ||
module.exports = rule('remark-lint:list-item-indent', listItemIndent) | ||
const remarkLintListItemIndent = lintRule( | ||
'remark-lint:list-item-indent', | ||
/** @type {import('unified-lint-rule').Rule<Root, Options>} */ | ||
(tree, file, option = 'tab-size') => { | ||
const value = String(file) | ||
var start = position.start | ||
if (option !== 'tab-size' && option !== 'space' && option !== 'mixed') { | ||
file.fail( | ||
'Incorrect list-item indent style `' + | ||
option + | ||
"`: use either `'tab-size'`, `'space'`, or `'mixed'`" | ||
) | ||
} | ||
var styles = {'tab-size': true, mixed: true, space: true} | ||
visit(tree, 'list', (node) => { | ||
if (generated(node)) return | ||
function listItemIndent(tree, file, option) { | ||
var contents = String(file) | ||
var preferred = typeof option === 'string' ? option : 'tab-size' | ||
const spread = node.spread | ||
let index = -1 | ||
if (styles[preferred] !== true) { | ||
file.fail( | ||
'Incorrect list-item indent style `' + | ||
preferred + | ||
"`: use either `'tab-size'`, `'space'`, or `'mixed'`" | ||
) | ||
} | ||
while (++index < node.children.length) { | ||
const item = node.children[index] | ||
const head = item.children[0] | ||
const final = pointStart(head) | ||
visit(tree, 'list', visitor) | ||
const marker = value | ||
.slice(pointStart(item).offset, final.offset) | ||
.replace(/\[[x ]?]\s*$/i, '') | ||
function visitor(node) { | ||
var spread = node.spread || node.loose | ||
const bulletSize = marker.replace(/\s+$/, '').length | ||
if (!generated(node)) { | ||
node.children.forEach(visitItem) | ||
} | ||
const style = | ||
option === 'tab-size' || (option === 'mixed' && spread) | ||
? Math.ceil(bulletSize / 4) * 4 | ||
: bulletSize + 1 | ||
function visitItem(item) { | ||
var head = item.children[0] | ||
var final = start(head) | ||
var marker | ||
var bulletSize | ||
var style | ||
var diff | ||
var reason | ||
var abs | ||
if (marker.length !== style) { | ||
const diff = style - marker.length | ||
const abs = Math.abs(diff) | ||
marker = contents | ||
.slice(start(item).offset, final.offset) | ||
.replace(/\[[x ]?]\s*$/i, '') | ||
bulletSize = marker.replace(/\s+$/, '').length | ||
style = | ||
preferred === 'tab-size' || (preferred === 'mixed' && spread) | ||
? Math.ceil(bulletSize / 4) * 4 | ||
: bulletSize + 1 | ||
if (marker.length !== style) { | ||
diff = style - marker.length | ||
abs = Math.abs(diff) | ||
reason = | ||
'Incorrect list-item indent: ' + | ||
(diff > 0 ? 'add' : 'remove') + | ||
' ' + | ||
abs + | ||
' ' + | ||
plural('space', abs) | ||
file.message(reason, final) | ||
file.message( | ||
'Incorrect list-item indent: ' + | ||
(diff > 0 ? 'add' : 'remove') + | ||
' ' + | ||
abs + | ||
' ' + | ||
plural('space', abs), | ||
final | ||
) | ||
} | ||
} | ||
} | ||
}) | ||
} | ||
} | ||
) | ||
export default remarkLintListItemIndent |
{ | ||
"name": "remark-lint-list-item-indent", | ||
"version": "2.0.1", | ||
"version": "3.0.0", | ||
"description": "remark-lint rule to warn when the spacing between a list item’s bullet and its content violates a given style", | ||
@@ -25,13 +25,29 @@ "license": "MIT", | ||
], | ||
"sideEffects": false, | ||
"type": "module", | ||
"main": "index.js", | ||
"types": "index.d.ts", | ||
"files": [ | ||
"index.d.ts", | ||
"index.js" | ||
], | ||
"dependencies": { | ||
"@types/mdast": "^3.0.0", | ||
"pluralize": "^8.0.0", | ||
"unified-lint-rule": "^1.0.0", | ||
"unist-util-generated": "^1.1.0", | ||
"unist-util-position": "^3.0.0", | ||
"unist-util-visit": "^2.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-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 | ||
} | ||
} |
@@ -194,2 +194,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][]: | ||
@@ -201,2 +204,5 @@ | ||
This package exports no identifiers. | ||
The default export is `remarkLintListItemIndent`. | ||
## Use | ||
@@ -228,10 +234,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 remarkLintListItemIndent from 'remark-lint-list-item-indent' | ||
remark() | ||
.use(require('remark-lint')) | ||
+ .use(require('remark-lint-list-item-indent')) | ||
.process('_Emphasis_ and **importance**', function (err, file) { | ||
console.error(report(err || file)) | ||
.use(remarkLint) | ||
+ .use(remarkLintListItemIndent) | ||
.process('_Emphasis_ and **importance**') | ||
.then((file) => { | ||
console.error(reporter(file)) | ||
}) | ||
@@ -254,5 +263,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 | ||
@@ -277,6 +286,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 | ||
@@ -283,0 +294,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
12036
4
191
301
Yes
7
+ 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)
+ 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)
- 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-visit@2.0.3(transitive)
- Removedunist-util-visit-parents@3.1.1(transitive)
- Removedwrapped@1.0.1(transitive)
Updatedunified-lint-rule@^2.0.0
Updatedunist-util-generated@^2.0.0
Updatedunist-util-position@^4.0.0
Updatedunist-util-visit@^4.0.0