From 36e249cce8639b4d7e5c0c45b4d3615c0c2d2d55 Mon Sep 17 00:00:00 2001 From: Joseph Kato Date: Thu, 9 Jan 2025 12:45:10 -0800 Subject: [PATCH] refactor: re-name struct fields --- internal/core/blueprint.go | 25 +++++++++---------- internal/lint/code.go | 4 +-- testdata/styles/config/blueprints/OpenAPI.yml | 10 ++++---- testdata/styles/config/blueprints/Python.yml | 4 +-- testdata/styles/config/blueprints/Vale.yml | 4 +-- 5 files changed, 23 insertions(+), 24 deletions(-) diff --git a/internal/core/blueprint.go b/internal/core/blueprint.go index bec1ec0b..5d82bb12 100644 --- a/internal/core/blueprint.go +++ b/internal/core/blueprint.go @@ -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. @@ -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. @@ -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") } @@ -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 } @@ -88,7 +87,7 @@ func (b *Blueprint) Apply(f *File) ([]ScopedValues, error) { } found = append(found, ScopedValues{ - Scope: s.Scope, + Scope: s.Name, Values: values, }) } diff --git a/internal/lint/code.go b/internal/lint/code.go index 065725aa..a2bcd0cc 100755 --- a/internal/lint/code.go +++ b/internal/lint/code.go @@ -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 } diff --git a/testdata/styles/config/blueprints/OpenAPI.yml b/testdata/styles/config/blueprints/OpenAPI.yml index adc11460..6fef35de 100644 --- a/testdata/styles/config/blueprints/OpenAPI.yml +++ b/testdata/styles/config/blueprints/OpenAPI.yml @@ -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 diff --git a/testdata/styles/config/blueprints/Python.yml b/testdata/styles/config/blueprints/Python.yml index b3a32a92..6d817dfa 100644 --- a/testdata/styles/config/blueprints/Python.yml +++ b/testdata/styles/config/blueprints/Python.yml @@ -1,3 +1,3 @@ engine: tree-sitter -steps: - - query: (comment)+ @comment +scopes: + - expr: (comment)+ @comment diff --git a/testdata/styles/config/blueprints/Vale.yml b/testdata/styles/config/blueprints/Vale.yml index 6522e6e2..49c84b4d 100644 --- a/testdata/styles/config/blueprints/Vale.yml +++ b/testdata/styles/config/blueprints/Vale.yml @@ -1,3 +1,3 @@ engine: dasel -steps: - - query: description +scopes: + - expr: description