Skip to content

Commit eec2f59

Browse files
committed
fix: read a .qdocinc as the include it is, and keep meta out of prose
Signed-off-by: Joseph Kato <joseph@jdkato.io>
1 parent 7618d04 commit eec2f59

3 files changed

Lines changed: 107 additions & 1 deletion

File tree

‎internal/lint/ast.go‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ func (l *Linter) lintScope(f *core.File, state *walker, txt string) error {
278278
if core.StringInSlice("data", state.tagHistory) {
279279
f.Metrics["meta"]++
280280

281-
b := state.block(txt, withClasses("meta", state)+f.MetaScope+f.RealExt, 0)
281+
b := state.block(txt, withClasses("meta", state)+metaScope(f)+f.RealExt, 0)
282282
return l.lintBlock(f, b, state.lines, 0, false)
283283
}
284284

@@ -399,6 +399,19 @@ func seek(s, text string, from int) (int, int) {
399399
// carrying no distinct tag can still be selected. An AsciiDoc block title is a
400400
// `<div class="title">`, indistinguishable from body text by tag alone, and
401401
// becomes `text.class.title` here. See #642.
402+
// metaScope is the context a fragment carries, with the `text` it opens with
403+
// taken off.
404+
//
405+
// MetaScope is appended to every block's scope, and a comment's is
406+
// `text.comment.line`. A selector matches on the set of sections a scope has,
407+
// so appending that to `meta` puts `text` back and an ordinary rule matches
408+
// the content `meta` exists to hold apart -- the same QDoc comment lints
409+
// differently in a `.qdoc` file, where there is no MetaScope, than in the C++
410+
// source it was written in. See #784.
411+
func metaScope(f *core.File) string {
412+
return strings.TrimPrefix(f.MetaScope, ".text")
413+
}
414+
402415
func withClasses(scope string, state *walker) string {
403416
classes := state.classes()
404417
if len(classes) == 0 {

‎internal/lint/qdoc.go‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,16 @@ func qdocConvert(content string, inComment bool) string {
654654
}
655655

656656
// lintQDoc lints a QDoc source: Qt's documentation markup.
657+
//
658+
// A `.qdocinc` is the exception. It is an include -- the body of a comment,
659+
// pulled into a document by `\include` -- so its markup is not wrapped in
660+
// `/*! ... */`, and reading it as a `.qdoc` file leaves the whole thing
661+
// unread while waiting for a comment to open. Starting inside one reads both
662+
// shapes: a `/*!` still opens a comment where the file writes one. See #784.
657663
func (l *Linter) lintQDoc(f *core.File) error {
664+
if f.RealExt == ".qdocinc" {
665+
return l.lintQDocWith(f, qdocFragmentToHTML)
666+
}
658667
return l.lintQDocWith(f, qdocToHTML)
659668
}
660669

‎testdata/e2e/lint.yaml‎

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,90 @@ cases:
702702
widget.cpp:6:23:T.Tok:'ZQX' in a doc comment
703703
widget.cpp:8:26:T.Tok:'ZQX' in a doc comment
704704
705+
- name: qdocinc-include
706+
about: "a `.qdocinc` is an include, not a file of comments: its markup is
707+
the body of one, so nothing waits for a `/*!` that the file never
708+
writes, and a `//! [name]` marker is still markup"
709+
files:
710+
.vale.ini: |
711+
StylesPath = styles
712+
MinAlertLevel = suggestion
713+
714+
[*.qdocinc]
715+
T.Tok = YES
716+
styles/T/Tok.yml: |
717+
extends: existence
718+
message: "'%s'"
719+
level: error
720+
nonword: true
721+
raw:
722+
- ZQX
723+
steps.qdocinc: |
724+
//! [intro]
725+
\note A ZQX in an included note.
726+
//! [intro]
727+
728+
A ZQX in an included paragraph.
729+
wrapped.qdocinc: |
730+
/*!
731+
A ZQX in an include that writes the comment out.
732+
*/
733+
args: .
734+
exit: 1
735+
want: |
736+
steps.qdocinc:2:13:T.Tok:'ZQX'
737+
steps.qdocinc:5:3:T.Tok:'ZQX'
738+
wrapped.qdocinc:2:7:T.Tok:'ZQX'
739+
740+
- name: qdoc-meta-in-source
741+
about: "the same comment lints the same way wherever it is written: an
742+
image file name is `meta` in a C++ source as much as in a `.qdoc` file,
743+
so an ordinary rule passes over it and a `meta` rule reaches it"
744+
files:
745+
.vale.ini: |
746+
StylesPath = styles
747+
MinAlertLevel = suggestion
748+
749+
[formats]
750+
cpp = qdoc
751+
752+
[*.{qdoc,cpp}]
753+
T.Prose = YES
754+
T.Image = YES
755+
styles/T/Prose.yml: |
756+
extends: existence
757+
message: "'%s' as prose"
758+
level: error
759+
nonword: true
760+
raw:
761+
- ZQX
762+
styles/T/Image.yml: |
763+
extends: existence
764+
message: "'%s' in a file name"
765+
scope: meta.class.image
766+
level: error
767+
nonword: true
768+
raw:
769+
- ZQX
770+
same.qdoc: |
771+
/*!
772+
\image ZQX-diagram.png A caption with a ZQX in it.
773+
*/
774+
widget.cpp: |
775+
#include "widget.h"
776+
777+
/*!
778+
\image ZQX-diagram.png A caption with a ZQX in it.
779+
*/
780+
void Widget::clicked() {}
781+
args: .
782+
exit: 1
783+
want: |
784+
same.qdoc:2:12:T.Image:'ZQX' in a file name
785+
same.qdoc:2:45:T.Prose:'ZQX' as prose
786+
widget.cpp:4:12:T.Image:'ZQX' in a file name
787+
widget.cpp:4:45:T.Prose:'ZQX' as prose
788+
705789
- name: qml-fragments
706790
about: doc comments in QML sources lint as QDoc through `[formats]`;
707791
the QML code itself -- objects, bindings, functions, strings, line

0 commit comments

Comments
 (0)