-
Notifications
You must be signed in to change notification settings - Fork 66.9k
Expand file tree
/
Copy pathinternal-links-slash.ts
More file actions
executable file
·48 lines (46 loc) · 1.64 KB
/
internal-links-slash.ts
File metadata and controls
executable file
·48 lines (46 loc) · 1.64 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
import { describe, expect, test } from 'vitest'
import { runRule } from '../../lib/init-test'
import { internalLinksSlash } from '../../lib/linting-rules/internal-links-slash'
describe(internalLinksSlash.names.join(' - '), () => {
test('relative links that do not start with / fail', async () => {
const markdown = [
'# heading',
'[GitHub Actions Quickstart](actions/quickstart.md)',
'',
'[GitHub Actions Quickstart](en/quickstart.md)',
].join('\n')
const result = await runRule(internalLinksSlash, { strings: { markdown } })
const errors = result.markdown
expect(errors.length).toBe(2)
expect(errors.map((error) => error.lineNumber)).toEqual([2, 4])
expect(errors[0].errorRange).toEqual([29, 21])
expect(errors[1].errorRange).toEqual([29, 16])
expect(errors[0].fixInfo).toEqual({
deleteCount: 0,
editColumn: 29,
insertText: '/',
lineNumber: 2,
})
expect(errors[1].fixInfo).toEqual({
deleteCount: 0,
editColumn: 29,
insertText: '/',
lineNumber: 4,
})
})
test('relative links that start with / pass', async () => {
const markdown = [
'Hello [GitHub Actions](/actions/index.md)',
'- "[Actions](/actions/index.md)"',
// Not a relative page link
'[Anchor on page](#anchor-on-page)',
// Not internal links
'[External Link](https://git-scm.com/)',
'[External link](http://example.com)',
'[External Link](mailto:email@example.com)',
].join('\n')
const result = await runRule(internalLinksSlash, { strings: { markdown } })
const errors = result.markdown
expect(errors.length).toBe(0)
})
})