Skip to content

Commit 0e2f8bf

Browse files
committed
eat: support QML sources via qml = qdoc
Signed-off-by: Joseph Kato <joseph@jdkato.io>
1 parent cc710aa commit 0e2f8bf

5 files changed

Lines changed: 72 additions & 0 deletions

File tree

‎internal/core/format.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ var FormatByExtension = map[string][]string{
7777
`\.(?:myst)$`: {".myst", "markup"},
7878
`\.(?:qdoc)$`: {".qdoc", "markup"},
7979
`\.(?:qmd)$`: {".qmd", "markup"},
80+
`\.(?:qml)$`: {".qml", "code"},
8081
`\.(?:org)$`: {".org", "markup"},
8182
`\.(?:php)$`: {".php", "code"},
8283
`\.(?:pl|pm|pod)$`: {".r", "code"},

‎internal/core/util_test.go‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ func TestFormatFromExt(t *testing.T) {
1616
".Rmd": {".md", "markup"},
1717
".rmd": {".md", "markup"},
1818
".R": {".r", "code"},
19+
".qml": {".qml", "code"},
1920
}
2021
m := map[string]string{}
2122
for ext, format := range extToFormat {
@@ -27,6 +28,14 @@ func TestFormatFromExt(t *testing.T) {
2728
t.Errorf("expected = %v, got = %v", format[1], f)
2829
}
2930
}
31+
32+
mapped := map[string]string{"cpp": "qdoc", "qml": "qdoc"}
33+
for _, ext := range []string{".cpp", ".qml"} {
34+
normExt, f := FormatFromExt(ext, mapped)
35+
if normExt != ".qdoc" || f != "fragment" {
36+
t.Errorf("expected = [.qdoc fragment], got = [%v %v]", normExt, f)
37+
}
38+
}
3039
}
3140

3241
func TestPrepText(t *testing.T) {

‎internal/lint/code/lang.go‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ func GetLanguageFromExt(ext string) (*Language, error) {
6161
return Tsx(), nil
6262
case ".proto":
6363
return Protobuf(), nil
64+
case ".qml":
65+
return QML(), nil
6466
case ".yml":
6567
return YAML(), nil
6668
case ".css":

‎internal/lint/code/qml.go‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package code
2+
3+
import (
4+
"regexp"
5+
6+
"github.com/errata-ai/vale/v3/internal/core"
7+
"github.com/smacker/go-tree-sitter/javascript"
8+
)
9+
10+
// QML is parsed with the JavaScript grammar: QML's object syntax isn't valid
11+
// JavaScript, but comments are extras and survive error recovery, which is all
12+
// comment extraction needs.
13+
func QML() *Language {
14+
return &Language{
15+
Delims: regexp.MustCompile(`//|/\*[!*]?|\*/`),
16+
Prefix: cStylePrefix,
17+
Parser: javascript.GetLanguage(),
18+
Queries: []core.Scope{{Name: "", Expr: "(comment) @comment", Type: ""}},
19+
Padding: cStyle,
20+
}
21+
}

‎testdata/e2e/lint.yaml‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,45 @@ cases:
377377
widget.cpp:8:26:T.Tok:'ZQX' in a doc comment
378378
widget.cpp:15:41:T.Tok:'ZQX' in a doc comment
379379
380+
- name: qml-fragments
381+
about: doc comments in QML sources lint as QDoc through `[formats]`;
382+
the QML code itself is never prose
383+
files:
384+
.vale.ini: |
385+
StylesPath = styles
386+
MinAlertLevel = suggestion
387+
388+
[formats]
389+
qml = qdoc
390+
391+
[*.qml]
392+
T.Tok = YES
393+
styles/T/Tok.yml: |
394+
extends: existence
395+
message: "'%s' in a doc comment"
396+
level: error
397+
nonword: true
398+
raw:
399+
- ZQX
400+
Button.qml: |
401+
import QtQuick
402+
403+
/*!
404+
\qmltype Button
405+
\brief A ZQX in the brief.
406+
407+
\section1 A ZQX heading
408+
*/
409+
Button {
410+
// A ZQX in a line comment stays code.
411+
width: ZQX
412+
}
413+
args: Button.qml
414+
exit: 1
415+
want: |
416+
Button.qml:5:14:T.Tok:'ZQX' in a doc comment
417+
Button.qml:7:17:T.Tok:'ZQX' in a doc comment
418+
380419
- name: quarto
381420
about: "#793 -- fenced divs, attributes, and shortcodes are markup, div
382421
content is linted, and code cells stay skipped, options and all"

0 commit comments

Comments
 (0)