Socket
Socket
Sign inDemoInstall

remark-lint-list-item-indent

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

remark-lint-list-item-indent - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

113

index.js

@@ -12,2 +12,13 @@ /**

*
* ## Fix
*
* [`remark-stringify`](https://github.com/remarkjs/remark/tree/master/packages/remark-stringify)
* uses `'tab-size'` (named `'tab'` there) by default to ensure markdown is
* seen the same way across vendors. This can be configured with the
* [`listItemIndent`](https://github.com/remarkjs/remark/tree/master/packages/remark-stringify#optionslistitemindent)
* option. This rule’s `'space'` option is named `'1'` there.
*
* 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"}

@@ -94,78 +105,70 @@ *

'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:list-item-indent', listItemIndent);
module.exports = rule('remark-lint:list-item-indent', listItemIndent)
var start = position.start;
var start = position.start
var STYLES = {
'tab-size': true,
mixed: true,
space: true
};
var styles = {'tab-size': true, mixed: true, space: true}
function listItemIndent(ast, file, preferred) {
var contents = file.toString();
function listItemIndent(tree, file, pref) {
var contents = String(file)
preferred = typeof preferred === 'string' ? preferred : 'tab-size';
pref = typeof pref === 'string' ? pref : 'tab-size'
if (STYLES[preferred] !== true) {
file.fail('Invalid list-item indent style `' + preferred + '`: use either `\'tab-size\'`, `\'space\'`, or `\'mixed\'`');
if (styles[pref] !== true) {
file.fail(
'Invalid list-item indent style `' +
pref +
"`: use either `'tab-size'`, `'space'`, or `'mixed'`"
)
}
visit(ast, 'list', visitor);
visit(tree, 'list', visitor)
function visitor(node) {
var items = node.children;
var loose = node.loose
if (generated(node)) {
return;
if (!generated(node)) {
node.children.forEach(visitItem)
}
items.forEach(visitItem);
function visitItem(item) {
var head = item.children[0];
var initial = start(item).offset;
var final = start(head).offset;
var bulletSize;
var tab;
var marker;
var shouldBe;
var diff;
var word;
var head = item.children[0]
var final = start(head)
var marker
var bulletSize
var style
var diff
var reason
marker = contents.slice(initial, final);
marker = contents
.slice(start(item).offset, final.offset)
.replace(/\[[x ]?]\s*$/i, '')
/* Support checkboxes. */
marker = marker.replace(/\[[x ]?]\s*$/i, '');
bulletSize = marker.trimRight().length
bulletSize = marker.trimRight().length;
tab = Math.ceil(bulletSize / 4) * 4;
style =
pref === 'tab-size' || (pref === 'mixed' && loose)
? Math.ceil(bulletSize / 4) * 4
: bulletSize + 1
if (preferred === 'tab-size') {
shouldBe = tab;
} else if (preferred === 'space') {
shouldBe = bulletSize + 1;
} else {
shouldBe = node.loose ? tab : bulletSize + 1;
}
if (marker.length !== style) {
diff = style - marker.length
if (marker.length !== shouldBe) {
diff = shouldBe - marker.length;
word = diff > 0 ? 'add' : 'remove';
reason =
'Incorrect list-item indent: ' +
(diff > 0 ? 'add' : 'remove') +
' ' +
Math.abs(diff) +
' ' +
plural('space', diff)
diff = Math.abs(diff);
file.message(
'Incorrect list-item indent: ' + word +
' ' + diff + ' ' + plural('space', diff),
start(head)
);
file.message(reason, final)
}

@@ -172,0 +175,0 @@ }

{
"name": "remark-lint-list-item-indent",
"version": "1.0.1",
"version": "1.0.2",
"description": "remark-lint rule to warn when the spacing between a list item’s bullet and its content violates a given style",

@@ -14,4 +14,4 @@ "license": "MIT",

],
"repository": "https://github.com/wooorm/remark-lint/tree/master/packages/remark-lint-list-item-indent",
"bugs": "https://github.com/wooorm/remark-lint/issues",
"repository": "https://github.com/remarkjs/remark-lint/tree/master/packages/remark-lint-list-item-indent",
"bugs": "https://github.com/remarkjs/remark-lint/issues",
"author": "Titus Wormer <tituswormer@gmail.com> (http://wooorm.com)",

@@ -25,3 +25,3 @@ "contributors": [

"dependencies": {
"plur": "^2.1.2",
"plur": "^3.0.0",
"unified-lint-rule": "^1.0.0",

@@ -28,0 +28,0 @@ "unist-util-generated": "^1.1.0",

@@ -10,2 +10,13 @@ <!--This file is generated-->

## Fix
[`remark-stringify`](https://github.com/remarkjs/remark/tree/master/packages/remark-stringify)
uses `'tab-size'` (named `'tab'` there) by default to ensure markdown is
seen the same way across vendors. This can be configured with the
[`listItemIndent`](https://github.com/remarkjs/remark/tree/master/packages/remark-stringify#optionslistitemindent)
option. This rule’s `'space'` option is named `'1'` there.
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

@@ -17,4 +28,4 @@

| ------ | ------- |
| [`remark-preset-lint-markdown-style-guide`](https://github.com/wooorm/remark-lint/tree/master/packages/remark-preset-lint-markdown-style-guide) | |
| [`remark-preset-lint-recommended`](https://github.com/wooorm/remark-lint/tree/master/packages/remark-preset-lint-recommended) | |
| [`remark-preset-lint-markdown-style-guide`](https://github.com/remarkjs/remark-lint/tree/master/packages/remark-preset-lint-markdown-style-guide) | `'mixed'` |
| [`remark-preset-lint-recommended`](https://github.com/remarkjs/remark-lint/tree/master/packages/remark-preset-lint-recommended) | `'tab-size'` |

@@ -218,2 +229,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)
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc