remark-lint-no-table-indentation
Advanced tools
Comparing version 3.0.0 to 4.0.0
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 @@ |
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
9647
4
136
226
Yes
6
+ 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-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-location@4.1.0(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-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)
- Removedvfile-location@3.2.0(transitive)
- Removedwrapped@1.0.1(transitive)
Updatedunified-lint-rule@^2.0.0
Updatedunist-util-position@^4.0.0
Updatedunist-util-visit@^4.0.0
Updatedvfile-location@^4.0.0