-
Notifications
You must be signed in to change notification settings - Fork 66.9k
Expand file tree
/
Copy pathliquid-syntax.ts
More file actions
86 lines (82 loc) · 3.35 KB
/
liquid-syntax.ts
File metadata and controls
86 lines (82 loc) · 3.35 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import { describe, expect, test } from 'vitest'
import { runRule } from '../../lib/init-test'
import { frontmatterLiquidSyntax, liquidSyntax } from '../../lib/linting-rules/liquid-syntax'
// Configure the test figure to not split frontmatter and content
const fmOptions = { markdownlintOptions: { frontMatter: null } }
describe(frontmatterLiquidSyntax.names.join(' - '), () => {
test('Frontmatter that contains invalid syntax fails', async () => {
const markdown = [
'---',
'title: "{% ata variables.product.product_name %}"',
'shortTitle: "{% "',
'intro: "{% data reusables.foo.bar }"',
'permissions: "{% if true %}Permission statement"',
'showMiniToc: "{% if true %}Permission statement"',
'---',
].join('\n')
const result = await runRule(frontmatterLiquidSyntax, { strings: { markdown }, ...fmOptions })
const errors = result.markdown
expect(errors.length).toBe(4)
expect(errors.map((error) => error.lineNumber)).toEqual([2, 3, 4, 5])
expect(errors[0].errorRange).toEqual([9, 40])
})
test('Frontmatter that contains valid Liquid passes', async () => {
const markdown = [
'---',
"title: '{% data variables.product.product_name %}'",
'shortTitle:',
"intro: '{% data reusables.foo.bar %}'",
"permissions: '{% if true %}Permission statement{% endif %}'",
'showMiniToc: true',
'---',
].join('\n')
const result = await runRule(liquidSyntax, { strings: { markdown }, ...fmOptions })
const errors = result.markdown
expect(errors.length).toBe(0)
})
})
describe(liquidSyntax.names.join(' - '), () => {
test('Missing closing tag syntax in Markdown content fails', async () => {
const markdown = ['---', 'title: Title', '---', '{% data reusables.foo.bar }'].join('\n')
const result = await runRule(liquidSyntax, { strings: { markdown } })
const errors = result.markdown
expect(errors.length).toBe(1)
expect(errors[0].lineNumber).toBe(4)
expect(errors[0].errorRange).toEqual([1, 27])
})
test('Misspelled data tag in Markdown content fails', async () => {
const markdown = [
'---',
'title: Title',
'---',
'{% ata variables.product.product_name %}',
].join('\n')
const result = await runRule(liquidSyntax, { strings: { markdown } })
const errors = result.markdown
expect(errors.length).toBe(1)
expect(errors[0].lineNumber).toBe(4)
expect(errors[0].errorRange).toEqual([1, 40])
})
test('Missing endif tag in Markdown content fails', async () => {
const markdown = ['---', 'title: Title', '---', '{% if true %}Permission statement'].join('\n')
const result = await runRule(liquidSyntax, { strings: { markdown } })
const errors = result.markdown
expect(errors.length).toBe(1)
expect(errors[0].lineNumber).toBe(4)
expect(errors[0].errorRange).toEqual([1, 33])
})
test('Valid Liquid syntax in Markdown content passes', async () => {
const markdown = [
'---',
'title: "Title"',
'---',
'{% data reusables.foo.bar %}',
'{% if true %}Permission statement{% endif %}',
// Not correct, but not caught by this rule. See liquid-ifversion-tags.
'{% ifversion ghhes %}bla{%endif%}',
].join('\n')
const result = await runRule(liquidSyntax, { strings: { markdown } })
const errors = result.markdown
expect(errors.length).toBe(0)
})
})