Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

remark-lint-no-table-indentation

Package Overview
Dependencies
Maintainers
2
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

remark-lint-no-table-indentation - npm Package Compare versions

Comparing version 3.0.0 to 4.0.0

index.d.ts

129

index.js

@@ -17,3 +17,4 @@ /**

*
* @example {"name": "ok.md", "gfm": true}
* @example
* {"name": "ok.md", "gfm": true}
*

@@ -26,3 +27,4 @@ * Paragraph.

*
* @example {"name": "not-ok.md", "label": "input", "gfm": true}
* @example
* {"name": "not-ok.md", "label": "input", "gfm": true}
*

@@ -35,3 +37,4 @@ * Paragraph.

*
* @example {"name": "not-ok.md", "label": "output", "gfm": true}
* @example
* {"name": "not-ok.md", "label": "output", "gfm": true}
*

@@ -42,3 +45,4 @@ * 3:4: Do not indent table rows

*
* @example {"name": "not-ok-blockquote.md", "label": "input", "gfm": true}
* @example
* {"name": "not-ok-blockquote.md", "label": "input", "gfm": true}
*

@@ -48,7 +52,9 @@ * >··| A |

*
* @example {"name": "not-ok-blockquote.md", "label": "output", "gfm": true}
* @example
* {"name": "not-ok-blockquote.md", "label": "output", "gfm": true}
*
* 1:4: Do not indent table rows
*
* @example {"name": "not-ok-list.md", "label": "input", "gfm": true}
* @example
* {"name": "not-ok-list.md", "label": "input", "gfm": true}
*

@@ -60,3 +66,4 @@ * -···paragraph

*
* @example {"name": "not-ok-list.md", "label": "output", "gfm": true}
* @example
* {"name": "not-ok-list.md", "label": "output", "gfm": true}
*

@@ -66,74 +73,70 @@ * 3:6: Do not indent table rows

'use strict'
/**
* @typedef {import('mdast').Root} Root
*/
var rule = require('unified-lint-rule')
var visit = require('unist-util-visit')
var position = require('unist-util-position')
var vfileLocation = require('vfile-location')
import {lintRule} from 'unified-lint-rule'
import {visit, SKIP} from 'unist-util-visit'
import {pointStart, pointEnd} from 'unist-util-position'
import {location} from 'vfile-location'
module.exports = rule('remark-lint:no-table-indentation', noTableIndentation)
const remarkLintNoTableIndentation = lintRule(
'remark-lint:no-table-indentation',
/** @type {import('unified-lint-rule').Rule<Root, void>} */
(tree, file) => {
const value = String(file)
const loc = location(value)
var reason = 'Do not indent table rows'
visit(tree, 'table', (node, _, parent) => {
const end = pointEnd(node).line
let line = pointStart(node).line
let column = 0
function noTableIndentation(tree, file) {
var content = String(file)
var location = vfileLocation(content)
if (parent && parent.type === 'root') {
column = 1
} else if (parent && parent.type === 'blockquote') {
column = pointStart(parent).column + 2
} else if (parent && parent.type === 'listItem') {
column = pointStart(parent.children[0]).column
visit(tree, 'table', visitor)
// Skip past the first line if we’re the first child of a list item.
/* c8 ignore next 3 */
if (parent.children[0] === node) {
line++
}
}
function visitor(node, _, parent) {
var line = position.start(node).line
var end = position.end(node).line
var column
var offset
var lineColumn
/* istanbul ignore else - Custom nodes may be containers. */
if (parent && parent.type === 'root') {
column = 1
} else if (parent && parent.type === 'blockquote') {
column = position.start(parent).column + 2
} else if (parent && parent.type === 'listItem') {
column = position.start(parent.children[0]).column
// Skip past the first line if we’re the first child of a list item.
if (parent.children[0] === node) {
line++
// In a parent we don’t know, exit.
if (!column || !line) {
return
}
}
// In a parent we don’t know, exit.
if (!column || !line) {
return
}
while (line <= end) {
let offset = loc.toOffset({line, column})
const lineColumn = offset
while (line <= end) {
offset = location.toOffset({line: line, column: column})
lineColumn = offset
while (/[ \t]/.test(value.charAt(offset - 1))) {
offset--
}
while (/[ \t]/.test(content.charAt(offset - 1))) {
offset--
}
if (!offset || /[\r\n>]/.test(value.charAt(offset - 1))) {
offset = lineColumn
/* istanbul ignore else - Exit if we find some other content before this
* line.
* This might be because the paragraph line is lazy, which isn’t this
* rule. */
if (!offset || /[\r\n>]/.test(content.charAt(offset - 1))) {
offset = lineColumn
while (/[ \t]/.test(value.charAt(offset))) {
offset++
}
while (/[ \t]/.test(content.charAt(offset))) {
offset++
if (lineColumn !== offset) {
file.message('Do not indent table rows', loc.toPoint(offset))
}
}
if (lineColumn !== offset) {
file.message(reason, location.toPosition(offset))
}
line++
}
line++
}
return SKIP
})
}
)
return visit.SKIP
}
}
export default remarkLintNoTableIndentation
{
"name": "remark-lint-no-table-indentation",
"version": "3.0.0",
"version": "4.0.0",
"description": "remark-lint rule to warn when tables are indented",

@@ -24,12 +24,28 @@ "license": "MIT",

],
"sideEffects": false,
"type": "module",
"main": "index.js",
"types": "index.d.ts",
"files": [
"index.d.ts",
"index.js"
],
"dependencies": {
"unified-lint-rule": "^1.0.0",
"unist-util-position": "^3.0.0",
"unist-util-visit": "^2.0.0",
"vfile-location": "^3.0.0"
"@types/mdast": "^3.0.0",
"unified": "^10.0.0",
"unified-lint-rule": "^2.0.0",
"unist-util-position": "^4.0.0",
"unist-util-visit": "^4.0.0",
"vfile-location": "^4.0.0"
},
"xo": false
"scripts": {
"build": "rimraf \"*.d.ts\" && tsc && type-coverage"
},
"xo": false,
"typeCoverage": {
"atLeast": 100,
"detail": true,
"strict": true,
"ignoreCatch": true
}
}

@@ -117,2 +117,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][]:

@@ -124,2 +127,5 @@

This package exports no identifiers.
The default export is `remarkLintNoTableIndentation`.
## Use

@@ -151,10 +157,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 remarkLintNoTableIndentation from 'remark-lint-no-table-indentation'
remark()
.use(require('remark-lint'))
+ .use(require('remark-lint-no-table-indentation'))
.process('_Emphasis_ and **importance**', function (err, file) {
console.error(report(err || file))
.use(remarkLint)
+ .use(remarkLintNoTableIndentation)
.process('_Emphasis_ and **importance**')
.then((file) => {
console.error(reporter(file))
})

@@ -177,5 +186,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

@@ -204,2 +213,4 @@ [coverage-badge]: https://img.shields.io/codecov/c/github/remarkjs/remark-lint.svg

[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
[npm]: https://docs.npmjs.com/cli/install

@@ -206,0 +217,0 @@

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