Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions internal/core/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ var viewEngines = []string{"tree-sitter", "dasel"}

// A Scope is a single query that we want to run against a document.
type Scope struct {
Name string `yaml:"name"`
Expr string `yaml:"expr"`
Type string `yaml:"type"`
Name string `yaml:"name"`
Expr string `yaml:"expr"`
Type string `yaml:"type"`
Ignore []string `yaml:"ignore"` // rules to skip for this scope
}

// A View is a named, virtual representation of a subset of a file's
Expand All @@ -43,6 +44,7 @@ type ScopedValues struct {
Scope string
Format string
Values []string
Ignore []string // rules to skip for this scope
}

// NewView creates a new blueprint from the given path.
Expand Down Expand Up @@ -95,6 +97,7 @@ func (b *View) Apply(f *File) ([]ScopedValues, error) {
Scope: s.Name,
Values: values,
Format: s.Type,
Ignore: s.Ignore,
})
}

Expand Down
4 changes: 4 additions & 0 deletions internal/lint/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func (l *Linter) lintScopedValues(f *core.File, values []core.ScopedValues) erro

for _, match := range values {
l.SetMetaScope(match.Scope)
l.SetScopeIgnore(match.Ignore)

seen := make(map[string]int)
for _, v := range match.Values {
Expand Down Expand Up @@ -75,5 +76,8 @@ func (l *Linter) lintScopedValues(f *core.File, values []core.ScopedValues) erro
}
}

// Reset scope-specific ignores to avoid affecting other linting paths.
l.SetScopeIgnore(nil)

return err
}
33 changes: 27 additions & 6 deletions internal/lint/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ import (

// A Linter lints a File.
type Linter struct {
Manager *check.Manager
glob *glob.Glob
client *http.Client
HasDir bool
nonGlobal bool
metaScope string
Manager *check.Manager
glob *glob.Glob
client *http.Client
HasDir bool
nonGlobal bool
metaScope string
scopeIgnore []string // rules to skip for the current scope
}

type lintResult struct {
Expand Down Expand Up @@ -80,6 +81,21 @@ func (l *Linter) SetMetaScope(scope string) {
}
}

// SetScopeIgnore sets the list of rules to ignore for the current scope.
func (l *Linter) SetScopeIgnore(ignore []string) {
l.scopeIgnore = ignore
}

// isScopeIgnored checks if a rule should be ignored for the current scope.
func (l *Linter) isScopeIgnored(name string) bool {
for _, ignored := range l.scopeIgnore {
if ignored == name {
return true
}
}
return false
}

// Lint src according to its format.
func (l *Linter) Lint(input []string, pat string) ([]*core.File, error) {
var linted []*core.File
Expand Down Expand Up @@ -303,6 +319,11 @@ func (l *Linter) shouldRun(name string, f *core.File, chk check.Rule, blk nlp.Bl
name = strings.Join([]string{list[0], list[1]}, ".")
}

// Has the check been ignored for the current scope (e.g., YAML key)?
if l.isScopeIgnored(name) {
return false
}

chkScope := check.NewScope(details.Scope)
if f.QueryComments(name) { //nolint:gocritic
// It has been disabled via an in-text comment.
Expand Down
2 changes: 2 additions & 0 deletions testdata/features/views.feature
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ Feature: Views
github-workflow.json:494:264:Vale.Spelling:Did you really mean 'prereleased'?
github-workflow.json:568:83:Vale.Spelling:Did you really mean 'job_id'?
github-workflow.json:652:83:Vale.Spelling:Did you really mean 'job_id'?
ignore.yml:3:24:Vale.Spelling:Did you really mean 'tset'?
ignore.yml:3:48:Vale.Spelling:Did you really mean 'speling'?
test.java:13:38:vale.Annotations:'XXX' left in text
test.py:1:3:vale.Annotations:'FIXME' left in text
test.py:11:3:vale.Annotations:'XXX' left in text
Expand Down
5 changes: 5 additions & 0 deletions testdata/fixtures/views/.vale.ini
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,8 @@ View = NewLine
BasedOnStyles = Vale, Scopes

View = Ansible

[ignore.yml]
BasedOnStyles = Vale

View = Ignore
3 changes: 3 additions & 0 deletions testdata/fixtures/views/ignore.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name: tset-resurce
kind: DeplymentConfig
description: This is a tset description with a speling error.
18 changes: 18 additions & 0 deletions testdata/styles/config/views/Ignore.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
engine: dasel
scopes:
# Extract 'name' field - ignore spelling errors
- name: metadata
expr: name
ignore:
- Vale.Spelling

# Extract 'kind' field - ignore spelling errors
- name: metadata
expr: kind
ignore:
- Vale.Spelling

# Extract 'description' field - all rules apply
- name: content
expr: description
type: md