Skip to content
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
3 changes: 3 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ RUN echo "docker ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/docker
# Create a non-root user and switch to it
USER docker

# Add /app/bin to the PATH
ENV PATH="/app/bin:$PATH"

# Set the working directory
WORKDIR /workspace

Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ jobs:
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
# - name: Lint
# env:
# GOFLAGS: -buildvcs=false -tags=next
# run: /app/bin/golangci-lint run -v ./...
- name: Lint
env:
GOFLAGS: -buildvcs=false -tags=next
run: /app/bin/golangci-lint run -v ./...
- name: Run Build and Tests
run: make test
- name: Run Integration Tests
Expand Down
155 changes: 72 additions & 83 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,67 +1,18 @@
linters-settings:
dupl:
threshold: 100
funlen:
lines: 100
statements: 50
goconst:
min-len: 3
min-occurrences: 4
gocritic:
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style
gocyclo:
min-complexity: 15
goimports:
local-prefixes: github.com/Jguer/yay/v12
gomnd:
checks:
- argument
- case
- condition
- return
ignored-numbers:
- "0"
- "1"
- "2"
- "3"
ignored-functions:
- strings.SplitN
lll:
line-length: 140
misspell:
locale: US
nolintlint:
allow-unused: false # report any unused nolint directives
require-explanation: false # don't require an explanation for nolint directives
require-specific: false # don't require nolint directives to be specific about which linter is being skipped

version: "2"
run:
go: "1.20"
linters:
# please, do not use `enable-all`: it's deprecated and will be removed soon.
# inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint
disable-all: true
default: none
enable:
- forbidigo
- bodyclose
- dogsled
- dupl
- errorlint
- errcheck
# - funlen # TOFIX
- errorlint
- gochecknoinits
# - goconst # TOFIX
- gocritic
# - gocyclo # TOFIX
- gofmt
- goimports
# - gomnd # TOFIX
- goprintffuncname
- gosec
- gosimple
- govet
- ineffassign
- lll
Expand All @@ -70,36 +21,74 @@ linters:
- noctx
- nolintlint
- staticcheck
- stylecheck
- typecheck
- unconvert
- unparam
- unused
- whitespace

run:
go: "1.20"
timeout: "10m"
forbidigo:
forbid:
- p: ^fmt\.Print.*$
msg: Do not commit print statements.

issues:
exclude-rules:
- path: (.+)_test.go
linters:
- lll
- revive
- wsl
- govet
- godot
- errcheck
- stylecheck
- dupl
- gocritic
- gochecknoinits
- errorlint

exclude:
- G204
settings:
dupl:
threshold: 100
funlen:
lines: 100
statements: 50
goconst:
min-len: 3
min-occurrences: 4
gocritic:
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style
gocyclo:
min-complexity: 15
lll:
line-length: 140
misspell:
locale: US
nolintlint:
require-explanation: false
require-specific: false
allow-unused: false
exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
rules:
- linters:
- dupl
- errcheck
- errorlint
- gochecknoinits
- gocritic
- godot
- govet
- lll
- revive
- staticcheck
- wsl
path: (.+)_test.go
- path: (.+)\.go$
text: G204
paths:
- third_party$
- builtin$
- examples$
formatters:
enable:
- gofmt
- goimports
settings:
goimports:
local-prefixes:
- github.com/Jguer/yay/v12
exclusions:
generated: lax
paths:
- third_party$
- builtin$
- examples$
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"go.lintTool": "golangci-lint",
"gopls": {
"formatting.gofumpt": true,
"formatting.local": "github.com/Jguer/yay/v12"
}
}
2 changes: 1 addition & 1 deletion ci.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ COPY go.mod .
RUN pacman-key --init && pacman -Sy && pacman -S --overwrite=* --noconfirm archlinux-keyring && \
pacman -Su --overwrite=* --needed --noconfirm pacman doxygen meson asciidoc go git gcc make sudo base-devel && \
rm -rfv /var/cache/pacman/* /var/lib/pacman/sync/* && \
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.64.6 && \
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v2.1.5 && \
go mod download
5 changes: 3 additions & 2 deletions clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ func syncClean(ctx context.Context, run *runtime.Runtime, cmdArgs *parser.Argume
_, removeAll, _ := cmdArgs.GetArg("c", "clean")

for _, v := range run.PacmanConf.CleanMethod {
if v == "KeepInstalled" {
switch v {
case "KeepInstalled":
keepInstalled = true
} else if v == "KeepCurrent" {
case "KeepCurrent":
keepCurrent = true
}
}
Expand Down
2 changes: 1 addition & 1 deletion local_install.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func srcinfoExists(ctx context.Context,
return fmt.Errorf("unable to generate .SRCINFO: %w - %s", err, stderr)
}

if len(srcinfo) == 0 {
if srcinfo == "" {
return fmt.Errorf("generated .SRCINFO is empty, check your PKGBUILD for errors")
}

Expand Down
16 changes: 8 additions & 8 deletions pkg/dep/dep_graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (i *InstallInfo) String() string {
}

type (
Reason int
Reason uint
Source int
)

Expand Down Expand Up @@ -804,17 +804,17 @@ func makeAURPKGFromSrcinfo(dbExecutor db.Executor, srcInfo *gosrc.Srcinfo) ([]*a
Description: getDesc(pkg),
URL: pkg.URL,
Depends: append(archStringToString(alpmArch, pkg.Depends),
archStringToString(alpmArch, srcInfo.Package.Depends)...),
MakeDepends: archStringToString(alpmArch, srcInfo.PackageBase.MakeDepends),
CheckDepends: archStringToString(alpmArch, srcInfo.PackageBase.CheckDepends),
archStringToString(alpmArch, srcInfo.Depends)...),
MakeDepends: archStringToString(alpmArch, srcInfo.MakeDepends),
CheckDepends: archStringToString(alpmArch, srcInfo.CheckDepends),
Conflicts: append(archStringToString(alpmArch, pkg.Conflicts),
archStringToString(alpmArch, srcInfo.Package.Conflicts)...),
archStringToString(alpmArch, srcInfo.Conflicts)...),
Provides: append(archStringToString(alpmArch, pkg.Provides),
archStringToString(alpmArch, srcInfo.Package.Provides)...),
archStringToString(alpmArch, srcInfo.Provides)...),
Replaces: append(archStringToString(alpmArch, pkg.Replaces),
archStringToString(alpmArch, srcInfo.Package.Replaces)...),
archStringToString(alpmArch, srcInfo.Replaces)...),
OptDepends: append(archStringToString(alpmArch, pkg.OptDepends),
archStringToString(alpmArch, srcInfo.Package.OptDepends)...),
archStringToString(alpmArch, srcInfo.OptDepends)...),
Groups: pkg.Groups,
License: pkg.License,
Keywords: []string{},
Expand Down
6 changes: 3 additions & 3 deletions pkg/intrange/intrange.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ type IntRange struct {
// IntRanges is a slice of IntRange.
type IntRanges []IntRange

func makeIntRange(min, max int) IntRange {
func makeIntRange(minVal, maxVal int) IntRange {
return IntRange{
min,
max,
min: minVal,
max: maxVal,
}
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/intrange/intrange_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ func TestParseNumberMenu(t *testing.T) {
},
mapset.NewThreadUnsafeSet[string](), mapset.NewThreadUnsafeSet[string](),
},
{IntRanges{}, IntRanges{}, mapset.NewThreadUnsafeSet[string]("abort", "all", "none"), mapset.NewThreadUnsafeSet[string]()},
{IntRanges{}, IntRanges{}, mapset.NewThreadUnsafeSet[string]("a-b"), mapset.NewThreadUnsafeSet[string]("abort", "a-b")},
{IntRanges{}, IntRanges{}, mapset.NewThreadUnsafeSet[string]("-9223372036854775809-9223372036854775809"), mapset.NewThreadUnsafeSet[string]()},
{IntRanges{}, IntRanges{}, mapset.NewThreadUnsafeSet("abort", "all", "none"), mapset.NewThreadUnsafeSet[string]()},
{IntRanges{}, IntRanges{}, mapset.NewThreadUnsafeSet("a-b"), mapset.NewThreadUnsafeSet("abort", "a-b")},
{IntRanges{}, IntRanges{}, mapset.NewThreadUnsafeSet("-9223372036854775809-9223372036854775809"), mapset.NewThreadUnsafeSet[string]()},
{IntRanges{
makeIntRange(1, 1),
makeIntRange(2, 2),
Expand All @@ -86,7 +86,7 @@ func TestParseNumberMenu(t *testing.T) {
}, IntRanges{}, mapset.NewThreadUnsafeSet[string](), mapset.NewThreadUnsafeSet[string]()},
{IntRanges{}, IntRanges{}, mapset.NewThreadUnsafeSet[string](), mapset.NewThreadUnsafeSet[string]()},
{IntRanges{}, IntRanges{}, mapset.NewThreadUnsafeSet[string](), mapset.NewThreadUnsafeSet[string]()},
{IntRanges{}, IntRanges{}, mapset.NewThreadUnsafeSet[string]("a", "b", "c", "d", "e"), mapset.NewThreadUnsafeSet[string]()},
{IntRanges{}, IntRanges{}, mapset.NewThreadUnsafeSet("a", "b", "c", "d", "e"), mapset.NewThreadUnsafeSet[string]()},
}

for n, in := range inputs {
Expand Down
2 changes: 1 addition & 1 deletion pkg/query/query_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ func matchesSearch(pkg *aur.Pkg, terms []string) bool {
desc := strings.ToLower(pkg.Description)
targ := strings.ToLower(pkgN)

if !(strings.Contains(name, targ) || strings.Contains(desc, targ)) {
if !strings.Contains(name, targ) && !strings.Contains(desc, targ) {
return false
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/query/version_diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func GetVersionDiff(oldVersion, newVersion string) (left, right string) {
}

for index, char := range oldVersion {
charIsSpecial := !(unicode.IsLetter(char) || unicode.IsNumber(char))
charIsSpecial := !unicode.IsLetter(char) && !unicode.IsNumber(char)

if (index >= len(newVersion)) || (char != rune(newVersion[index])) {
if charIsSpecial {
Expand Down
11 changes: 6 additions & 5 deletions pkg/settings/exe/cmd_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,12 @@ func (c *CmdBuilder) deElevateCommand(ctx context.Context, cmd *exec.Cmd) *exec.

if userFound, err := user.Lookup(ogCaller); err == nil {
cmd.SysProcAttr = &syscall.SysProcAttr{}
uid, _ := strconv.Atoi(userFound.Uid)
gid, _ := strconv.Atoi(userFound.Gid)
cmd.SysProcAttr.Credential = &syscall.Credential{Uid: uint32(uid), Gid: uint32(gid)}

return cmd
uid64, errUid := strconv.ParseUint(userFound.Uid, 10, 32)
gid64, errGid := strconv.ParseUint(userFound.Gid, 10, 32)
if errUid == nil && errGid == nil {
cmd.SysProcAttr.Credential = &syscall.Credential{Uid: uint32(uid64), Gid: uint32(gid64)}
return cmd
}
}

cmdArgs := []string{
Expand Down
3 changes: 1 addition & 2 deletions pkg/settings/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (o *Option) Add(args ...string) {
}

func (o *Option) First() string {
if o.Args == nil || len(o.Args) == 0 {
if len(o.Args) == 0 {
return ""
}

Expand Down Expand Up @@ -565,7 +565,6 @@ func (a *Arguments) parseShortOption(arg, param string) (usedNext bool, err erro
break
} else {
err = a.AddArg(char)

if err != nil {
return
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/sync/build/pkg_archive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import (
"os/exec"
"testing"

"github.com/Jguer/yay/v12/pkg/settings/exe"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/Jguer/yay/v12/pkg/settings/exe"
)

func TestParsePackageList(t *testing.T) {
Expand Down
5 changes: 3 additions & 2 deletions pkg/sync/workdir/preparer.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,15 @@ func (preper *Preparer) PrepareWorkspace(ctx context.Context,

for _, layer := range targets {
for _, info := range layer {
if info.Source == dep.AUR {
switch info.Source {
case dep.AUR:
pkgBase := *info.AURBase
pkgBuildDir := filepath.Join(preper.cfg.BuildDir, pkgBase)
if preper.needToCloneAURBase(info, pkgBuildDir) {
aurBasesToClone.Add(pkgBase)
}
pkgBuildDirsByBase[pkgBase] = pkgBuildDir
} else if info.Source == dep.SrcInfo {
case dep.SrcInfo:
pkgBase := *info.AURBase
pkgBuildDirsByBase[pkgBase] = *info.SrcinfoPath
}
Expand Down
Loading
Loading