Skip to content

Commit

Permalink
refactor: support assigning markup type per-scope
Browse files Browse the repository at this point in the history
  • Loading branch information
jdkato committed Jan 9, 2025
1 parent 36e249c commit f65c0bf
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 16 deletions.
2 changes: 2 additions & 0 deletions internal/core/blueprint.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type Blueprint struct {
// A ScopedValues is a value that has been assigned a scope.
type ScopedValues struct {
Scope string
Format string
Values []string
}

Expand Down Expand Up @@ -89,6 +90,7 @@ func (b *Blueprint) Apply(f *File) ([]ScopedValues, error) {
found = append(found, ScopedValues{
Scope: s.Name,
Values: values,
Format: s.Type,
})
}

Expand Down
5 changes: 5 additions & 0 deletions internal/core/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,11 @@ func (f *File) SetText(s string) {
f.history = map[string]int{}
}

// SetNormedExt sets the normalized extension of a File.
func (f *File) SetNormedExt(ext string) {
f.NormedExt = "." + ext
}

// AddAlert calculates the in-text location of an Alert and adds it to a File.
func (f *File) AddAlert(a Alert, blk nlp.Block, lines, pad int, lookup bool) {
ctx := blk.Context
Expand Down
23 changes: 12 additions & 11 deletions internal/lint/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,28 +38,29 @@ func (l *Linter) lintScopedValues(f *core.File, values []core.ScopedValues) erro
last := 0
index := 0

for _, matches := range values {
l.SetMetaScope(matches.Scope)
for _, v := range matches.Values {
for _, match := range values {
l.SetMetaScope(match.Scope)
for _, v := range match.Values {
i, line := findLineBySubstring(wholeFile, v, index)
if i == 0 {
return core.NewE100(f.Path, fmt.Errorf("'%s' not found", v))
}

index = i

f.SetText(v)
f.SetNormedExt(match.Format)

switch f.NormedExt {
case ".md":
switch match.Format {
case "md":
err = l.lintMarkdown(f)
case ".rst":
case "rst":
err = l.lintRST(f)
case ".xml":
err = l.lintADoc(f)
case ".html":
case "html":
err = l.lintHTML(f)
case ".org":
case "org":
err = l.lintOrg(f)
case "adoc":
err = l.lintADoc(f)
default:
err = l.lintLines(f)
}
Expand Down
4 changes: 2 additions & 2 deletions internal/lint/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,12 +274,12 @@ func (l *Linter) lintProse(f *core.File, blk nlp.Block, lines int) error {
}

func (l *Linter) lintTxt(f *core.File) error {
block := nlp.NewBlock("", f.Content, "text"+f.RealExt)
block := nlp.NewBlock("", f.Content, "text"+l.metaScope+f.RealExt)
return l.lintProse(f, block, len(f.Lines))
}

func (l *Linter) lintLines(f *core.File) error {
block := nlp.NewBlock("", f.Content, "text"+f.RealExt)
block := nlp.NewBlock("", f.Content, "text"+l.metaScope+f.RealExt)
return l.lintBlock(f, block, len(f.Lines), 0, true)
}

Expand Down
3 changes: 0 additions & 3 deletions testdata/fixtures/blueprints/.vale.ini
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
StylesPath = ../../styles
MinAlertLevel = suggestion

[formats]
yml = md

[*.py]
vale.Annotations = YES

Expand Down
4 changes: 4 additions & 0 deletions testdata/styles/config/blueprints/OpenAPI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@ engine: dasel
scopes:
- name: title
expr: info.title

- expr: info.description
type: md

- expr: servers.all().description
type: md

0 comments on commit f65c0bf

Please sign in to comment.