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

feat: lint config and fixes, dep updates #128

Merged
merged 4 commits into from
Sep 6, 2024
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
28 changes: 28 additions & 0 deletions .github/workflows/lint-soft.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: lint-soft
on:
push:
pull_request:

permissions:
contents: read
# Optional: allow read access to pull request. Use with `only-new-issues` option.
pull-requests: read

jobs:
golangci:
name: lint-soft
runs-on: ubuntu-latest
steps:
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: ^1

- uses: actions/checkout@v4
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
# Optional: golangci-lint command line arguments.
args: --config .golangci-soft.yml --issues-exit-code=0
# Optional: show only new issues if it's a pull request. The default value is `false`.
only-new-issues: true
28 changes: 28 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: lint
on:
push:
pull_request:

permissions:
contents: read
# Optional: allow read access to pull request. Use with `only-new-issues` option.
pull-requests: read

jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: ^1

- uses: actions/checkout@v4
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
# Optional: golangci-lint command line arguments.
#args:
# Optional: show only new issues if it's a pull request. The default value is `false`.
only-new-issues: true
39 changes: 39 additions & 0 deletions .golangci-soft.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
run:
tests: false

issues:
include:
- EXC0001
- EXC0005
- EXC0011
- EXC0012
- EXC0013

max-issues-per-linter: 0
max-same-issues: 0

linters:
enable:
- exhaustive
- goconst
- godot
- godox
- gomoddirectives
- goprintffuncname
- misspell
- nakedret
- nestif
- noctx
- nolintlint
- prealloc
- wrapcheck

# disable default linters, they are already enabled in .golangci.yml
disable:
- errcheck
- gosimple
- govet
- ineffassign
- staticcheck
- typecheck
- unused
28 changes: 28 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
run:
tests: false

issues:
include:
- EXC0001
- EXC0005
- EXC0011
- EXC0012
- EXC0013

max-issues-per-linter: 0
max-same-issues: 0

linters:
enable:
- bodyclose
- goimports
- gosec
- nilerr
- predeclared
- revive
- rowserrcheck
- sqlclosecheck
- tparallel
- unconvert
- unparam
- whitespace
2 changes: 1 addition & 1 deletion ansi.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"

"github.com/beevik/etree"
"github.com/charmbracelet/x/exp/term/ansi"
"github.com/charmbracelet/x/ansi"
"github.com/mattn/go-runewidth"
)

Expand Down
11 changes: 5 additions & 6 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ func expandPadding(p []float64, scale float64) []float64 {
return []float64{p[top] * scale, p[right] * scale, p[bottom] * scale, p[left] * scale}
default:
return []float64{0, 0, 0, 0}

}
}

Expand All @@ -102,7 +101,7 @@ const (
var userConfigPath = filepath.Join(xdg.ConfigHome, "freeze", "user.json")

func loadUserConfig() (fs.File, error) {
return os.Open(userConfigPath)
return os.Open(userConfigPath) //nolint: wrapcheck
}

func saveUserConfig(config Config) error {
Expand All @@ -112,19 +111,19 @@ func saveUserConfig(config Config) error {

err := os.MkdirAll(filepath.Dir(userConfigPath), os.ModePerm)
if err != nil {
return err
return err //nolint: wrapcheck
}
f, err := os.Create(userConfigPath)
if err != nil {
return err
return err //nolint: wrapcheck
}
b, err := json.Marshal(config)
if err != nil {
return err
return err //nolint: wrapcheck
}
_, err = f.Write(b)

printFilenameOutput(userConfigPath)

return err
return err //nolint: wrapcheck
}
1 change: 0 additions & 1 deletion cut_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,4 @@ func TestCut(t *testing.T) {
t.Errorf("cut(%s, %v)", test.input, test.lines)
}
}

}
6 changes: 4 additions & 2 deletions error.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import (
"github.com/charmbracelet/lipgloss"
)

var errorHeader = lipgloss.NewStyle().Foreground(lipgloss.Color("#F1F1F1")).Background(lipgloss.Color("#FF5F87")).Bold(true).Padding(0, 1).Margin(1).MarginLeft(2).SetString("ERROR")
var errorDetails = lipgloss.NewStyle().Foreground(lipgloss.Color("#757575")).Margin(0, 0, 1, 2)
var (
errorHeader = lipgloss.NewStyle().Foreground(lipgloss.Color("#F1F1F1")).Background(lipgloss.Color("#FF5F87")).Bold(true).Padding(0, 1).Margin(1).MarginLeft(2).SetString("ERROR")
errorDetails = lipgloss.NewStyle().Foreground(lipgloss.Color("#757575")).Margin(0, 0, 1, 2)
)

func printError(title string, err error) {
fmt.Printf("%s\n", lipgloss.JoinHorizontal(lipgloss.Center, errorHeader.String(), title))
Expand Down
9 changes: 7 additions & 2 deletions font/font.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,10 @@ var JetBrainsMonoTTF []byte
//go:embed JetBrainsMonoNL-Regular.ttf
var JetBrainsMonoNLTTF []byte

var JetBrainsMono string = base64.StdEncoding.EncodeToString(JetBrainsMonoTTF)
var JetBrainsMonoNL string = base64.StdEncoding.EncodeToString(JetBrainsMonoNLTTF)
var (
// JetBrainsMono font.
JetBrainsMono = base64.StdEncoding.EncodeToString(JetBrainsMonoTTF)

// JetBrainsMonoNL font.
JetBrainsMonoNL = base64.StdEncoding.EncodeToString(JetBrainsMonoNLTTF)
)
14 changes: 8 additions & 6 deletions freeze_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ import (

const binary = "./test/freeze-test"

var update = flag.Bool("update", false, "update golden files")
var png = flag.Bool("png", false, "update pngs")
var (
update = flag.Bool("update", false, "update golden files")
png = flag.Bool("png", false, "update pngs")
)

func TestMain(m *testing.M) {
flag.Parse()
Expand Down Expand Up @@ -264,15 +266,15 @@ func TestFreezeConfigurations(t *testing.T) {
if err != nil {
t.Fatal("unable to remove output files")
}
err = os.MkdirAll("test/output/svg", 0755)
err = os.MkdirAll("test/output/svg", 0o755)
if err != nil {
t.Fatal("unable to create output directory")
}
err = os.MkdirAll("test/golden/svg", 0755)
err = os.MkdirAll("test/golden/svg", 0o755)
if err != nil {
t.Fatal("unable to create output directory")
}
err = os.MkdirAll("test/output/png", 0755)
err = os.MkdirAll("test/output/png", 0o755)
if err != nil {
t.Fatal("unable to create output directory")
}
Expand All @@ -299,7 +301,7 @@ func TestFreezeConfigurations(t *testing.T) {
}
goldenfile := "test/golden/svg/" + tc.output + ".svg"
if *update {
if err := os.WriteFile(goldenfile, got, 0644); err != nil {
if err := os.WriteFile(goldenfile, got, 0o644); err != nil {
t.Log(err)
t.Fatal("unexpected error")
}
Expand Down
46 changes: 25 additions & 21 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,47 +1,51 @@
module github.com/charmbracelet/freeze

go 1.21
go 1.21.0

toolchain go1.22.5

require (
github.com/adrg/xdg v0.4.0
github.com/adrg/xdg v0.5.0
github.com/alecthomas/chroma/v2 v2.14.0
github.com/alecthomas/kong v0.9.0
github.com/aymanbagabas/go-udiff v0.2.0
github.com/beevik/etree v1.3.0
github.com/beevik/etree v1.4.1
github.com/caarlos0/go-shellwords v1.0.12
github.com/charmbracelet/huh v0.3.1-0.20240327025511-ec643317aa10
github.com/charmbracelet/lipgloss v0.10.1-0.20240325130315-f16ea2bdcb88
github.com/charmbracelet/huh v0.6.0
github.com/charmbracelet/lipgloss v0.13.0
github.com/charmbracelet/log v0.4.0
github.com/charmbracelet/x/ansi v0.2.3
github.com/charmbracelet/x/exp/term v0.0.0-20240403043919-dea9035a27d4
github.com/creack/pty v1.1.21
github.com/creack/pty v1.1.23
github.com/kanrichan/resvg-go v0.0.2-0.20231001163256-63db194ca9f5
github.com/mattn/go-isatty v0.0.20
github.com/mattn/go-runewidth v0.0.15
golang.org/x/sys v0.18.0
github.com/mattn/go-runewidth v0.0.16
github.com/muesli/reflow v0.3.0
golang.org/x/sys v0.25.0
)

require (
github.com/atotto/clipboard v0.1.4 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/catppuccin/go v0.2.0 // indirect
github.com/charmbracelet/bubbles v0.18.0 // indirect
github.com/charmbracelet/bubbletea v0.25.0 // indirect
github.com/charmbracelet/x/errors v0.0.0-20240117030013-d31dba354651 // indirect
github.com/charmbracelet/x/exp/strings v0.0.0-20240327191656-1e1cd98f30d4 // indirect
github.com/containerd/console v1.0.4 // indirect
github.com/dlclark/regexp2 v1.11.0 // indirect
github.com/charmbracelet/bubbles v0.20.0 // indirect
github.com/charmbracelet/bubbletea v1.1.0 // indirect
github.com/charmbracelet/x/errors v0.0.0-20240906161213-162f3037fef5 // indirect
github.com/charmbracelet/x/exp/strings v0.0.0-20240906161213-162f3037fef5 // indirect
github.com/charmbracelet/x/term v0.2.0 // indirect
github.com/dlclark/regexp2 v1.11.4 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
github.com/go-logfmt/logfmt v0.6.0 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mattn/go-localereader v0.0.1 // indirect
github.com/mitchellh/hashstructure/v2 v2.0.2 // indirect
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
github.com/muesli/cancelreader v0.2.2 // indirect
github.com/muesli/reflow v0.3.0 // indirect
github.com/muesli/termenv v0.15.2 // indirect
github.com/muesli/termenv v0.15.3-0.20240618155329-98d742f6907a // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/tetratelabs/wazero v1.7.0 // indirect
golang.org/x/exp v0.0.0-20240325151524-a685a6edb6d8 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/term v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
github.com/tetratelabs/wazero v1.8.0 // indirect
golang.org/x/exp v0.0.0-20240904232852-e7e105dedf7e // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/text v0.18.0 // indirect
)
Loading
Loading