6
0
mirror of https://github.com/grdl/git-get.git synced 2026-02-04 11:01:46 +00:00

Simplify linters config, fix cyclop issues in main.go

This commit is contained in:
Grzegorz Dlugoszewski
2025-08-24 14:29:56 +02:00
parent ccdca12f96
commit b31de718d4
3 changed files with 84 additions and 183 deletions

View File

@@ -1,115 +1,20 @@
version: 2
version: "2"
run:
timeout: 5m
go: '1.24'
timeout: 1m
linters-settings:
errcheck:
check-type-assertions: true
check-blank: true
govet:
enable-all: true
disable:
- shadow
gocyclo:
min-complexity: 15
dupl:
threshold: 100
goconst:
min-len: 3
min-occurrences: 3
lll:
line-length: 120
unparam:
check-exported: false
nakedret:
max-func-lines: 30
prealloc:
simple: true
range-loops: true
for-loops: false
gocritic:
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style
funlen:
lines: 100
statements: 50
godox:
keywords:
- NOTE
- OPTIMIZE
- HACK
dogsled:
max-blank-identifiers: 2
whitespace:
multi-if: false
multi-func: false
formatters:
enable:
- gci
- gofmt
- goimports
linters:
disable-all: true
enable:
- bodyclose
- dogsled
- dupl
- errcheck
- funlen
- gochecknoinits
- goconst
- gocritic
- gocyclo
- godox
- goprintffuncname
- gosec
- govet
- ineffassign
- lll
- misspell
- nakedret
- noctx
- nolintlint
- prealloc
- revive
- staticcheck
- unconvert
- unparam
- unused
- whitespace
default: all
issues:
exclude-rules:
- path: _test\.go
linters:
- funlen
- goconst
- lll
exclusions:
rules:
- path: _test.go
linters:
- dupl # We don't mind duplicated code in tests. It helps with clarity
- path: pkg/git/test/
linters:
- goconst
exclude-use-default: false
max-issues-per-linter: 0
max-same-issues: 0
output:
format: colored-line-number
print-issued-lines: true
print-linter-name: true

View File

@@ -296,40 +296,6 @@ git list --fetch
git list --out dump > backup-$(date +%Y%m%d).txt
```
## Testing
Run the test suite:
```bash
# Run all tests
go test ./...
# Run tests with coverage
go test -race -coverprofile=coverage.out ./...
go tool cover -html=coverage.out
# Run specific package tests
go test -v ./pkg/git
```
### Linting
This project uses comprehensive linting with golangci-lint. The linting configuration includes 25+ linters for code quality, security, and style checking.
```bash
# Install golangci-lint (if not already installed)
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
# Run linting with the project's configuration
golangci-lint run
# Run with verbose output
golangci-lint run -v
# Fix auto-fixable issues
golangci-lint run --fix
```
## Troubleshooting
### Common Issues
@@ -373,19 +339,51 @@ git get user/repo
We welcome contributions!
### Quick Start for Contributors
### Quick Start
1. **Fork the repository**
2. **Create a feature branch**: `git checkout -b feature/amazing-feature`
3. **Install dependencies**: `go mod download`
4. **Make changes and add tests**
5. **Format**: `go fmt ./...`
6. **Run tests**: `go test ./...`
7. **Run linter**: `golangci-lint run`
8. **Commit changes**: `git commit -m 'Add amazing feature'`
9. **Push to branch**: `git push origin feature/amazing-feature`
10. **Open a Pull Request**
6. **Build**: `go build -o git-get ./cmd/`
7. **Run tests**: `go test ./...`
8. **Run linter**: `golangci-lint run`
9. **Commit changes**: `git commit -m 'Add amazing feature'`
10. **Push to branch**: `git push origin feature/amazing-feature`
11. **Open a Pull Request**
### Testing
Run the test suite:
```bash
# Run all tests
go test ./...
# Run tests with coverage
go test -race -coverprofile=coverage.out ./...
go tool cover -html=coverage.out
# Run specific package tests
go test -v ./pkg/git
```
### Linting
```bash
# Install golangci-lint (if not already installed)
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
# Run linting with the project's configuration
golangci-lint run
# Run with verbose output
golangci-lint run -v
# Fix auto-fixable issues
golangci-lint run --fix
```
## License

View File

@@ -6,56 +6,54 @@ import (
"strings"
)
// This program behaves as a git subcommand (see https://git.github.io/htmldocs/howto/new-command.html)
// When added to PATH, git recognizes it as its subcommand and it can be invoked as "git get..." or "git list..."
// It can also be invoked as a regular binary with subcommands: "git-get get..." or "git-get list"
// The following flow detects the invokation method and runs the appropriate command.
func main() {
// This program behaves as a git subcommand (see https://git.github.io/htmldocs/howto/new-command.html)
// When added to PATH, git recognizes it as its subcommand and it can be invoked as "git get..." or "git list..."
// It can also be invoked as a regular binary with subcommands: "git-get get..." or "git-get list"
// The following flow detects the invokation method and runs the appropriate command.
command, args := determineCommand()
executeCommand(command, args)
}
programName := filepath.Base(os.Args[0])
// Remove common executable extensions
programName = strings.TrimSuffix(programName, ".exe")
// Determine which command to run based on program name or first argument
var command string
var args []string
func determineCommand() (string, []string) {
programName := strings.TrimSuffix(filepath.Base(os.Args[0]), ".exe")
switch programName {
case "git-get":
// Check if first argument is a subcommand
if len(os.Args) > 1 && (os.Args[1] == "get" || os.Args[1] == "list") {
// Called as: git-get get <repo> or git-get list
command = os.Args[1]
args = os.Args[2:]
} else {
// Called as: git-get <repo> (default to get command)
command = "get"
args = os.Args[1:]
}
return handleGitGetInvocation()
case "git-list":
// Called as: git-list (symlinked binary)
command = "list"
args = os.Args[1:]
return handleGitListInvocation()
default:
// Fallback: use first argument as command
if len(os.Args) > 1 {
command = os.Args[1]
args = os.Args[2:]
} else {
command = "get"
args = []string{}
}
return handleDefaultInvocation()
}
}
// Execute the appropriate command
func handleGitGetInvocation() (string, []string) {
if len(os.Args) > 1 && (os.Args[1] == "get" || os.Args[1] == "list") {
return os.Args[1], os.Args[2:]
}
return "get", os.Args[1:]
}
func handleGitListInvocation() (string, []string) {
return "list", os.Args[1:]
}
func handleDefaultInvocation() (string, []string) {
if len(os.Args) > 1 {
return os.Args[1], os.Args[2:]
}
return "get", []string{}
}
func executeCommand(command string, args []string) {
switch command {
case "get":
runGet(args)
case "list":
runList(args)
default:
// Default to get command for unknown commands
runGet(os.Args[1:])
}
}