Skip to content

Commit 45aeac2

Browse files
committedJan 19, 2024
Add better messages, rewrite and improve rules
1 parent ccea691 commit 45aeac2

File tree

192 files changed

+8772
-4455
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

192 files changed

+8772
-4455
lines changed
 

‎package.json

+1
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@
133133
"remark-cli": "^12.0.0",
134134
"remark-comment-config": "^8.0.0",
135135
"remark-directive": "^3.0.0",
136+
"remark-frontmatter": "^5.0.0",
136137
"remark-gfm": "^4.0.0",
137138
"remark-github": "^12.0.0",
138139
"remark-math": "^6.0.0",

‎packages/remark-lint-blockquote-indentation/index.js

+68-37
Original file line numberDiff line numberDiff line change
@@ -65,41 +65,52 @@
6565
* @author Titus Wormer
6666
* @copyright 2015 Titus Wormer
6767
* @license MIT
68+
*
6869
* @example
69-
* {"name": "ok.md", "config": 4}
70+
* {"config": 2, "name": "ok-2.md"}
71+
*
72+
* > Mercury.
7073
*
71-
* > Hello
74+
* Venus.
7275
*
73-
* Paragraph.
76+
* > Earth.
7477
*
75-
* > World
7678
* @example
77-
* {"name": "ok.md", "config": 2}
79+
* {"config": 4, "name": "ok-4.md"}
7880
*
79-
* > Hello
81+
* > Mercury.
8082
*
81-
* Paragraph.
83+
* Venus.
8284
*
83-
* > World
85+
* > Earth.
8486
*
8587
* @example
86-
* {"name": "not-ok.md", "label": "input"}
88+
* { "name": "ok-tab.md"}
89+
*
90+
* >␉Mercury.
8791
*
88-
* > Hello
92+
* @example
93+
* {"label": "input", "name": "not-ok.md"}
8994
*
90-
* Paragraph.
95+
* > Mercury.
9196
*
92-
* > World
97+
* Venus.
9398
*
94-
* Paragraph.
99+
* > Earth.
95100
*
96-
* > World
101+
* Mars.
97102
*
103+
* > Jupiter
98104
* @example
99-
* {"name": "not-ok.md", "label": "output"}
105+
* {"label": "output", "name": "not-ok.md"}
106+
*
107+
* 5:5: Unexpected `4` spaces between block quote marker and content, expected `3` spaces, remove `1` space
108+
* 9:3: Unexpected `2` spaces between block quote marker and content, expected `3` spaces, add `1` space
100109
*
101-
* 5:5: Remove 1 space between block quote and content
102-
* 9:3: Add 1 space between block quote and content
110+
* @example
111+
* {"config": "🌍", "label": "output", "name": "not-ok-options.md", "positionless": true}
112+
*
113+
* 1:1: Unexpected value `🌍` for `options`, expected `number` or `'consistent'`
103114
*/
104115

105116
/**
@@ -114,7 +125,7 @@
114125
import pluralize from 'pluralize'
115126
import {lintRule} from 'unified-lint-rule'
116127
import {pointStart} from 'unist-util-position'
117-
import {visit} from 'unist-util-visit'
128+
import {visitParents} from 'unist-util-visit-parents'
118129

119130
const remarkLintBlockquoteIndentation = lintRule(
120131
{
@@ -130,33 +141,53 @@ const remarkLintBlockquoteIndentation = lintRule(
130141
* Nothing.
131142
*/
132143
function (tree, file, options) {
133-
let option = options || 'consistent'
144+
/** @type {number | undefined} */
145+
let expected
146+
147+
if (options === null || options === undefined || options === 'consistent') {
148+
// Empty.
149+
} else if (typeof options === 'number') {
150+
expected = options
151+
} else {
152+
file.fail(
153+
'Unexpected value `' +
154+
options +
155+
"` for `options`, expected `number` or `'consistent'`"
156+
)
157+
}
134158

135-
visit(tree, 'blockquote', function (node) {
159+
visitParents(tree, 'blockquote', function (node, parents) {
136160
const start = pointStart(node)
137-
const head = pointStart(node.children[0])
161+
const headStart = pointStart(node.children[0])
138162

139-
if (head && start) {
140-
const count = head.column - start.column
163+
if (headStart && start) {
164+
const actual = headStart.column - start.column
141165

142-
if (option === 'consistent') {
143-
option = count
144-
} else {
145-
const diff = option - count
146-
147-
if (diff !== 0) {
148-
const abs = Math.abs(diff)
166+
if (expected) {
167+
const difference = expected - actual
168+
const differenceAbsolute = Math.abs(difference)
149169

170+
if (difference !== 0) {
150171
file.message(
151-
(diff > 0 ? 'Add' : 'Remove') +
152-
' ' +
153-
abs +
154-
' ' +
155-
pluralize('space', abs) +
156-
' between block quote and content',
157-
head
172+
'Unexpected `' +
173+
actual +
174+
'` ' +
175+
pluralize('space', actual) +
176+
' between block quote marker and content, expected `' +
177+
expected +
178+
'` ' +
179+
pluralize('space', expected) +
180+
', ' +
181+
(difference > 0 ? 'add' : 'remove') +
182+
' `' +
183+
differenceAbsolute +
184+
'` ' +
185+
pluralize('space', differenceAbsolute),
186+
{ancestors: [...parents, node], place: headStart}
158187
)
159188
}
189+
} else {
190+
expected = actual
160191
}
161192
}
162193
})

0 commit comments

Comments
 (0)
Please sign in to comment.