mirror of
https://github.com/onyx-and-iris/ignr.git
synced 2026-03-03 08:59: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
|
||||
with:
|
||||
go-version: '1.24'
|
||||
- name: Install golangci-lint
|
||||
run: go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
|
||||
- name: Run golangci-lint
|
||||
run: golangci-lint run ./...
|
||||
- name: golangci-lint
|
||||
uses: golangci/golangci-lint-action@v9
|
||||
with:
|
||||
version: v2.6.0
|
||||
args: --config .golangci.yml
|
||||
|
||||
168
.golangci.yml
168
.golangci.yml
@ -1,54 +1,142 @@
|
||||
version: '2'
|
||||
|
||||
run:
|
||||
# timeout for analysis, e.g. 30s, 3m, default is 1m
|
||||
timeout: 3m
|
||||
# exclude test files
|
||||
tests: true
|
||||
go: '1.24'
|
||||
|
||||
linters:
|
||||
# Set to true runs only fast linters.
|
||||
# Good option for 'lint on save', pre-commit hook or CI.
|
||||
fast: true
|
||||
|
||||
disable-all: true
|
||||
|
||||
disable: []
|
||||
enable:
|
||||
- gosimple
|
||||
- govet
|
||||
- ineffassign
|
||||
- staticcheck
|
||||
- unused
|
||||
- gofmt
|
||||
- gofumpt
|
||||
- misspell
|
||||
- unparam
|
||||
- gosec
|
||||
- asciicheck
|
||||
- errname
|
||||
- gci
|
||||
- godot
|
||||
- goimports
|
||||
- revive
|
||||
|
||||
linters-settings:
|
||||
gofmt:
|
||||
rewrite-rules:
|
||||
- pattern: 'interface{}'
|
||||
replacement: 'any'
|
||||
- pattern: 'a[b:len(a)]'
|
||||
replacement: 'a[b:]'
|
||||
# Default enabled linters
|
||||
- errcheck # Check for unchecked errors
|
||||
- govet # Go's built-in vetting tool
|
||||
- ineffassign # Detect ineffectual assignments
|
||||
- staticcheck # Advanced static analysis
|
||||
- unused # Check for unused code
|
||||
# Additional useful linters
|
||||
- misspell # Detect common misspellings
|
||||
- unparam # Check for unused function parameters
|
||||
- gosec # Security checks
|
||||
- asciicheck # Check for non-ASCII characters
|
||||
- errname # Check error variable names
|
||||
- godot # Check for missing periods in comments
|
||||
- revive # Highly configurable linter for style and correctness
|
||||
- gocritic # Detect code issues and suggest improvements
|
||||
- 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
|
||||
|
||||
settings:
|
||||
misspell:
|
||||
locale: UK
|
||||
|
||||
errcheck:
|
||||
check-type-assertions: true
|
||||
check-blank: true
|
||||
exclude-functions:
|
||||
- fmt.Fprintf
|
||||
- fmt.Fprintln
|
||||
- fmt.Printf
|
||||
- fmt.Println
|
||||
- fmt.Errorf
|
||||
|
||||
revive:
|
||||
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:
|
||||
max-same-issues: 0
|
||||
max-issues-per-linter: 0
|
||||
exclude-use-default: false
|
||||
exclude:
|
||||
# gosec: Duplicated errcheck checks
|
||||
- G104
|
||||
# gosec: integer overflow conversion int -> uint32
|
||||
- G115
|
||||
# Limit the number of same issues reported to avoid spam
|
||||
max-same-issues: 50
|
||||
|
||||
# Limit the number of issues per linter to keep output manageable
|
||||
max-issues-per-linter: 100
|
||||
|
||||
@ -9,6 +9,7 @@ vars:
|
||||
|
||||
WINDOWS: '{{.BIN_DIR}}/{{.PROGRAM}}_windows_amd64.exe'
|
||||
LINUX: '{{.BIN_DIR}}/{{.PROGRAM}}_linux_amd64'
|
||||
MACOS: '{{.BIN_DIR}}/{{.PROGRAM}}_darwin_amd64'
|
||||
|
||||
tasks:
|
||||
default:
|
||||
@ -22,6 +23,7 @@ tasks:
|
||||
cmds:
|
||||
- task: build-windows
|
||||
- task: build-linux
|
||||
- task: build-macos
|
||||
|
||||
vet:
|
||||
desc: Vet the code
|
||||
@ -46,6 +48,12 @@ tasks:
|
||||
- GOOS=linux GOARCH=amd64 go build -o {{.LINUX}} -ldflags="-X main.version={{.VERSION}}"
|
||||
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:
|
||||
desc: Run tests
|
||||
cmds:
|
||||
|
||||
26
main.go
26
main.go
@ -3,6 +3,7 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"os"
|
||||
"runtime/debug"
|
||||
"strings"
|
||||
@ -45,16 +46,31 @@ func init() {
|
||||
viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))
|
||||
viper.SetEnvPrefix("IGNR")
|
||||
viper.AutomaticEnv()
|
||||
viper.BindPFlag("token", rootCmd.PersistentFlags().Lookup("token"))
|
||||
viper.BindPFlag("height", rootCmd.PersistentFlags().Lookup("height"))
|
||||
viper.BindPFlag("filter", rootCmd.PersistentFlags().Lookup("filter"))
|
||||
viper.BindPFlag("start-search", rootCmd.PersistentFlags().Lookup("start-search"))
|
||||
if err := viper.BindPFlag("token", rootCmd.PersistentFlags().Lookup("token")); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
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.
|
||||
// It executes the root command and handles any errors.
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
16
new.go
16
new.go
@ -20,9 +20,7 @@ var newCmd = &cobra.Command{
|
||||
Use: "new",
|
||||
Short: "Create a new .gitignore file",
|
||||
Args: cobra.NoArgs,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return runNewCommand(cmd, args)
|
||||
},
|
||||
RunE: runNewCommand,
|
||||
}
|
||||
|
||||
func init() {
|
||||
@ -61,7 +59,11 @@ func runNewCommand(cmd *cobra.Command, _ []string) error {
|
||||
if err != nil {
|
||||
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 {
|
||||
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.
|
||||
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)
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user