Skip to content

Commit ecbcb3b

Browse files
committed
feat: support for front matter
WIP
1 parent ab50f45 commit ecbcb3b

File tree

10 files changed

+276
-20
lines changed

10 files changed

+276
-20
lines changed

internal/lint/adoc.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ func (l *Linter) lintADoc(f *core.File) error {
4343
return core.NewE100("lintAdoc", errors.New("asciidoctor not found"))
4444
}
4545

46+
err = l.lintMetadata(f)
47+
if err != nil {
48+
return err
49+
}
50+
4651
s, err := l.Transform(f)
4752
if err != nil {
4853
return err

internal/lint/md.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ var reNumericList = regexp.MustCompile(`(?m)^\d+\.`)
3636
func (l Linter) lintMarkdown(f *core.File) error {
3737
var buf bytes.Buffer
3838

39+
err := l.lintMetadata(f)
40+
if err != nil {
41+
return err
42+
}
43+
3944
s, err := l.Transform(f)
4045
if err != nil {
4146
return err

internal/lint/mdx.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ func (l Linter) lintMDX(f *core.File) error {
1616
return core.NewE100("lintMDX", errors.New("mdx2vast not found"))
1717
}
1818

19+
err = l.lintMetadata(f)
20+
if err != nil {
21+
return err
22+
}
23+
1924
s, err := l.Transform(f)
2025
if err != nil {
2126
return err

internal/lint/metadata.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"github.com/errata-ai/vale/v3/internal/nlp"
1212
)
1313

14-
func (l Linter) lintMetadata(f *core.File) error { //nolint:unused
14+
func (l Linter) lintMetadata(f *core.File) error {
1515
metadata := make(map[string]any)
1616

1717
_, err := frontmatter.Parse(strings.NewReader(f.Content), &metadata)

internal/lint/org.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,13 @@ func (l Linter) lintOrg(f *core.File) error {
3939
s = reOrgProps.ReplaceAllString(s, orgExample)
4040

4141
f.Content = s
42-
s, err := l.Transform(f)
42+
43+
err := l.lintMetadata(f)
44+
if err != nil {
45+
return err
46+
}
47+
48+
s, err = l.Transform(f)
4349
if err != nil {
4450
return err
4551
}

internal/lint/rst.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ func (l *Linter) lintRST(f *core.File) error {
4242
return core.NewE100("lintRST", errors.New("rst2html not found"))
4343
}
4444

45+
err := l.lintMetadata(f)
46+
if err != nil {
47+
return err
48+
}
49+
4550
s, err := l.Transform(f)
4651
if err != nil {
4752
return err
Lines changed: 44 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,46 @@
11
Feature: Frontmatter
22

3-
# Scenario: Markup with frontmatter
4-
# When I test "frontmatter"
5-
# Then the output should contain exactly:
6-
# """
7-
# test.md:2:9:Meta.Title:'My document' should be in title case
8-
# test.md:3:23:vale.Annotations:'NOTE' left in text
9-
# test.md:4:19:vale.Annotations:'XXX' left in text
10-
# test.md:9:1:vale.Annotations:'NOTE' left in text
11-
# test.md:38:1:vale.Annotations:'XXX' left in text
12-
# test.md:40:29:vale.Annotations:'TODO' left in text
13-
# test.md:42:3:vale.Annotations:'TODO' left in text
14-
# test.md:42:10:vale.Annotations:'XXX' left in text
15-
# test.md:42:16:vale.Annotations:'FIXME' left in text
16-
# test.md:46:21:vale.Annotations:'FIXME' left in text
17-
# test.md:50:5:vale.Annotations:'TODO' left in text
18-
# test.md:52:3:vale.Annotations:'TODO' left in text
19-
# """
3+
Scenario: Markup with frontmatter
4+
When I test "frontmatter"
5+
Then the output should contain exactly:
6+
"""
7+
test.adoc:3:23:vale.Annotations:'XXX' left in text
8+
test.adoc:4:27:vale.Annotations:'NOTE' left in text
9+
test.adoc:5:13:Meta.Title:'My document' should be in title case
10+
test.adoc:18:39:vale.Annotations:'TODO' left in text
11+
test.adoc:37:27:vale.Annotations:'XXX' left in text
12+
test.adoc:52:1:vale.Annotations:'TODO' left in text
13+
test.adoc:67:1:vale.Annotations:'FIXME' left in text
14+
test.adoc:67:21:vale.Annotations:'TODO' left in text
15+
test.adoc:67:27:vale.Annotations:'XXX' left in text
16+
test.adoc:72:38:vale.Annotations:'XXX' left in text
17+
test.adoc:74:20:vale.Annotations:'TODO' left in text
18+
test.adoc:83:16:vale.Annotations:'TODO' left in text
19+
test.adoc:87:6:vale.Annotations:'NOTE' left in text
20+
test.adoc:94:6:vale.Annotations:'NOTE' left in text
21+
test.md:2:9:Meta.Title:'My document' should be in title case
22+
test.md:3:23:vale.Annotations:'NOTE' left in text
23+
test.md:4:19:vale.Annotations:'XXX' left in text
24+
test.md:9:1:vale.Annotations:'NOTE' left in text
25+
test.md:38:1:vale.Annotations:'XXX' left in text
26+
test.md:40:29:vale.Annotations:'TODO' left in text
27+
test.md:42:3:vale.Annotations:'TODO' left in text
28+
test.md:42:10:vale.Annotations:'XXX' left in text
29+
test.md:42:16:vale.Annotations:'FIXME' left in text
30+
test.md:46:21:vale.Annotations:'FIXME' left in text
31+
test.md:50:5:vale.Annotations:'TODO' left in text
32+
test.md:52:3:vale.Annotations:'TODO' left in text
33+
test.rst:2:10:Meta.Title:'My document' should be in title case
34+
test.rst:3:24:vale.Annotations:'NOTE' left in text
35+
test.rst:4:20:vale.Annotations:'XXX' left in text
36+
test.rst:10:34:vale.Annotations:'XXX' left in text
37+
test.rst:56:19:vale.Annotations:'TODO' left in text
38+
test.rst:64:1:vale.Annotations:'NOTE' left in text
39+
test.rst:66:40:vale.Annotations:'TODO' left in text
40+
test.rst:69:3:vale.Annotations:'TODO' left in text
41+
test.rst:69:29:vale.Annotations:'XXX' left in text
42+
test.rst:75:3:vale.Annotations:'FIXME' left in text
43+
test.rst:81:3:vale.Annotations:'TODO' left in text
44+
test.rst:81:38:vale.Annotations:'XXX' left in text
45+
test.rst:87:10:vale.Annotations:'TODO' left in text
46+
"""
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
StylesPath = ../../styles
22
MinAlertLevel = suggestion
33

4-
[*.{md}]
4+
[*.{md,rst,adoc}]
55
vale.Annotations = YES
66
Meta.Title = YES
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
;;;
2+
{
3+
"author": "John Doe XXX",
4+
"description": "A short NOTE summary of the document's purpose.",
5+
"title": "My document"
6+
}
7+
;;;
8+
9+
Reference code like `TODO` or `methods` inline.
10+
11+
Literal block:
12+
13+
....
14+
XXX = False
15+
# This is a codeblock.
16+
....
17+
18+
Indent the line one space to insert a TODO code snippet
19+
20+
XXX = False
21+
22+
Listing block with title, no syntax highlighting:
23+
24+
.Gemfile.lock
25+
----
26+
// XXX: fix this relatively soon.
27+
func ExtFromSyntax(name string) string {
28+
for XXX, relatively := range LookupSyntaxName {
29+
if matched, _ := regexp.MatchString(r, name); matched {
30+
return s
31+
}
32+
}
33+
return name
34+
}
35+
----
36+
37+
Code block with title and XXX syntax highlighting:
38+
39+
[[app-listing]]
40+
[source,python]
41+
.app.py
42+
----
43+
def foo():
44+
"""
45+
NOTE: this is a very important function.
46+
"""
47+
obviously = False
48+
very = True
49+
return very and obviously
50+
----
51+
52+
TODO: this is not in a block.
53+
54+
[source,go]
55+
----
56+
// XXX: fix this relatively soon.
57+
func ExtFromSyntax(name string) string {
58+
for XXX, relatively := range LookupSyntaxName {
59+
if matched, _ := regexp.MatchString(r, name); matched {
60+
return s
61+
}
62+
}
63+
return name
64+
}
65+
----
66+
67+
FIXME *bold phrase* TODO _XXX_
68+
69+
70+
.Table Title
71+
|===
72+
|Name of Column 1 |Name of Column 2 |XXX
73+
74+
|Cell in column 1, TODO
75+
|Cell in column 2, row 1
76+
|Cell in column 3, row 1
77+
78+
|Cell in column 1, row 2
79+
|Cell in column 2, row 2
80+
|Cell in column 3, row 2
81+
|===
82+
83+
image:logo.png[TODO]
84+
85+
This should not {TODO} raise an alert.
86+
87+
This NOTE should be found.
88+
89+
[source,NOTE]
90+
----
91+
some NOTE
92+
----
93+
94+
This NOTE should be found too.
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
+++
2+
title = "My document"
3+
description = "A short NOTE summary of the document's purpose."
4+
author = "John Doe XXX"
5+
+++
6+
7+
Introduction
8+
########################################
9+
10+
This is a very interesting file. XXX:
11+
12+
.. code-block:: bash
13+
14+
$ brew install very
15+
16+
17+
A MacPorts *port* is also available:
18+
19+
.. code-block:: python
20+
21+
def foo():
22+
"""
23+
NOTE: this is a very important function.
24+
"""
25+
obviously = False
26+
very = True
27+
return very and obviously
28+
29+
As you can see, ``very = True``. Here is another interesting codeblock:
30+
31+
.. code-block:: go
32+
33+
// XXX: fix this relatively soon.
34+
func ExtFromSyntax(name string) string {
35+
for XXX, relatively := range LookupSyntaxName {
36+
if matched, _ := regexp.MatchString(r, name); matched {
37+
return s
38+
}
39+
}
40+
return name
41+
}
42+
43+
A `very` MacPorts *port* is also available: TODO
44+
45+
::
46+
47+
XXX: This is preformatted text.
48+
49+
This is extremely important.
50+
51+
52+
.. highlight:: c
53+
54+
::
55+
56+
printf("%s", "TODO") // TODO:
57+
58+
.. highlight:: none
59+
60+
::
61+
62+
printf("%s", "TODO") // TODO:
63+
64+
NOTE: The block is over by now
65+
66+
The |biohazard| symbol must be used on TODO containers used to dispose of medical waste.
67+
68+
+------------+------------+-----------+
69+
| TODO | Header 2 | XXX |
70+
+============+============+===========+
71+
| body row 1 | column 2 | column 3 |
72+
+------------+------------+-----------+
73+
| body row 2 | Cells may span columns.|
74+
+------------+------------+-----------+
75+
| FIXME | Cells may | - Cells |
76+
+------------+ span rows. | - contain |
77+
| body row 4 | | - blocks. |
78+
+------------+------------+-----------+
79+
80+
81+
**TODO** this is a sentence ``TODO`` XXX.
82+
83+
.. |biohazard| image:: biohazard.png
84+
85+
86+
.. image:: /images/logo.png
87+
:alt: TODO
88+
89+
90+
.. code-block:: text
91+
:caption: /etc/salt/autosign_grains/uuid
92+
93+
def foo():
94+
"""
95+
NOTE: this is a very important function.
96+
"""
97+
obviously = False
98+
very = True
99+
return very and obviously
100+
101+
102+
.. code:: pwsh
103+
104+
& TODO
105+
106+
107+
.. code:: pwsh-session
108+
109+
& TODO

0 commit comments

Comments
 (0)