Skip to content

Commit 8ab88af

Browse files
committed
refactor: blueprint -> view
Signed-off-by: Joseph Kato <joseph@jdkato.io>
1 parent b0a597a commit 8ab88af

File tree

19 files changed

+53
-51
lines changed

19 files changed

+53
-51
lines changed

internal/core/config.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ var (
3434
// PipeDir is the default location for Vale's configuration pipeline.
3535
PipeDir = ".vale-config"
3636

37-
VocabDir = filepath.Join(ConfigDir, "vocabularies")
38-
DictDir = filepath.Join(ConfigDir, "dictionaries")
39-
TmplDir = filepath.Join(ConfigDir, "templates")
40-
IgnoreDir = filepath.Join(ConfigDir, "ignore")
41-
ActionDir = filepath.Join(ConfigDir, "actions")
42-
FilterDir = filepath.Join(ConfigDir, "filters")
43-
ScriptDir = filepath.Join(ConfigDir, "scripts")
44-
BlueprintsDir = filepath.Join(ConfigDir, "blueprints")
37+
VocabDir = filepath.Join(ConfigDir, "vocabularies")
38+
DictDir = filepath.Join(ConfigDir, "dictionaries")
39+
TmplDir = filepath.Join(ConfigDir, "templates")
40+
IgnoreDir = filepath.Join(ConfigDir, "ignore")
41+
ActionDir = filepath.Join(ConfigDir, "actions")
42+
FilterDir = filepath.Join(ConfigDir, "filters")
43+
ScriptDir = filepath.Join(ConfigDir, "scripts")
44+
ViewDir = filepath.Join(ConfigDir, "views")
4545
)
4646

4747
// ConfigDirs is a list of all directories that contain user-defined, non-style
@@ -54,7 +54,7 @@ var ConfigDirs = []string{
5454
ActionDir,
5555
ScriptDir,
5656
FilterDir,
57-
BlueprintsDir,
57+
ViewDir,
5858
}
5959

6060
// ConfigVars is a list of all supported environment variables.
@@ -213,10 +213,10 @@ type Config struct {
213213
AcceptedTokens []string `json:"-"` // Project-specific vocabulary (okay)
214214
RejectedTokens []string `json:"-"` // Project-specific vocabulary (avoid)
215215

216-
FallbackPath string `json:"-"`
217-
SecToPat map[string]glob.Glob `json:"-"`
218-
Styles []string `json:"-"`
219-
Blueprints map[string]*Blueprint `json:"-"`
216+
FallbackPath string `json:"-"`
217+
SecToPat map[string]glob.Glob `json:"-"`
218+
Styles []string `json:"-"`
219+
Views map[string]*View `json:"-"`
220220

221221
NLPEndpoint string // An external API to call for NLP-related work.
222222

@@ -245,7 +245,7 @@ func NewConfig(flags *CLIFlags) (*Config, error) {
245245
cfg.TokenIgnores = make(map[string][]string)
246246
cfg.CommentDelimiters = make(map[string][2]string)
247247
cfg.FormatToLang = make(map[string]string)
248-
cfg.Blueprints = make(map[string]*Blueprint)
248+
cfg.Views = make(map[string]*View)
249249
cfg.Paths = []string{}
250250
cfg.ConfigFiles = []string{}
251251

internal/core/ini.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,20 +122,20 @@ var syntaxOpts = map[string]func(string, *ini.Section, *Config) error{
122122
cfg.FormatToLang[label] = sec.Key("Lang").String()
123123
return nil
124124
},
125-
"Blueprint": func(label string, sec *ini.Section, cfg *Config) error {
126-
name := sec.Key("Blueprint").String()
125+
"View": func(label string, sec *ini.Section, cfg *Config) error {
126+
name := sec.Key("View").String()
127127

128-
path := FindConfigAsset(cfg, name+".yml", BlueprintsDir)
128+
path := FindConfigAsset(cfg, name+".yml", ViewDir)
129129
if path == "" {
130-
return fmt.Errorf("blueprint '%s' not found", name)
130+
return fmt.Errorf("view '%s' not found", name)
131131
}
132132

133-
blueprint, err := NewBlueprint(path)
133+
view, err := NewView(path)
134134
if err != nil {
135135
return err
136136
}
137137

138-
cfg.Blueprints[label] = blueprint
138+
cfg.Views[label] = view
139139
return nil
140140
},
141141
}

internal/core/blueprint.go renamed to internal/core/view.go

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
type DaselValue = map[string]any
1616

1717
var blockChompingRegex = regexp.MustCompile(`(\w: )>(-?\s*)`)
18-
var blueprintEngines = []string{"tree-sitter", "dasel"}
18+
var viewEngines = []string{"tree-sitter", "dasel"}
1919

2020
// A Scope is a single query that we want to run against a document.
2121
type Scope struct {
@@ -24,14 +24,16 @@ type Scope struct {
2424
Type string `yaml:"type"`
2525
}
2626

27-
// A Blueprint is a set of queries that we want to run against a document.
27+
// A View is a named, virtual representation of a subset of a file's
28+
// structured content. It is defined by a set of queries that can be
29+
// used to extract specific information from the file.
2830
//
2931
// The supported engines are:
3032
//
3133
// - `tree-sitter`
3234
// - `dasel`
3335
// - `command`
34-
type Blueprint struct {
36+
type View struct {
3537
Engine string `yaml:"engine"`
3638
Scopes []Scope `yaml:"scopes"`
3739
}
@@ -43,34 +45,34 @@ type ScopedValues struct {
4345
Values []string
4446
}
4547

46-
// NewBlueprint creates a new blueprint from the given path.
47-
func NewBlueprint(path string) (*Blueprint, error) {
48-
var blueprint Blueprint
48+
// NewView creates a new blueprint from the given path.
49+
func NewView(path string) (*View, error) {
50+
var view View
4951

5052
data, err := os.ReadFile(path)
5153
if err != nil {
5254
return nil, err
5355
}
5456

55-
err = yaml.Unmarshal(data, &blueprint)
57+
err = yaml.Unmarshal(data, &view)
5658
if err != nil {
5759
return nil, err
5860
}
5961

60-
if blueprint.Engine == "" {
62+
if view.Engine == "" {
6163
return nil, fmt.Errorf("missing parser")
62-
} else if !StringInSlice(blueprint.Engine, blueprintEngines) {
63-
return nil, fmt.Errorf("unsupported parser: %s", blueprint.Engine)
64+
} else if !StringInSlice(view.Engine, viewEngines) {
65+
return nil, fmt.Errorf("unsupported parser: %s", view.Engine)
6466
}
6567

66-
if len(blueprint.Scopes) == 0 {
68+
if len(view.Scopes) == 0 {
6769
return nil, fmt.Errorf("missing queries")
6870
}
6971

70-
return &blueprint, nil
72+
return &view, nil
7173
}
7274

73-
func (b *Blueprint) Apply(f *File) ([]ScopedValues, error) {
75+
func (b *View) Apply(f *File) ([]ScopedValues, error) {
7476
found := []ScopedValues{}
7577

7678
value, err := fileToValue(f)

internal/lint/code.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ import (
1313
"github.com/errata-ai/vale/v3/internal/nlp"
1414
)
1515

16-
func updateQueries(f *core.File, blueprints map[string]*core.Blueprint) ([]core.Scope, error) {
16+
func updateQueries(f *core.File, views map[string]*core.View) ([]core.Scope, error) {
1717
var found []core.Scope
1818

19-
for syntax, blueprint := range blueprints {
19+
for syntax, view := range views {
2020
sec, err := glob.Compile(syntax)
2121
if err != nil {
2222
return nil, err
2323
} else if sec.Match(f.Path) {
24-
found = blueprint.Scopes
24+
found = view.Scopes
2525
}
2626
}
2727

@@ -36,7 +36,7 @@ func (l *Linter) lintCode(f *core.File) error {
3636
}
3737
ignored := l.Manager.Config.IgnoredScopes
3838

39-
found, err := updateQueries(f, l.Manager.Config.Blueprints)
39+
found, err := updateQueries(f, l.Manager.Config.Views)
4040
if err != nil {
4141
return err
4242
} else if len(found) > 0 {

internal/lint/data.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ import (
99
)
1010

1111
func (l *Linter) lintData(f *core.File) error {
12-
for syntax, blueprint := range l.Manager.Config.Blueprints {
12+
for syntax, view := range l.Manager.Config.Views {
1313
sec, err := glob.Compile(syntax)
1414
if err != nil {
1515
return err
1616
} else if sec.Match(f.Path) {
17-
found, berr := blueprint.Apply(f)
17+
found, berr := view.Apply(f)
1818
if berr != nil {
1919
return core.NewE201FromTarget(
2020
berr.Error(),
21-
fmt.Sprintf("Blueprint = %s", blueprint),
21+
fmt.Sprintf("View = %s", view),
2222
l.Manager.Config.RootINI,
2323
)
2424
}

internal/lint/fragment.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func (l *Linter) lintFragments(f *core.File) error {
5858
return err
5959
}
6060

61-
found, err := updateQueries(f, l.Manager.Config.Blueprints)
61+
found, err := updateQueries(f, l.Manager.Config.Views)
6262
if err != nil {
6363
return err
6464
} else if len(found) > 0 {

internal/lint/lint.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,8 @@ func (l *Linter) lintFile(src string) lintResult {
184184
simple := l.Manager.Config.Flags.Simple
185185

186186
// NOTE: This is a sanity check to ensure that we don't run any checks that
187-
// we actually have a blueprint to apply.
188-
hasBlueprints := len(l.Manager.Config.Blueprints) > 0
187+
// we actually have a View to apply.
188+
hasViews := len(l.Manager.Config.Views) > 0
189189

190190
if file.Format == "markup" && !simple { //nolint:gocritic
191191
switch file.NormedExt {
@@ -206,7 +206,7 @@ func (l *Linter) lintFile(src string) lintResult {
206206
case ".org":
207207
err = l.lintOrg(file)
208208
}
209-
} else if file.Format == "data" && !simple && hasBlueprints {
209+
} else if file.Format == "data" && !simple && hasViews {
210210
err = l.lintData(file)
211211
} else if file.Format == "code" && !simple {
212212
err = l.lintCode(file)

testdata/features/blueprints.feature

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
Feature: Blueprints
1+
Feature: Views
22
Scenario: YAML
3-
When I test "blueprints"
3+
When I test "views"
44
Then the output should contain exactly:
55
"""
66
API.yml:3:10:Scopes.Titles:'sample API' should be capitalized

testdata/fixtures/blueprints/.vale.ini renamed to testdata/fixtures/views/.vale.ini

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,21 @@ py = md
77
[*.json]
88
BasedOnStyles = Vale
99

10-
Blueprint = GitHubActions
10+
View = GitHubActions
1111

1212
[*.py]
1313
vale.Annotations = YES
1414

15-
Blueprint = Python
15+
View = Python
1616

1717
[*.{yml,yaml}]
1818
BasedOnStyles = Vale, Scopes
1919

2020
[API.yml]
21-
Blueprint = OpenAPI
21+
View = OpenAPI
2222

2323
[Petstore.yaml]
24-
Blueprint = Petstore
24+
View = Petstore
2525

2626
[Rule.yml]
27-
Blueprint = Vale
27+
View = Vale

0 commit comments

Comments
 (0)