Socket
Socket
Sign inDemoInstall

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 2.0.1 to 3.0.0

97

index.js

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

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

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

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

@@ -35,6 +35,27 @@ * Paragraph.

*
* @example {"name": "not-ok.md", "label": "output"}
* @example {"name": "not-ok.md", "label": "output", "gfm": true}
*
* 3:1-3:21: Do not indent table rows
* 5:1-5:21: Do not indent table rows
* 3:4: Do not indent table rows
* 4:4: Do not indent table rows
* 5:4: Do not indent table rows
*
* @example {"name": "not-ok-blockquote.md", "label": "input", "gfm": true}
*
* >··| A |
* >·| - |
*
* @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}
*
* -···paragraph
*
* ·····| A |
* ····| - |
*
* @example {"name": "not-ok-list.md", "label": "output", "gfm": true}
*
* 3:6: Do not indent table rows
*/

@@ -47,3 +68,3 @@

var position = require('unist-util-position')
var generated = require('unist-util-generated')
var vfileLocation = require('vfile-location')

@@ -55,24 +76,62 @@ module.exports = rule('remark-lint:no-table-indentation', noTableIndentation)

function noTableIndentation(tree, file) {
var contents = String(file)
var content = String(file)
var location = vfileLocation(content)
visit(tree, 'table', visitor)
function visitor(node) {
if (!generated(node)) {
node.children.forEach(each)
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++
}
}
return visit.SKIP
}
// In a parent we don’t know, exit.
if (!column || !line) {
return
}
function each(row) {
var fence = contents.slice(
position.start(row).offset,
position.start(row.children[0]).offset
)
while (line <= end) {
offset = location.toOffset({line: line, column: column})
lineColumn = offset
if (fence.indexOf('|') > 1) {
file.message(reason, row)
while (/[ \t]/.test(content.charAt(offset - 1))) {
offset--
}
/* 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(content.charAt(offset))) {
offset++
}
if (lineColumn !== offset) {
file.message(reason, location.toPosition(offset))
}
}
line++
}
return visit.SKIP
}
}

6

package.json
{
"name": "remark-lint-no-table-indentation",
"version": "2.0.1",
"version": "3.0.0",
"description": "remark-lint rule to warn when tables are indented",

@@ -29,7 +29,7 @@ "license": "MIT",

"unified-lint-rule": "^1.0.0",
"unist-util-generated": "^1.1.0",
"unist-util-position": "^3.0.0",
"unist-util-visit": "^2.0.0"
"unist-util-visit": "^2.0.0",
"vfile-location": "^3.0.0"
},
"xo": false
}

@@ -37,2 +37,4 @@ <!--This file is generated-->

Note: this example uses [GFM][].
```markdown

@@ -54,2 +56,4 @@ Paragraph.

Note: this example uses [GFM][].
Note: `·` represents a space.

@@ -68,6 +72,47 @@

```text
3:1-3:21: Do not indent table rows
5:1-5:21: Do not indent table rows
3:4: Do not indent table rows
4:4: Do not indent table rows
5:4: Do not indent table rows
```
##### `not-ok-blockquote.md`
###### In
Note: this example uses [GFM][].
Note: `·` represents a space.
```markdown
>··| A |
>·| - |
```
###### Out
```text
1:4: Do not indent table rows
```
##### `not-ok-list.md`
###### In
Note: this example uses [GFM][].
Note: `·` represents a space.
```markdown
-···paragraph
·····| A |
····| - |
```
###### Out
```text
3:6: Do not indent table rows
```
## Install

@@ -154,5 +199,5 @@

[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

@@ -172,1 +217,3 @@ [npm]: https://docs.npmjs.com/cli/install

[author]: https://wooorm.com
[gfm]: https://github.com/remarkjs/remark-gfm
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