Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spell incantation for "github.com/golangci/golangci-lint" Go module #34

Merged
merged 1 commit into from
Nov 24, 2020
Merged
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
6 changes: 4 additions & 2 deletions pkg/cast/gobin/gobin.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// Copyright (c) 2019-present Sven Greb <[email protected]>
// This source code is licensed under the MIT license found in the LICENSE file.

// Package gobin provides a caster to install and run Go module executables using the "github.com/myitcv/gobin" module.
// See https://github.com/myitcv/gobin for more details about "gobin".
// Package gobin provides a caster to install and run Go module executables using the "github.com/myitcv/gobin" module
// command.
// See https://pkg.go.dev/github.com/myitcv/gobin for more details about "gobin".
// The source code of the "gobin" is available at https://github.com/myitcv/gobin.
//
// Go Executable Installation
//
Expand Down
6 changes: 2 additions & 4 deletions pkg/spell/goimports/goimports.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) 2019-present Sven Greb <[email protected]>
// This source code is licensed under the MIT license found in the LICENSE file.

// Package goimports provides a spell incantation for the "golang.org/x/tools/cmd/goimports" Go module.
// Package goimports provides a spell incantation for the "golang.org/x/tools/cmd/goimports" Go module command.
// See https://pkg.go.dev/golang.org/x/tools/cmd/goimports for more details about "goimports".
// The source code of "goimports" is available at https://github.com/golang/tools/tree/master/cmd/goimports.
package goimports
Expand All @@ -16,15 +16,13 @@ import (
"github.com/svengreb/wand/pkg/spell"
)

// Spell is a spell incantation for the "golang.org/x/tools/cmd/goimports" Go module.
// Spell is a spell incantation for the "golang.org/x/tools/cmd/goimports" Go module command.
type Spell struct {
ac app.Config
opts *Options
}

// Formula returns the spell incantation formula.
// See `goimports help environment`, `go help env` and the `go` command documentations for more details:
// - https://golang.org/cmd/go/#hdr-Environment_variables
func (s *Spell) Formula() []string {
var args []string

Expand Down
13 changes: 5 additions & 8 deletions pkg/spell/goimports/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ import (
)

const (
// DefaultGoModulePath is the default "goimports" module import path.
// DefaultGoModulePath is the default "goimports" module command import path.
DefaultGoModulePath = "golang.org/x/tools/cmd/goimports"

// DefaultGoModuleVersion is the default "goimports" module version.
DefaultGoModuleVersion = "latest"
)

// Options are spell incantation options for the "golang.org/x/tools/cmd/goimports" Go module.
// Options are spell incantation options for the "golang.org/x/tools/cmd/goimports" Go module command.
type Options struct {
// env are spell incantation specific environment variables.
env map[string]string
Expand Down Expand Up @@ -52,7 +52,7 @@ type Options struct {
verbose bool
}

// Option is a spell incantation option for the "golang.org/x/tools/cmd/goimports" Go module.
// Option is a spell incantation option for the "golang.org/x/tools/cmd/goimports" Go module command.
type Option func(*Options)

// WithEnv sets the spell incantation specific environment.
Expand All @@ -62,7 +62,7 @@ func WithEnv(env map[string]string) Option {
}
}

// WithExtraArgs sets additional arguments to pass to the "goimports" command.
// WithExtraArgs sets additional arguments to pass to the "goimports" module command.
func WithExtraArgs(extraArgs ...string) Option {
return func(o *Options) {
o.extraArgs = append(o.extraArgs, extraArgs...)
Expand Down Expand Up @@ -132,7 +132,7 @@ func WithVerboseOutput(verbose bool) Option {
}
}

// newOptions creates new "golang.org/x/tools/cmd/goimports" Go module spell incantation options.
// newOptions creates new spell incantation options for the "golang.org/x/tools/cmd/goimports" Go module command.
func newOptions(opts ...Option) (*Options, error) {
version, versionErr := semver.NewVersion(DefaultGoModuleVersion)
if versionErr != nil {
Expand All @@ -148,9 +148,6 @@ func newOptions(opts ...Option) (*Options, error) {
Version: version,
IsLatest: true,
},
listNonCompliantFiles: true,
persistChanges: true,
reportAllErrors: true,
}
for _, o := range opts {
o(opt)
Expand Down
57 changes: 57 additions & 0 deletions pkg/spell/golangcilint/golangcilint.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright (c) 2019-present Sven Greb <[email protected]>
// This source code is licensed under the MIT license found in the LICENSE file.

// Package golangcilint provides a spell incantation for the "github.com/golangci/golangci-lint/cmd/golangci-lint" Go
// module command.
// See https://pkg.go.dev/github.com/golangci/golangci-lint for more details about "golangci-lint".
// The source code of the "golangci-lint" is available at https://github.com/golangci/golangci-lint.
package golangcilint

import (
"github.com/svengreb/wand"
"github.com/svengreb/wand/pkg/app"
"github.com/svengreb/wand/pkg/project"
"github.com/svengreb/wand/pkg/spell"
)

// Spell is a spell incantation for the "github.com/golangci/golangci-lint/cmd/golangci-lint" Go module command.
// If not extra arguments are configured, DefaultArgs are passed to the executable.
type Spell struct {
ac app.Config
opts *Options
}

// Formula returns the spell incantation formula.
func (s *Spell) Formula() []string {
return s.opts.args
}

// Kind returns the spell incantation kind.
func (s *Spell) Kind() spell.Kind {
return spell.KindGoModule
}

// Options returns the spell incantation options.
func (s *Spell) Options() interface{} {
return *s.opts
}

// GoModuleID returns partial Go module identifier information.
func (s *Spell) GoModuleID() *project.GoModuleID {
return s.opts.goModule
}

// Env returns spell incantation specific environment variables.
func (s *Spell) Env() map[string]string {
return s.opts.env
}

// New creates a new spell incantation for the "build" command of the Go toolchain.
//nolint:gocritic // The app.Config struct is passed as value by design to ensure immutability.
func New(wand wand.Wand, ac app.Config, opts ...Option) (*Spell, error) {
opt, optErr := newOptions(opts...)
if optErr != nil {
return nil, optErr
}
return &Spell{ac: ac, opts: opt}, nil
}
113 changes: 113 additions & 0 deletions pkg/spell/golangcilint/options.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
// Copyright (c) 2019-present Sven Greb <[email protected]>
// This source code is licensed under the MIT license found in the LICENSE file.

package golangcilint

import (
"fmt"

"github.com/Masterminds/semver/v3"

"github.com/svengreb/wand/pkg/cast"
"github.com/svengreb/wand/pkg/project"
)

const (
// DefaultGoModulePath is the default "goimports" module command import path.
DefaultGoModulePath = "github.com/golangci/golangci-lint/cmd/golangci-lint"

// DefaultGoModuleVersion is the default "goimports" module version.
DefaultGoModuleVersion = "v1.32.0"
)

// DefaultArgs are the default arguments to pass to the "golangci-lint" command.
var DefaultArgs = []string{"run"}

// Options are spell incantation options for the "github.com/golangci/golangci-lint/cmd/golangci-lint" Go module
// command.
type Options struct {
// args are arguments to pass to the "golangci-lint" command.
args []string

// env are spell incantation specific environment variables.
env map[string]string

// goModule are partial Go module identifier information.
goModule *project.GoModuleID

// verbose indicates whether the output should be verbose.
verbose bool
}

// Option is a spell incantation option for the "github.com/golangci/golangci-lint/cmd/golangci-lint" Go module command.
type Option func(*Options)

// WithArgs sets additional arguments to pass to the "golangci-lint" module command.
// By default DefaultArgs are passed.
func WithArgs(args ...string) Option {
return func(o *Options) {
o.args = append(o.args, args...)
}
}

// WithEnv sets the spell incantation specific environment.
func WithEnv(env map[string]string) Option {
return func(o *Options) {
o.env = env
}
}

// WithModulePath sets the "golangci-lint" module command import path.
// Defaults to DefaultGoModulePath.
func WithModulePath(path string) Option {
return func(o *Options) {
if path != "" {
o.goModule.Path = path
}
}
}

// WithModuleVersion sets the "golangci-lint" module version.
// Defaults to DefaultGoModuleVersion.
func WithModuleVersion(version *semver.Version) Option {
return func(o *Options) {
if version != nil {
o.goModule.Version = version
}
}
}

// WithVerboseOutput indicates whether the output should be verbose.
func WithVerboseOutput(verbose bool) Option {
return func(o *Options) {
o.verbose = verbose
}
}

// newOptions creates new spell incantation options for the "github.com/golangci/golangci-lint/cmd/golangci-lint" Go
// module command.
func newOptions(opts ...Option) (*Options, error) {
version, versionErr := semver.NewVersion(DefaultGoModuleVersion)
if versionErr != nil {
return nil, &cast.ErrCast{
Err: fmt.Errorf("parsing default module version %q: %w", DefaultGoModulePath, versionErr),
Kind: cast.ErrCasterInvalidOpts,
}
}
opt := &Options{
env: make(map[string]string),
goModule: &project.GoModuleID{
Path: DefaultGoModulePath,
Version: version,
},
}
for _, o := range opts {
o(opt)
}

if len(opt.args) == 0 {
opt.args = append(opt.args, DefaultArgs...)
}

return opt, nil
}