-
Notifications
You must be signed in to change notification settings - Fork 66.9k
Expand file tree
/
Copy pathlink-punctuation.ts
More file actions
55 lines (50 loc) · 1.96 KB
/
link-punctuation.ts
File metadata and controls
55 lines (50 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { describe, expect, test } from 'vitest'
import { runRule } from '../../lib/init-test'
import { linkPunctuation } from '../../lib/linting-rules/link-punctuation'
describe(linkPunctuation.names.join(' - '), () => {
test('inline links without quotes or a period should not error', async () => {
const markdown = [
'[This should pass](./image.png)',
'[AUTOTITLE](./image.png)',
// These are not necessarily good descriptions, but they are valid
// per the requirements of the rule
"[A link with end quote'](./image.png)",
'["A link with start quote](./image.png)',
'[A link with a question mark?](./image.png)',
'[A link with an exclamation point!](./image.png)',
].join('\n')
const result = await runRule(linkPunctuation, { strings: { markdown } })
const errors = result.markdown
expect(errors.length).toBe(0)
})
test('inline links with quotes or punctuation should error', async () => {
const markdown = [
'["A title"](./image.png)',
"['A title'](./image.png)",
'[A title.](./image.png)',
'["A title."](./image.png)',
'["A title".](./image.png)',
"['A title.'](./image.png)",
"['A title'.](./image.png)",
"['A title'?](./image.png)",
'["A title"!](./image.png)',
"['A title?'](./image.png)",
'["A title!"](./image.png)',
].join('\n')
const result = await runRule(linkPunctuation, { strings: { markdown } })
const errors = result.markdown
expect(errors.length).toBe(11)
expect(errors[0].errorRange).toEqual([2, 9])
expect(errors[6].lineNumber).toBe(7)
})
test('links that is not plain text', async () => {
const markdown = [
'[*emphasize*](./image.png)',
'[**boldness**](./image.png)',
'[**boldness** and *emphasize*](./image.png)',
].join('\n')
const result = await runRule(linkPunctuation, { strings: { markdown } })
const errors = result.markdown
expect(errors.length).toBe(0)
})
})