Skip to content

Commit

Permalink
chore: implement fieldalignment
Browse files Browse the repository at this point in the history
  • Loading branch information
JanDeDobbeleer committed Dec 25, 2024
1 parent 1b6c134 commit 043d4e3
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 65 deletions.
54 changes: 29 additions & 25 deletions .github/workflows/code.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
on:
pull_request:
paths:
- 'src/**'

name: Validate Code
jobs:
test:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ${{ github.workspace }}/src
steps:
- name: Install Go
uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed
with:
go-version: 1.22.4
- name: Checkout code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- name: Golang CI
uses: golangci/golangci-lint-action@971e284b6050e8a5849b72094c50ab08da042db8
with:
working-directory: src
- name: Unit Tests
run: go test -v ./...
on:
pull_request:
paths:
- 'src/**'

name: Validate Code
jobs:
test:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ${{ github.workspace }}/src
steps:
- name: Install Go
uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed
with:
go-version: 1.22.4
- name: Checkout code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- name: Golang CI
uses: golangci/golangci-lint-action@971e284b6050e8a5849b72094c50ab08da042db8
with:
working-directory: src
- name: Fieldalignment
run: |
go install golang.org/x/tools/go/analysis/passes/fieldalignment/cmd/fieldalignment@latest
fieldalignment "./..."
- name: Unit Tests
run: go test -v ./...
16 changes: 7 additions & 9 deletions src/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ func TestResolveConfigPath(t *testing.T) {

func TestLoadConfig(t *testing.T) {
tests := []struct {
expected *Aliae
name string
config string
expected *Aliae
expectError bool
}{
{
"Valid",
"aliae.valid.yaml",
&Aliae{
name: "Valid",
config: "aliae.valid.yaml",
expected: &Aliae{
Aliae: shell.Aliae{
{Name: "test", Value: shell.Template("test")},
{Name: "test2", Value: shell.Template("test2")},
Expand All @@ -48,13 +48,11 @@ func TestLoadConfig(t *testing.T) {
{Name: "TEST_ENV", Value: "test"},
},
},
false,
},
{
"Invalid",
"aliae.invalid.yaml",
nil,
true,
name: "Invalid",
config: "aliae.invalid.yaml",
expectError: true,
},
}

Expand Down
2 changes: 1 addition & 1 deletion src/config/unmarshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ type Aliae struct {

type FuncMap []StringFunc
type StringFunc struct {
Name []byte
F func(string) ([]byte, error)
Name []byte
}

func customUnmarshaler(a *Aliae, b []byte) error {
Expand Down
2 changes: 1 addition & 1 deletion src/context/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import (
var Current *Runtime

type Runtime struct {
Path *Path
Shell string
OS string
Home string
Arch string
Path *Path
}

func Init(shell string) {
Expand Down
21 changes: 9 additions & 12 deletions src/shell/aliae.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,15 @@ var (
type Aliae []*Alias

type Alias struct {
Name string `yaml:"name"`
Value Template `yaml:"value"`
Type Type `yaml:"type"`
If If `yaml:"if"`

// PowerShell only options
Description string `yaml:"description"`
Force bool `yaml:"force"`
Option Option `yaml:"option"`
Scope Option `yaml:"scope"`

template string
Name string `yaml:"name"`
Value Template `yaml:"value"`
Type Type `yaml:"type"`
If If `yaml:"if"`
Description string `yaml:"description"`
Option Option `yaml:"option"`
Scope Option `yaml:"scope"`
template string
Force bool `yaml:"force"`
}

type Option string
Expand Down
2 changes: 1 addition & 1 deletion src/shell/aliae_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ def __foobar():
func TestAliaeRender(t *testing.T) {
cases := []struct {
Case string
Aliae Aliae
Expected string
Aliae Aliae
}{
{
Case: "Single alias",
Expand Down
9 changes: 4 additions & 5 deletions src/shell/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@ import (
type Envs []*Env

type Env struct {
Name string `yaml:"name"`
Value interface{} `yaml:"value"`
Name string `yaml:"name"`
Delimiter Template `yaml:"delimiter"`
If If `yaml:"if"`
Persist bool `yaml:"persist"`
Type EnvType `yaml:"type"`

template string
parsed bool
template string
Persist bool `yaml:"persist"`
parsed bool
}

func (e *Env) string() string {
Expand Down
6 changes: 3 additions & 3 deletions src/shell/env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ func TestEnvironmentVariable(t *testing.T) {
}
cases := []struct {
Case string
Env Env
Shell string
Expected string
Env Env
}{
{
Case: "PWSH",
Expand Down Expand Up @@ -160,9 +160,9 @@ func TestEnvRender(t *testing.T) {
cases := []struct {
Case string
Shell string
Expected string
Env Envs
NonEmptyScript bool
Expected string
}{
{
Case: "PWSH - No elements",
Expand Down Expand Up @@ -223,9 +223,9 @@ $env:FOO = "bar"`,

func TestEnvironmentVariableDelimiter(t *testing.T) {
cases := []struct {
Env *Env
Case string
Expected string
Env *Env
}{
{
Case: "No delimiter",
Expand Down
9 changes: 4 additions & 5 deletions src/shell/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ import (
type Paths []*Path

type Path struct {
Value Template `yaml:"value"`
If If `yaml:"if"`
Persist bool `yaml:"persist"`
Force bool `yaml:"force"`

Value Template `yaml:"value"`
If If `yaml:"if"`
template string
Persist bool `yaml:"persist"`
Force bool `yaml:"force"`
}

func (p *Path) string() string {
Expand Down
2 changes: 1 addition & 1 deletion src/shell/path_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,9 @@ func TestPathRender(t *testing.T) {
cases := []struct {
Case string
Shell string
Expected string
Paths Paths
NonEmptyScript bool
Expected string
}{
{
Case: "PWSH - No PATHS",
Expand Down
2 changes: 1 addition & 1 deletion src/shell/pwsh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (

func TestPowerShellCommandAlias(t *testing.T) {
cases := []struct {
Alias *Alias
Case string
Shell string
Expected string
Alias *Alias
}{
{
Case: "PWSH",
Expand Down
2 changes: 1 addition & 1 deletion src/shell/script_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (
func TestScriptRender(t *testing.T) {
cases := []struct {
Case string
Expected string
Scripts Scripts
NonEmptyScript bool
Expected string
}{
{
Case: "No content",
Expand Down

0 comments on commit 043d4e3

Please sign in to comment.