Skip to content

Commit

Permalink
go lint fixes (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
moshebe committed Aug 2, 2020
1 parent c838d46 commit 25b2a55
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"gopkg.in/yaml.v2"
)

// AppFs hold the file-system abstraction for this package
var AppFs = afero.NewOsFs()

// Config contains the fields of gebug configuration
Expand Down
5 changes: 4 additions & 1 deletion pkg/input/input.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package input

import (
"github.com/spf13/afero"
"io/ioutil"
"os"
"path"
Expand All @@ -12,9 +13,11 @@ import (
"go.uber.org/zap"
)

// AppFs hold the file-system abstraction for this package
var AppFs = afero.NewOsFs()

// ConfigPrompt asks for fields for the configuration
type ConfigPrompt interface {

// Run asks for configuration field and saves it in configuration
Run() error
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/setup/ide.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import (
"path"
)

// AppFs hold the file-system abstraction for this package
var AppFs = afero.NewOsFs()

// Ide defines the expected behaviour of each IDE that will have a Gebug integration
type Ide interface {
// Detected tells if the IDE trails were found in the working directory. e.g: `.vscode` or `.idea` directories.
Detected() (bool, error)
Expand Down Expand Up @@ -36,6 +38,7 @@ func (i baseIde) detected(ideDirName string) (bool, error) {
return detected, nil
}

// SupportedIdes returns a dictionary holds the IDE name along with the corresponding instance
func SupportedIdes(workDir string, port int) map[string]Ide {
return map[string]Ide{
"Visual Studio Code": &VsCode{baseIde{WorkDir: workDir, DebuggerPort: port}},
Expand Down
5 changes: 5 additions & 0 deletions pkg/setup/vscode.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@ const (
defaultVsCodeConfVersion = "0.2.0"
)

// VsCode is the 'Visual Studio Code' integration with Gebug
type VsCode struct {
baseIde
}

// Detected tells if the IDE trails were found in the working directory (the `.vscode` directory exists)
func (v VsCode) Detected() (bool, error) {
return v.detected(vscodeDirName)
}

// GebugInstalled tells if Gebug debugger mode was set in the IDE 'launch.json' file
func (v VsCode) GebugInstalled() (bool, error) {
detected, err := v.Detected()
if err != nil {
Expand All @@ -45,10 +48,12 @@ func (v VsCode) GebugInstalled() (bool, error) {
return installed, nil
}

// Enable Gebug's debugger configurations by adding the Gebug object from the configurations json in 'launch.json'
func (v VsCode) Enable() error {
return v.setEnabled(true)
}

// Disable Gebug's debugger configurations by removing the Gebug object from the configurations json in 'launch.json'
func (v VsCode) Disable() error {
return v.setEnabled(false)
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/testutil/testutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"testing"
)

// RunTestData runs all the tests resides in the `testdata` directory and their input/golden file has the following prefix
// using the `check` function the caller can easily consume the test file input and compare the actual result with the golden one.
func RunTestData(t *testing.T, prefix string, check func(t *testing.T, input, golden *bytes.Buffer)) {
baseDir := "./testdata"
files, err := ioutil.ReadDir(baseDir)
Expand Down
7 changes: 7 additions & 0 deletions pkg/validate/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ import (
"github.com/pkg/errors"
)

// Validator defines the behaviour validation behaviour
type Validator interface {
Validate(string) error
}

// NonEmptyValidator checks that the input is not empty after trimming
type NonEmptyValidator struct{}

// Validate checks the input and return an error if its invalid
func (v NonEmptyValidator) Validate(input string) error {
input = strings.TrimSpace(input)
if len(input) <= 0 {
Expand All @@ -23,10 +26,12 @@ func (v NonEmptyValidator) Validate(input string) error {
return nil
}

// RegexValidator checks that the input matches a pattern after trimming
type RegexValidator struct {
Pattern string
}

// Validate checks the input and return an error if its invalid
func (v RegexValidator) Validate(input string) error {
input = strings.TrimSpace(input)
if len(input) <= 0 {
Expand All @@ -40,11 +45,13 @@ func (v RegexValidator) Validate(input string) error {
return nil
}

// NumericRangeValidator checks that the input is a valid number after trimming and its value is between a given range
type NumericRangeValidator struct {
Min int
Max int
}

// Validate checks the input and return an error if its invalid
func (v NumericRangeValidator) Validate(input string) error {
input = strings.TrimSpace(input)
if len(input) <= 0 {
Expand Down

0 comments on commit 25b2a55

Please sign in to comment.