Skip to content

Commit

Permalink
refactor: re-name struct fields
Browse files Browse the repository at this point in the history
  • Loading branch information
jdkato committed Jan 9, 2025
1 parent 462ecd7 commit 36e249c
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 24 deletions.
25 changes: 12 additions & 13 deletions internal/core/blueprint.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@ import (

type DaselValue = map[string]any

var blueprintEngines = []string{"tree-sitter", "dasel", "command"}
var blueprintEngines = []string{"tree-sitter", "dasel"}

// A Step is a single query that we want to run against a document.
//
// The result of the query is optionally assigned the given scope.
type Step struct {
Scope string `yaml:"scope"`
Query string `yaml:"query"`
// 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"`
}

// A Blueprint is a set of queries that we want to run against a document.
Expand All @@ -31,8 +30,8 @@ type Step struct {
// - `dasel`
// - `command`
type Blueprint struct {
Engine string `yaml:"engine"`
Steps []Step `yaml:"steps"`
Engine string `yaml:"engine"`
Scopes []Scope `yaml:"scopes"`
}

// A ScopedValues is a value that has been assigned a scope.
Expand Down Expand Up @@ -61,7 +60,7 @@ func NewBlueprint(path string) (*Blueprint, error) {
return nil, fmt.Errorf("unsupported parser: %s", blueprint.Engine)
}

if len(blueprint.Steps) == 0 {
if len(blueprint.Scopes) == 0 {
return nil, fmt.Errorf("missing queries")
}

Expand All @@ -76,8 +75,8 @@ func (b *Blueprint) Apply(f *File) ([]ScopedValues, error) {
return nil, NewE100(f.Path, err)
}

for _, s := range b.Steps {
selected, verr := dasel.Select(value, s.Query)
for _, s := range b.Scopes {
selected, verr := dasel.Select(value, s.Expr)
if verr != nil {
return found, verr
}
Expand All @@ -88,7 +87,7 @@ func (b *Blueprint) Apply(f *File) ([]ScopedValues, error) {
}

found = append(found, ScopedValues{
Scope: s.Scope,
Scope: s.Name,
Values: values,
})
}
Expand Down
4 changes: 2 additions & 2 deletions internal/lint/code.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ func updateQueries(f *core.File, blueprints map[string]*core.Blueprint) ([]strin
return nil, err
} else if sec.Match(f.Path) {
found := []string{}
for _, query := range blueprint.Steps {
found = append(found, query.Query)
for _, query := range blueprint.Scopes {
found = append(found, query.Expr)
}
return found, nil
}
Expand Down
10 changes: 5 additions & 5 deletions testdata/styles/config/blueprints/OpenAPI.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
engine: dasel
steps:
- scope: title
query: info.title
- query: info.description
- query: servers.all().description
scopes:
- name: title
expr: info.title
- expr: info.description
- expr: servers.all().description
4 changes: 2 additions & 2 deletions testdata/styles/config/blueprints/Python.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
engine: tree-sitter
steps:
- query: (comment)+ @comment
scopes:
- expr: (comment)+ @comment
4 changes: 2 additions & 2 deletions testdata/styles/config/blueprints/Vale.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
engine: dasel
steps:
- query: description
scopes:
- expr: description

0 comments on commit 36e249c

Please sign in to comment.