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
15 changes: 7 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,14 @@ jobs:
with:
go-version: '1.23'

- name: Install golangci-lint
run: |
# Download and install golangci-lint v2.6.2
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v2.6.2
golangci-lint --version

- name: Run golangci-lint
run: GOOS=${{ matrix.goos }} golangci-lint run --timeout=5m --config=../.golangci.yml
working-directory: src
uses: golangci/golangci-lint-action@v7
with:
version: v2.6.2
working-directory: src
args: --timeout=5m --config=../.golangci.yml
env:
GOOS: ${{ matrix.goos }}

- name: Verify no linting issues
if: success()
Expand Down
224 changes: 85 additions & 139 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,44 +1,32 @@
# golangci-lint configuration for dtvem
# Documentation: https://golangci-lint.run/usage/configuration/
# Documentation: https://golangci-lint.run/docs/configuration/file/

# Config version
version: 2
# Config version (must be a string for v2.x)
version: "2"

run:
# Timeout for analysis
timeout: 5m

# Include test files in linting
tests: true

# Output configuration
# Output configuration (v2.x format)
output:
# Colored output
format: colored-line-number

# Print lines of code with issue
print-issued-lines: true

# Print linter name in the end of issue text
print-linter-name: true

# Make issues output unique by line
uniq-by-line: true

# Sort results by: filepath, line and column
sort-results: true

# Linters configuration
formats:
text:
path: stdout
colors: true
# Sort results by file, linter, severity
sort-order:
- file
- linter
# Show statistics
show-stats: true

# Linters configuration (v2.x format)
linters:
# Disable all linters by default
disable-all: true

# Explicitly disable warning-only linters
disable:
- staticcheck # Code improvement suggestions
- revive # Style suggestions
- prealloc # Performance hints
- gosec # Security false positives
# Start with no linters enabled
default: none

# Enable specific linters
enable:
Expand All @@ -62,115 +50,73 @@ linters:
- nilerr # Find code that returns nil even if it checks that the error is not nil
- nilnil # Checks that there is no simultaneous return of nil error and invalid value

# WARNINGS ONLY (disabled to prevent CI failure)
# These are style/security suggestions that should not fail the build
# Re-enable locally with: golangci-lint run --enable-all
# - staticcheck # Code improvement suggestions (QF quick-fixes)
# - revive # Style suggestions (comment formatting, etc.)
# - prealloc # Performance hints
# - gosec # Security warnings (often false positives)

linters-settings:
# Settings for errcheck
errcheck:
# Report about not checking of errors in type assertions: `a := b.(MyStruct)`
check-type-assertions: true

# Report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`
check-blank: false

# List of functions to exclude from checking
exclude-functions:
- (*os.File).Close
- (*database/sql.Rows).Close

# Settings for govet
govet:
# Enable all analyzers
enable-all: true
# Disable specific analyzers
disable:
- shadow # Reports variables that shadow other variables (can be too noisy)

# Settings for gocyclo (cyclomatic complexity)
gocyclo:
# Minimal code complexity to report
min-complexity: 15

# Settings for dupl (code duplication)
dupl:
# Threshold for duplicate code detection
threshold: 100

# Settings for goconst
goconst:
# Minimal length of string constant
min-len: 3
# Minimum occurrences count to trigger issue
min-occurrences: 3
# Ignore test files
ignore-tests: true

# Settings for misspell
misspell:
# Correct spellings using locale preferences
locale: US

# DISABLED LINTER SETTINGS (commented out since linters are disabled above)
# Uncomment these when re-enabling the corresponding linters

# # Settings for revive (replacement for golint)
# revive:
# enable-all-rules: false
# rules:
# # ... (keep original rules for reference)

# # Settings for gosec (security)
# gosec:
# tests: true
# excludes:
# - G304 # File path provided as taint input

# # Settings for staticcheck
# staticcheck:
# checks: ["all"]

# Issues configuration
# Linter-specific settings (moved from top-level linters-settings)
settings:
# Settings for errcheck
errcheck:
# Report about not checking of errors in type assertions
check-type-assertions: true
# Report about assignment of errors to blank identifier
check-blank: false
# List of functions to exclude from checking
exclude-functions:
- (*os.File).Close
- (*database/sql.Rows).Close

# Settings for govet
govet:
# Enable all analyzers
enable-all: true
# Disable specific analyzers
disable:
- shadow # Reports variables that shadow other variables (can be too noisy)
- fieldalignment # Reports struct field ordering for memory optimization (too noisy)

# Settings for gocyclo (cyclomatic complexity)
gocyclo:
# Minimal code complexity to report (25 allows for existing complex functions)
min-complexity: 25

# Settings for dupl (code duplication)
dupl:
# Threshold for duplicate code detection
threshold: 100

# Settings for goconst
goconst:
# Minimal length of string constant
min-len: 3
# Minimum occurrences count to trigger issue
min-occurrences: 3

# Settings for misspell
misspell:
# Correct spellings using locale preferences
locale: US

# Exclusion rules (moved from issues section in v1.x)
exclusions:
# Generated files should be ignored
generated: lax
# Paths to exclude
paths:
- vendor
- dist
- .claude
- ".*\\.pb\\.go$"
# Rules to exclude specific linters in specific paths
rules:
# Ignore duplicate code and repeated strings in test files (test tables often have similar structure)
- linters:
- dupl
- goconst
path: "_test\\.go$"

# Issues configuration (v2.x format)
issues:
# Which dirs to skip: issues from them won't be reported
exclude-dirs:
- vendor
- dist
- .claude

# Which files to skip: issues from them won't be reported
exclude-files:
- ".*\\.pb\\.go$" # Skip generated protobuf files

# Exclude specific linters for matching issues
exclude-rules:
# Exclude known issues in generated files
- path: ".*\\.pb\\.go"
linters:
- all

# Ignore long lines in comments (e.g., URLs)
- linters:
- revive
text: "line is \\d+ characters"
source: "^\\s*//.*https?://"

# Maximum issues count per one linter
# Set to 0 to disable limit
# Maximum issues count per one linter (0 = unlimited)
max-issues-per-linter: 0

# Maximum count of issues with the same text
# Set to 0 to disable limit
# Maximum count of issues with the same text (0 = unlimited)
max-same-issues: 0

# Show only new issues created after git revision
# Useful for checking only your changes
# new-from-rev: origin/main

# Independently of option `exclude` we use default exclude patterns
exclude-use-default: false
# Make issues output unique by line
uniq-by-line: true
54 changes: 2 additions & 52 deletions src/cmd/shim/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

"github.com/dtvem/dtvem/src/internal/config"
"github.com/dtvem/dtvem/src/internal/constants"
"github.com/dtvem/dtvem/src/internal/path"
"github.com/dtvem/dtvem/src/internal/runtime"
"github.com/dtvem/dtvem/src/internal/shim"
"github.com/dtvem/dtvem/src/internal/ui"
Expand Down Expand Up @@ -111,7 +112,7 @@ func runShim() error {
// It attempts to fallback to system PATH or prompts for installation
func handleNoConfiguredVersion(shimName, runtimeName string, provider runtime.ShimProvider) error {
// Try to find the executable deeper in PATH (system installation)
systemPath := findInSystemPath(shimName)
systemPath := path.LookPathExcludingShims(shimName)

if systemPath != "" {
// Found system installation - use it
Expand Down Expand Up @@ -143,57 +144,6 @@ func handleNoConfiguredVersion(shimName, runtimeName string, provider runtime.Sh
return fmt.Errorf("no version configured")
}

// findInSystemPath searches for an executable in PATH, excluding dtvem's shims directory
func findInSystemPath(execName string) string {
// Get the shims directory to exclude it from search
shimsDir := config.DefaultPaths().Shims

// Get PATH environment variable
pathEnv := os.Getenv("PATH")
if pathEnv == "" {
return ""
}

// Split PATH into directories
pathDirs := filepath.SplitList(pathEnv)

// Search each directory
for _, dir := range pathDirs {
// Skip the dtvem shims directory
if strings.EqualFold(dir, shimsDir) {
continue
}

// Try to find the executable in this directory
var candidatePath string
if os.PathSeparator == '\\' {
// Windows: try .exe, .cmd, .bat extensions
for _, ext := range []string{".exe", ".cmd", ".bat"} {
candidate := filepath.Join(dir, execName+ext)
if info, err := os.Stat(candidate); err == nil && !info.IsDir() {
candidatePath = candidate
break
}
}
} else {
// Unix: check if file exists and is executable
candidate := filepath.Join(dir, execName)
if info, err := os.Stat(candidate); err == nil && !info.IsDir() {
// Check if executable (has execute permission)
if info.Mode()&0111 != 0 {
candidatePath = candidate
}
}
}

if candidatePath != "" {
return candidatePath
}
}

return ""
}

// getShimName returns the name of this shim binary
func getShimName() string {
shimPath := os.Args[0]
Expand Down
Loading