mirror of
https://github.com/onyx-and-iris/ignr.git
synced 2026-03-03 17:09:12 +00:00
Compare commits
3 Commits
7e33557c79
...
9f22086c73
| Author | SHA1 | Date | |
|---|---|---|---|
| 9f22086c73 | |||
| f8f317f576 | |||
| 1da96e4f30 |
9
.github/workflows/golang-ci.yml
vendored
9
.github/workflows/golang-ci.yml
vendored
@ -23,7 +23,8 @@ jobs:
|
|||||||
uses: actions/setup-go@v5
|
uses: actions/setup-go@v5
|
||||||
with:
|
with:
|
||||||
go-version: '1.24'
|
go-version: '1.24'
|
||||||
- name: Install golangci-lint
|
- name: golangci-lint
|
||||||
run: go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
|
uses: golangci/golangci-lint-action@v9
|
||||||
- name: Run golangci-lint
|
with:
|
||||||
run: golangci-lint run ./...
|
version: v2.6.0
|
||||||
|
args: --config .golangci.yml
|
||||||
|
|||||||
174
.golangci.yml
174
.golangci.yml
@ -1,54 +1,142 @@
|
|||||||
|
version: '2'
|
||||||
|
|
||||||
run:
|
run:
|
||||||
# timeout for analysis, e.g. 30s, 3m, default is 1m
|
|
||||||
timeout: 3m
|
timeout: 3m
|
||||||
# exclude test files
|
|
||||||
tests: true
|
tests: true
|
||||||
|
go: '1.24'
|
||||||
|
|
||||||
linters:
|
linters:
|
||||||
# Set to true runs only fast linters.
|
disable: []
|
||||||
# Good option for 'lint on save', pre-commit hook or CI.
|
|
||||||
fast: true
|
|
||||||
|
|
||||||
disable-all: true
|
|
||||||
|
|
||||||
enable:
|
enable:
|
||||||
- gosimple
|
# Default enabled linters
|
||||||
- govet
|
- errcheck # Check for unchecked errors
|
||||||
- ineffassign
|
- govet # Go's built-in vetting tool
|
||||||
- staticcheck
|
- ineffassign # Detect ineffectual assignments
|
||||||
- unused
|
- staticcheck # Advanced static analysis
|
||||||
- gofmt
|
- unused # Check for unused code
|
||||||
- gofumpt
|
# Additional useful linters
|
||||||
- misspell
|
- misspell # Detect common misspellings
|
||||||
- unparam
|
- unparam # Check for unused function parameters
|
||||||
- gosec
|
- gosec # Security checks
|
||||||
- asciicheck
|
- asciicheck # Check for non-ASCII characters
|
||||||
- errname
|
- errname # Check error variable names
|
||||||
- gci
|
- godot # Check for missing periods in comments
|
||||||
- godot
|
- revive # Highly configurable linter for style and correctness
|
||||||
- goimports
|
- gocritic # Detect code issues and suggest improvements
|
||||||
- revive
|
- gocyclo # Check for cyclomatic complexity
|
||||||
|
- dupl # Check for code duplication
|
||||||
|
- predeclared # Check for shadowing of predeclared identifiers
|
||||||
|
- copyloopvar # Check for loop variable capture in goroutines
|
||||||
|
- errorlint # Check for common mistakes in error handling
|
||||||
|
- goconst # Check for repeated strings that could be constants
|
||||||
|
- gosmopolitan # Check for non-portable code
|
||||||
|
|
||||||
linters-settings:
|
settings:
|
||||||
gofmt:
|
misspell:
|
||||||
rewrite-rules:
|
locale: UK
|
||||||
- pattern: 'interface{}'
|
|
||||||
replacement: 'any'
|
|
||||||
- pattern: 'a[b:len(a)]'
|
|
||||||
replacement: 'a[b:]'
|
|
||||||
|
|
||||||
misspell:
|
errcheck:
|
||||||
locale: UK
|
check-type-assertions: true
|
||||||
|
check-blank: true
|
||||||
|
exclude-functions:
|
||||||
|
- fmt.Fprintf
|
||||||
|
- fmt.Fprintln
|
||||||
|
- fmt.Printf
|
||||||
|
- fmt.Println
|
||||||
|
- fmt.Errorf
|
||||||
|
|
||||||
errcheck:
|
revive:
|
||||||
check-type-assertions: true
|
severity: warning
|
||||||
|
rules:
|
||||||
|
# Code quality and style
|
||||||
|
- name: exported
|
||||||
|
arguments:
|
||||||
|
- 'checkPrivateReceivers'
|
||||||
|
- 'sayRepetitiveInsteadOfStutters'
|
||||||
|
- name: var-naming
|
||||||
|
- name: package-comments
|
||||||
|
- name: range-val-in-closure
|
||||||
|
- name: time-naming
|
||||||
|
- name: context-as-argument
|
||||||
|
- name: context-keys-type
|
||||||
|
- name: dot-imports
|
||||||
|
- name: empty-block
|
||||||
|
- name: error-return
|
||||||
|
- name: error-strings
|
||||||
|
- name: error-naming
|
||||||
|
- name: if-return
|
||||||
|
- name: increment-decrement
|
||||||
|
- name: indent-error-flow
|
||||||
|
- name: receiver-naming
|
||||||
|
- name: redefines-builtin-id
|
||||||
|
- name: superfluous-else
|
||||||
|
- name: unexported-return
|
||||||
|
- name: unreachable-code
|
||||||
|
- name: unused-parameter
|
||||||
|
- name: var-declaration
|
||||||
|
- name: blank-imports
|
||||||
|
- name: range
|
||||||
|
|
||||||
|
# Disabled rules (can be enabled if needed)
|
||||||
|
# - name: line-length-limit
|
||||||
|
# arguments: [120]
|
||||||
|
# - name: function-length
|
||||||
|
# arguments: [50, 0]
|
||||||
|
# - name: cyclomatic
|
||||||
|
# arguments: [10]
|
||||||
|
|
||||||
|
gosec:
|
||||||
|
excludes:
|
||||||
|
- G104 # Duplicated errcheck checks
|
||||||
|
- G115 # integer overflow conversion int -> uint32
|
||||||
|
|
||||||
|
exclusions:
|
||||||
|
warn-unused: false
|
||||||
|
rules:
|
||||||
|
# Exclude some linters from running on tests files.
|
||||||
|
- path: _test\.go
|
||||||
|
linters:
|
||||||
|
- gocyclo
|
||||||
|
- errcheck
|
||||||
|
- dupl
|
||||||
|
- gosec
|
||||||
|
|
||||||
|
paths:
|
||||||
|
- vendor
|
||||||
|
|
||||||
|
# Formatters configuration
|
||||||
|
formatters:
|
||||||
|
# Enable specific formatters
|
||||||
|
enable:
|
||||||
|
- gofumpt # Stricter gofmt alternative
|
||||||
|
- goimports # Organizes imports
|
||||||
|
- gci # Controls import order/grouping
|
||||||
|
- golines # Enforces line length
|
||||||
|
|
||||||
|
# Formatter-specific settings
|
||||||
|
settings:
|
||||||
|
goimports:
|
||||||
|
local-prefixes: [github.com/onyx-and-iris/ignr]
|
||||||
|
|
||||||
|
gci:
|
||||||
|
# Define import sections order
|
||||||
|
sections:
|
||||||
|
- standard # Standard library
|
||||||
|
- default # Everything else
|
||||||
|
- prefix(github.com/onyx-and-iris/ignr) # Current module
|
||||||
|
|
||||||
|
gofumpt:
|
||||||
|
extra-rules: true # Enable additional formatting rules
|
||||||
|
|
||||||
|
exclusions:
|
||||||
|
warn-unused: true
|
||||||
|
|
||||||
|
paths:
|
||||||
|
- vendor
|
||||||
|
|
||||||
issues:
|
issues:
|
||||||
max-same-issues: 0
|
# Limit the number of same issues reported to avoid spam
|
||||||
max-issues-per-linter: 0
|
max-same-issues: 50
|
||||||
exclude-use-default: false
|
|
||||||
exclude:
|
# Limit the number of issues per linter to keep output manageable
|
||||||
# gosec: Duplicated errcheck checks
|
max-issues-per-linter: 100
|
||||||
- G104
|
|
||||||
# gosec: integer overflow conversion int -> uint32
|
|
||||||
- G115
|
|
||||||
|
|||||||
@ -9,6 +9,7 @@ vars:
|
|||||||
|
|
||||||
WINDOWS: '{{.BIN_DIR}}/{{.PROGRAM}}_windows_amd64.exe'
|
WINDOWS: '{{.BIN_DIR}}/{{.PROGRAM}}_windows_amd64.exe'
|
||||||
LINUX: '{{.BIN_DIR}}/{{.PROGRAM}}_linux_amd64'
|
LINUX: '{{.BIN_DIR}}/{{.PROGRAM}}_linux_amd64'
|
||||||
|
MACOS: '{{.BIN_DIR}}/{{.PROGRAM}}_darwin_amd64'
|
||||||
|
|
||||||
tasks:
|
tasks:
|
||||||
default:
|
default:
|
||||||
@ -22,6 +23,7 @@ tasks:
|
|||||||
cmds:
|
cmds:
|
||||||
- task: build-windows
|
- task: build-windows
|
||||||
- task: build-linux
|
- task: build-linux
|
||||||
|
- task: build-macos
|
||||||
|
|
||||||
vet:
|
vet:
|
||||||
desc: Vet the code
|
desc: Vet the code
|
||||||
@ -46,6 +48,12 @@ tasks:
|
|||||||
- GOOS=linux GOARCH=amd64 go build -o {{.LINUX}} -ldflags="-X main.version={{.VERSION}}"
|
- GOOS=linux GOARCH=amd64 go build -o {{.LINUX}} -ldflags="-X main.version={{.VERSION}}"
|
||||||
internal: true
|
internal: true
|
||||||
|
|
||||||
|
build-macos:
|
||||||
|
desc: Build the ignr project for macOS
|
||||||
|
cmds:
|
||||||
|
- GOOS=darwin GOARCH=amd64 go build -o {{.MACOS}} -ldflags="-X main.version={{.VERSION}}"
|
||||||
|
internal: true
|
||||||
|
|
||||||
test:
|
test:
|
||||||
desc: Run tests
|
desc: Run tests
|
||||||
cmds:
|
cmds:
|
||||||
|
|||||||
26
main.go
26
main.go
@ -3,6 +3,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"runtime/debug"
|
"runtime/debug"
|
||||||
"strings"
|
"strings"
|
||||||
@ -45,16 +46,31 @@ func init() {
|
|||||||
viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))
|
viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))
|
||||||
viper.SetEnvPrefix("IGNR")
|
viper.SetEnvPrefix("IGNR")
|
||||||
viper.AutomaticEnv()
|
viper.AutomaticEnv()
|
||||||
viper.BindPFlag("token", rootCmd.PersistentFlags().Lookup("token"))
|
if err := viper.BindPFlag("token", rootCmd.PersistentFlags().Lookup("token")); err != nil {
|
||||||
viper.BindPFlag("height", rootCmd.PersistentFlags().Lookup("height"))
|
log.Fatal(err)
|
||||||
viper.BindPFlag("filter", rootCmd.PersistentFlags().Lookup("filter"))
|
}
|
||||||
viper.BindPFlag("start-search", rootCmd.PersistentFlags().Lookup("start-search"))
|
if err := viper.BindPFlag("height", rootCmd.PersistentFlags().Lookup("height")); err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := viper.BindPFlag("filter", rootCmd.PersistentFlags().Lookup("filter")); err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := viper.BindPFlag(
|
||||||
|
"start-search",
|
||||||
|
rootCmd.PersistentFlags().Lookup("start-search"),
|
||||||
|
); err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// main is the entry point of the application.
|
// main is the entry point of the application.
|
||||||
// It executes the root command and handles any errors.
|
// It executes the root command and handles any errors.
|
||||||
func main() {
|
func main() {
|
||||||
if err := fang.Execute(context.Background(), rootCmd, fang.WithVersion(versionFromBuild())); err != nil {
|
if err := fang.Execute(
|
||||||
|
context.Background(),
|
||||||
|
rootCmd,
|
||||||
|
fang.WithVersion(versionFromBuild()),
|
||||||
|
); err != nil {
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
16
new.go
16
new.go
@ -20,9 +20,7 @@ var newCmd = &cobra.Command{
|
|||||||
Use: "new",
|
Use: "new",
|
||||||
Short: "Create a new .gitignore file",
|
Short: "Create a new .gitignore file",
|
||||||
Args: cobra.NoArgs,
|
Args: cobra.NoArgs,
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: runNewCommand,
|
||||||
return runNewCommand(cmd, args)
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -61,7 +59,11 @@ func runNewCommand(cmd *cobra.Command, _ []string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error opening file '%s': %w", gitignoreFileName, err)
|
return fmt.Errorf("error opening file '%s': %w", gitignoreFileName, err)
|
||||||
}
|
}
|
||||||
defer f.Close()
|
defer func() {
|
||||||
|
if err := f.Close(); err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "error closing file '%s': %v\n", gitignoreFileName, err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
if err = commitGitignore(content, f); err != nil {
|
if err = commitGitignore(content, f); err != nil {
|
||||||
return fmt.Errorf("error committing gitignore file: %w", err)
|
return fmt.Errorf("error committing gitignore file: %w", err)
|
||||||
@ -108,7 +110,11 @@ func runPrompt(client *github.Client, pc *promptConfig) (*github.Gitignore, erro
|
|||||||
|
|
||||||
// commitGitignore writes the content of the selected gitignore template to the .gitignore file.
|
// commitGitignore writes the content of the selected gitignore template to the .gitignore file.
|
||||||
func commitGitignore(content *github.Gitignore, w io.Writer) error {
|
func commitGitignore(content *github.Gitignore, w io.Writer) error {
|
||||||
if _, err := fmt.Fprintf(w, "# Generated by ignr: github.com/onyx-and-iris/ignr\n\n## %s ##\n", content.GetName()); err != nil {
|
if _, err := fmt.Fprintf(
|
||||||
|
w,
|
||||||
|
"# Generated by ignr: github.com/onyx-and-iris/ignr\n\n## %s ##\n",
|
||||||
|
content.GetName(),
|
||||||
|
); err != nil {
|
||||||
return fmt.Errorf("error writing header to file '%s': %w", gitignoreFileName, err)
|
return fmt.Errorf("error writing header to file '%s': %w", gitignoreFileName, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user