-
Notifications
You must be signed in to change notification settings - Fork 66.9k
Expand file tree
/
Copy pathcode-fence-line-length.ts
More file actions
50 lines (48 loc) · 1.8 KB
/
code-fence-line-length.ts
File metadata and controls
50 lines (48 loc) · 1.8 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
import { describe, expect, test } from 'vitest'
import { runRule } from '../../lib/init-test'
import { codeFenceLineLength } from '../../lib/linting-rules/code-fence-line-length'
describe(codeFenceLineLength.names.join(' - '), () => {
test('line length of max + 1 fails', async () => {
const markdown = [
'```shell',
'111',
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
'bbb',
'```',
].join('\n')
const result = await runRule(codeFenceLineLength, { strings: { markdown } })
const errors = result.markdown
expect(errors.length).toBe(1)
expect(errors[0].lineNumber).toBe(3)
expect(errors[0].errorRange).toEqual([1, 61])
expect(errors[0].fixInfo).toBeNull()
})
test('line length less than or equal to max length passes', async () => {
const markdown = [
'```javascript',
'111',
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
'```',
].join('\n')
const result = await runRule(codeFenceLineLength, { strings: { markdown } })
const errors = result.markdown
expect(errors.length).toBe(0)
})
test('multiple lines in code block that exceed max length fail', async () => {
const markdown = [
'```',
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaccc',
'1',
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbb',
'```',
].join('\n')
const result = await runRule(codeFenceLineLength, { strings: { markdown } })
const errors = result.markdown
expect(errors.length).toBe(2)
expect(errors[0].lineNumber).toBe(2)
expect(errors[1].lineNumber).toBe(4)
expect(errors[0].errorRange).toEqual([1, 61])
expect(errors[1].errorRange).toEqual([1, 61])
})
})