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
3
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 4.1.2 to 5.0.0

index.d.ts.map

14

index.d.ts

@@ -1,7 +0,7 @@

export default remarkLintNoTableIndentation
export type Root = import('mdast').Root
declare const remarkLintNoTableIndentation: import('unified').Plugin<
void[] | [unknown],
import('mdast').Root,
import('mdast').Root
>
export default remarkLintNoTableIndentation;
export type Root = import('mdast').Root;
declare const remarkLintNoTableIndentation: {
(config?: unknown): ((tree: import("mdast").Root, file: import("vfile").VFile, next: import("unified").TransformCallback<import("mdast").Root>) => undefined) | undefined;
readonly name: string;
};
//# sourceMappingURL=index.d.ts.map
/**
* ## When should I use this?
* remark-lint rule to warn when GFM tables are indented.
*
* You can use this package to check that tables are not indented.
* ## What is this?
*
* This package checks the indent of GFM tables.
* Tables are a GFM feature enabled with
* [`remark-gfm`](https://github.com/remarkjs/remark-gfm).
* [`remark-gfm`][github-remark-gfm].
*
* ## When should I use this?
*
* You can use this package to check that tables are consistent.
*
* ## API
*
* ### `unified().use(remarkLintNoTableIndentation)`
*
* Warn when GFM tables are indented.
*
* ###### Parameters
*
* There are no options.
*
* ###### Returns
*
* Transform ([`Transformer` from `unified`][github-unified-transformer]).
*
* ## Recommendation

@@ -16,63 +32,61 @@ *

* markdown.
* Hence, it’s recommended to not indent tables and to turn this rule on.
* So it’s recommended to not indent tables and to turn this rule on.
*
* ## Fix
*
* [`remark-gfm`](https://github.com/remarkjs/remark-gfm)
* formats all tables without indent.
* [`remark-stringify`][github-remark-stringify] with
* [`remark-gfm`][github-remark-gfm] formats all tables without indent.
*
* [api-remark-lint-no-table-indentation]: #unifieduseremarklintnotableindentation
* [github-remark-gfm]: https://github.com/remarkjs/remark-gfm
* [github-remark-stringify]: https://github.com/remarkjs/remark/tree/main/packages/remark-stringify
* [github-unified-transformer]: https://github.com/unifiedjs/unified#transformer
*
* @module no-table-indentation
* @summary
* remark-lint rule to warn when tables are indented.
* @author Titus Wormer
* @copyright 2015 Titus Wormer
* @license MIT
*
* @example
* {"name": "ok.md", "gfm": true}
*
* Paragraph.
* | Planet | Mean anomaly (°) |
* | ------- | ---------------: |
* | Mercury | 174 796 |
*
* | A | B |
* | ----- | ----- |
* | Alpha | Bravo |
*
* @example
* {"name": "not-ok.md", "label": "input", "gfm": true}
* {"gfm": true, "label": "input", "name": "not-ok.md"}
*
* Paragraph.
* ␠| Planet | Mean anomaly (°) |
* ␠␠| ------- | ---------------: |
* ␠␠␠| Mercury | 174 796 |
*
* ···| A | B |
* ···| ----- | ----- |
* ···| Alpha | Bravo |
*
* @example
* {"name": "not-ok.md", "label": "output", "gfm": true}
* {"gfm": true, "label": "output", "name": "not-ok.md"}
*
* 3:4: Do not indent table rows
* 4:4: Do not indent table rows
* 5:4: Do not indent table rows
* 1:2: Unexpected `1` extra space before table row, remove `1` space
* 2:3: Unexpected `2` extra spaces before table row, remove `2` spaces
* 3:4: Unexpected `3` extra spaces before table row, remove `3` spaces
*
* @example
* {"name": "not-ok-blockquote.md", "label": "input", "gfm": true}
* {"gfm": true, "label": "input", "name": "blockquote.md"}
*
* >··| A |
* >·| - |
* >␠| Planet |
* >␠␠| ------- |
*
* @example
* {"name": "not-ok-blockquote.md", "label": "output", "gfm": true}
* {"gfm": true, "label": "output", "name": "blockquote.md"}
*
* 1:4: Do not indent table rows
* 2:4: Unexpected `1` extra space before table row, remove `1` space
*
* @example
* {"name": "not-ok-list.md", "label": "input", "gfm": true}
* {"gfm": true, "label": "input", "name": "list.md"}
*
* -···paragraph
* *␠| Planet |
* ␠␠␠| ------- |
*
* ·····| A |
* ····| - |
*
* @example
* {"name": "not-ok-list.md", "label": "output", "gfm": true}
* {"gfm": true, "label": "output", "name": "list.md"}
*
* 3:6: Do not indent table rows
* 2:4: Unexpected `1` extra space before table row, remove `1` space
*/

@@ -84,5 +98,8 @@

import {ok as assert} from 'devlop'
import {phrasing} from 'mdast-util-phrasing'
import pluralize from 'pluralize'
import {lintRule} from 'unified-lint-rule'
import {visit, SKIP} from 'unist-util-visit'
import {pointStart, pointEnd} from 'unist-util-position'
import {pointEnd, pointStart} from 'unist-util-position'
import {SKIP, visitParents} from 'unist-util-visit-parents'
import {location} from 'vfile-location'

@@ -95,49 +112,112 @@

},
/** @type {import('unified-lint-rule').Rule<Root, void>} */
(tree, file) => {
/**
* @param {Root} tree
* Tree.
* @returns {undefined}
* Nothing.
*/
function (tree, file) {
const value = String(file)
const loc = location(value)
const locations = location(value)
visit(tree, 'table', (node, _, parent) => {
const end = pointEnd(node).line
let line = pointStart(node).line
let column = 0
// Note: this code is very similar to `remark-lint-no-paragraph-content-indent`.
visitParents(tree, function (node, parents) {
// Do not walk into phrasing.
if (phrasing(node)) {
return SKIP
}
if (parent && parent.type === 'root') {
if (node.type !== 'table') return
const parent = parents.at(-1)
const end = pointEnd(node)
const start = pointStart(node)
if (!parent || !end || !start) return
const parentHead = parent.children[0]
// Always defined if we have a parent.
assert(parentHead)
let line = start.line
/** @type {number | undefined} */
let column
if (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
} else if (parent.type === 'blockquote') {
const parentStart = pointStart(parent)
// 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++
if (parentStart) {
column = parentStart.column + 2
}
}
} else if (parent.type === 'listItem') {
const headStart = pointStart(parentHead)
// In a parent we don’t know, exit.
if (!column || !line) {
return
if (headStart) {
column = headStart.column
// Skip past the first line if we’re the first child of a list item.
if (parentHead === node) {
line++
}
}
}
while (line <= end) {
let offset = loc.toOffset({line, column})
const lineColumn = offset
/* c8 ignore next -- unknown parent. */
if (!column) return
while (/[ \t]/.test(value.charAt(offset - 1))) {
offset--
while (line <= end.line) {
let index = locations.toOffset({line, column})
/* c8 ignore next -- out of range somehow. */
if (typeof index !== 'number') continue
const expected = index
// Check that we only have whitespace / block quote marker before.
// We expect a line ending or a block quote marker.
// Otherwise (weird ancestor or lazy line) we stop.
let code = value.charCodeAt(index - 1)
while (code === 9 /* `\t` */ || code === 32 /* ` ` */) {
index--
code = value.charCodeAt(index - 1)
}
if (!offset || /[\r\n>]/.test(value.charAt(offset - 1))) {
offset = lineColumn
if (
code === 10 /* `\n` */ ||
code === 13 /* `\r` */ ||
code === 62 /* `>` */ ||
Number.isNaN(code)
) {
// Now check superfluous indent.
let actual = expected
while (/[ \t]/.test(value.charAt(offset))) {
offset++
code = value.charCodeAt(actual)
while (code === 9 /* `\t` */ || code === 32 /* ` ` */) {
code = value.charCodeAt(++actual)
}
if (lineColumn !== offset) {
// @ts-expect-error: assume we have a correct point.
file.message('Do not indent table rows', loc.toPoint(offset))
const difference = actual - expected
if (difference !== 0) {
file.message(
'Unexpected `' +
difference +
'` extra ' +
pluralize('space', difference) +
' before table row, remove `' +
difference +
'` ' +
pluralize('space', difference),
{
ancestors: [...parents, node],
place: {
line,
column: column + difference,
offset: actual
}
}
)
}

@@ -144,0 +224,0 @@ }

{
"name": "remark-lint-no-table-indentation",
"version": "4.1.2",
"version": "5.0.0",
"description": "remark-lint rule to warn when tables are indented",
"license": "MIT",
"keywords": [
"indent",
"lint",
"remark",
"lint",
"remark-lint",
"remark-lint-rule",
"rule",
"remark-lint-rule",
"table",
"indent"
"table"
],
"repository": {
"type": "git",
"url": "https://github.com/remarkjs/remark-lint",
"directory": "packages/remark-lint-no-table-indentation"
},
"repository": "https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-no-table-indentation",
"bugs": "https://github.com/remarkjs/remark-lint/issues",

@@ -26,28 +23,38 @@ "funding": {

"contributors": [
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
"Titus Wormer <tituswormer@gmail.com>"
],
"sideEffects": false,
"type": "module",
"main": "index.js",
"types": "index.d.ts",
"exports": "./index.js",
"files": [
"index.d.ts",
"index.d.ts.map",
"index.js"
],
"dependencies": {
"@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"
"@types/mdast": "^4.0.0",
"devlop": "^1.0.0",
"pluralize": "^8.0.0",
"mdast-util-phrasing": "^4.0.0",
"unified-lint-rule": "^3.0.0",
"unist-util-position": "^5.0.0",
"unist-util-visit-parents": "^6.0.0",
"vfile-location": "^5.0.0"
},
"scripts": {},
"xo": false,
"typeCoverage": {
"atLeast": 100,
"detail": true,
"strict": true,
"ignoreCatch": true
"ignoreCatch": true,
"strict": true
},
"xo": {
"prettier": true,
"rules": {
"capitalized-comments": "off",
"complexity": "off",
"unicorn/prefer-code-point": "off",
"unicorn/prefer-switch": "off"
}
}
}

@@ -5,45 +5,43 @@ <!--This file is generated-->

[![Build][build-badge]][build]
[![Coverage][coverage-badge]][coverage]
[![Downloads][downloads-badge]][downloads]
[![Size][size-badge]][size]
[![Sponsors][sponsors-badge]][collective]
[![Backers][backers-badge]][collective]
[![Chat][chat-badge]][chat]
[![Build][badge-build-image]][badge-build-url]
[![Coverage][badge-coverage-image]][badge-coverage-url]
[![Downloads][badge-downloads-image]][badge-downloads-url]
[![Size][badge-size-image]][badge-size-url]
[![Sponsors][badge-funding-sponsors-image]][badge-funding-url]
[![Backers][badge-funding-backers-image]][badge-funding-url]
[![Chat][badge-chat-image]][badge-chat-url]
[`remark-lint`][mono] rule to warn when tables are indented.
[`remark-lint`][github-remark-lint] rule to warn when GFM tables are indented.
## Contents
* [What is this?](#what-is-this)
* [When should I use this?](#when-should-i-use-this)
* [Presets](#presets)
* [Install](#install)
* [Use](#use)
* [API](#api)
* [`unified().use(remarkLintNoTableIndentation[, config])`](#unifieduseremarklintnotableindentation-config)
* [Recommendation](#recommendation)
* [Fix](#fix)
* [Examples](#examples)
* [Compatibility](#compatibility)
* [Contribute](#contribute)
* [License](#license)
* [What is this?](#what-is-this)
* [When should I use this?](#when-should-i-use-this)
* [Presets](#presets)
* [Install](#install)
* [Use](#use)
* [API](#api)
* [`unified().use(remarkLintNoTableIndentation)`](#unifieduseremarklintnotableindentation)
* [Recommendation](#recommendation)
* [Fix](#fix)
* [Examples](#examples)
* [Compatibility](#compatibility)
* [Contribute](#contribute)
* [License](#license)
## What is this?
This package is a [unified][] ([remark][]) plugin, specifically a `remark-lint`
rule.
Lint rules check markdown code style.
This package checks the indent of GFM tables.
Tables are a GFM feature enabled with
[`remark-gfm`][github-remark-gfm].
## When should I use this?
You can use this package to check that tables are not indented.
Tables are a GFM feature enabled with
[`remark-gfm`](https://github.com/remarkjs/remark-gfm).
You can use this package to check that tables are consistent.
## Presets
This rule is included in the following presets:
This plugin is included in the following presets:
| Preset | Setting |
| Preset | Options |
| - | - |

@@ -54,4 +52,5 @@ | [`remark-preset-lint-markdown-style-guide`](https://github.com/remarkjs/remark-lint/tree/main/packages/remark-preset-lint-markdown-style-guide) | |

This package is [ESM only][esm].
In Node.js (version 12.20+, 14.14+, or 16.0+), install with [npm][]:
This package is [ESM only][github-gist-esm].
In Node.js (version 16+),
install with [npm][npm-install]:

@@ -62,13 +61,13 @@ ```sh

In Deno with [`esm.sh`][esmsh]:
In Deno with [`esm.sh`][esm-sh]:
```js
import remarkLintNoTableIndentation from 'https://esm.sh/remark-lint-no-table-indentation@4'
import remarkLintNoTableIndentation from 'https://esm.sh/remark-lint-no-table-indentation@5'
```
In browsers with [`esm.sh`][esmsh]:
In browsers with [`esm.sh`][esm-sh]:
```html
<script type="module">
import remarkLintNoTableIndentation from 'https://esm.sh/remark-lint-no-table-indentation@4?bundle'
import remarkLintNoTableIndentation from 'https://esm.sh/remark-lint-no-table-indentation@5?bundle'
</script>

@@ -82,18 +81,20 @@ ```

```js
import remarkLint from 'remark-lint'
import remarkLintNoTableIndentation from 'remark-lint-no-table-indentation'
import remarkParse from 'remark-parse'
import remarkStringify from 'remark-stringify'
import {read} from 'to-vfile'
import {unified} from 'unified'
import {reporter} from 'vfile-reporter'
import {remark} from 'remark'
import remarkLint from 'remark-lint'
import remarkLintNoTableIndentation from 'remark-lint-no-table-indentation'
main()
const file = await read('example.md')
async function main() {
const file = await remark()
.use(remarkLint)
.use(remarkLintNoTableIndentation)
.process(await read('example.md'))
await unified()
.use(remarkParse)
.use(remarkLint)
.use(remarkLintNoTableIndentation)
.use(remarkStringify)
.process(file)
console.error(reporter(file))
}
console.error(reporter(file))
```

@@ -104,3 +105,3 @@

```sh
remark --use remark-lint --use remark-lint-no-table-indentation example.md
remark --frail --use remark-lint --use remark-lint-no-table-indentation .
```

@@ -126,11 +127,18 @@

This package exports no identifiers.
The default export is `remarkLintNoTableIndentation`.
It exports no additional [TypeScript][typescript] types.
The default export is
[`remarkLintNoTableIndentation`][api-remark-lint-no-table-indentation].
### `unified().use(remarkLintNoTableIndentation[, config])`
### `unified().use(remarkLintNoTableIndentation)`
This rule supports standard configuration that all remark lint rules accept
(such as `false` to turn it off or `[1, options]` to configure it).
Warn when GFM tables are indented.
###### Parameters
There are no options.
###### Returns
Transform ([`Transformer` from `unified`][github-unified-transformer]).
## Recommendation

@@ -140,8 +148,8 @@

markdown.
Hence, it’s recommended to not indent tables and to turn this rule on.
So it’s recommended to not indent tables and to turn this rule on.
## Fix
[`remark-gfm`](https://github.com/remarkjs/remark-gfm)
formats all tables without indent.
[`remark-stringify`][github-remark-stringify] with
[`remark-gfm`][github-remark-gfm] formats all tables without indent.

@@ -154,10 +162,9 @@ ## Examples

> 👉 **Note**: this example uses GFM ([`remark-gfm`][gfm]).
> 👉 **Note**: this example uses
> GFM ([`remark-gfm`][github-remark-gfm]).
```markdown
Paragraph.
| A | B |
| ----- | ----- |
| Alpha | Bravo |
| Planet | Mean anomaly (°) |
| ------- | ---------------: |
| Mercury | 174 796 |
```

@@ -173,12 +180,9 @@

> 👉 **Note**: this example uses GFM ([`remark-gfm`][gfm]).
> 👉 **Note**: this example uses
> GFM ([`remark-gfm`][github-remark-gfm]).
> 👉 **Note**: `·` represents a space.
```markdown
Paragraph.
···| A | B |
···| ----- | ----- |
···| Alpha | Bravo |
␠| Planet | Mean anomaly (°) |
␠␠| ------- | ---------------: |
␠␠␠| Mercury | 174 796 |
```

@@ -189,18 +193,17 @@

```text
3:4: Do not indent table rows
4:4: Do not indent table rows
5:4: Do not indent table rows
1:2: Unexpected `1` extra space before table row, remove `1` space
2:3: Unexpected `2` extra spaces before table row, remove `2` spaces
3:4: Unexpected `3` extra spaces before table row, remove `3` spaces
```
##### `not-ok-blockquote.md`
##### `blockquote.md`
###### In
> 👉 **Note**: this example uses GFM ([`remark-gfm`][gfm]).
> 👉 **Note**: this example uses
> GFM ([`remark-gfm`][github-remark-gfm]).
> 👉 **Note**: `·` represents a space.
```markdown
>··| A |
>·| - |
>␠| Planet |
>␠␠| ------- |
```

@@ -211,18 +214,15 @@

```text
1:4: Do not indent table rows
2:4: Unexpected `1` extra space before table row, remove `1` space
```
##### `not-ok-list.md`
##### `list.md`
###### In
> 👉 **Note**: this example uses GFM ([`remark-gfm`][gfm]).
> 👉 **Note**: this example uses
> GFM ([`remark-gfm`][github-remark-gfm]).
> 👉 **Note**: `·` represents a space.
```markdown
-···paragraph
·····| A |
····| - |
*␠| Planet |
␠␠␠| ------- |
```

@@ -233,3 +233,3 @@

```text
3:6: Do not indent table rows
2:4: Unexpected `1` extra space before table row, remove `1` space
```

@@ -239,14 +239,18 @@

Projects maintained by the unified collective are compatible with all maintained
Projects maintained by the unified collective are compatible with maintained
versions of Node.js.
As of now, that is Node.js 12.20+, 14.14+, and 16.0+.
Our projects sometimes work with older versions, but this is not guaranteed.
When we cut a new major release, we drop support for unmaintained versions of
Node.
This means we try to keep the current release line,
`remark-lint-no-table-indentation@5`,
compatible with Node.js 16.
## Contribute
See [`contributing.md`][contributing] in [`remarkjs/.github`][health] for ways
See [`contributing.md`][github-dotfiles-contributing] in [`remarkjs/.github`][github-dotfiles-health] for ways
to get started.
See [`support.md`][support] for ways to get help.
See [`support.md`][github-dotfiles-support] for ways to get help.
This project has a [code of conduct][coc].
This project has a [code of conduct][github-dotfiles-coc].
By interacting with this repository, organization, or community you agree to

@@ -257,54 +261,58 @@ abide by its terms.

[MIT][license] © [Titus Wormer][author]
[MIT][file-license] © [Titus Wormer][author]
[build-badge]: https://github.com/remarkjs/remark-lint/workflows/main/badge.svg
[api-remark-lint-no-table-indentation]: #unifieduseremarklintnotableindentation
[build]: https://github.com/remarkjs/remark-lint/actions
[author]: https://wooorm.com
[coverage-badge]: https://img.shields.io/codecov/c/github/remarkjs/remark-lint.svg
[badge-build-image]: https://github.com/remarkjs/remark-lint/workflows/main/badge.svg
[coverage]: https://codecov.io/github/remarkjs/remark-lint
[badge-build-url]: https://github.com/remarkjs/remark-lint/actions
[downloads-badge]: https://img.shields.io/npm/dm/remark-lint-no-table-indentation.svg
[badge-chat-image]: https://img.shields.io/badge/chat-discussions-success.svg
[downloads]: https://www.npmjs.com/package/remark-lint-no-table-indentation
[badge-chat-url]: https://github.com/remarkjs/remark/discussions
[size-badge]: https://img.shields.io/bundlephobia/minzip/remark-lint-no-table-indentation.svg
[badge-coverage-image]: https://img.shields.io/codecov/c/github/remarkjs/remark-lint.svg
[size]: https://bundlephobia.com/result?p=remark-lint-no-table-indentation
[badge-coverage-url]: https://codecov.io/github/remarkjs/remark-lint
[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg
[badge-downloads-image]: https://img.shields.io/npm/dm/remark-lint-no-table-indentation.svg
[backers-badge]: https://opencollective.com/unified/backers/badge.svg
[badge-downloads-url]: https://www.npmjs.com/package/remark-lint-no-table-indentation
[collective]: https://opencollective.com/unified
[badge-funding-backers-image]: https://opencollective.com/unified/backers/badge.svg
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg
[badge-funding-sponsors-image]: https://opencollective.com/unified/sponsors/badge.svg
[chat]: https://github.com/remarkjs/remark/discussions
[badge-funding-url]: https://opencollective.com/unified
[unified]: https://github.com/unifiedjs/unified
[badge-size-image]: https://img.shields.io/bundlejs/size/remark-lint-no-table-indentation
[remark]: https://github.com/remarkjs/remark
[badge-size-url]: https://bundlejs.com/?q=remark-lint-no-table-indentation
[mono]: https://github.com/remarkjs/remark-lint
[esm-sh]: https://esm.sh
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
[file-license]: https://github.com/remarkjs/remark-lint/blob/main/license
[esmsh]: https://esm.sh
[github-dotfiles-coc]: https://github.com/remarkjs/.github/blob/main/code-of-conduct.md
[npm]: https://docs.npmjs.com/cli/install
[github-dotfiles-contributing]: https://github.com/remarkjs/.github/blob/main/contributing.md
[health]: https://github.com/remarkjs/.github
[github-dotfiles-health]: https://github.com/remarkjs/.github
[contributing]: https://github.com/remarkjs/.github/blob/main/contributing.md
[github-dotfiles-support]: https://github.com/remarkjs/.github/blob/main/support.md
[support]: https://github.com/remarkjs/.github/blob/main/support.md
[github-gist-esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
[coc]: https://github.com/remarkjs/.github/blob/main/code-of-conduct.md
[github-remark-gfm]: https://github.com/remarkjs/remark-gfm
[license]: https://github.com/remarkjs/remark-lint/blob/main/license
[github-remark-lint]: https://github.com/remarkjs/remark-lint
[author]: https://wooorm.com
[github-remark-stringify]: https://github.com/remarkjs/remark/tree/main/packages/remark-stringify
[gfm]: https://github.com/remarkjs/remark-gfm
[github-unified-transformer]: https://github.com/unifiedjs/unified#transformer
[npm-install]: https://docs.npmjs.com/cli/install
[typescript]: https://www.typescriptlang.org
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