Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

golangci-lint: add capability to autofix #2700

Merged
merged 5 commits into from
Jun 7, 2023
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
9 changes: 9 additions & 0 deletions .automation/test/golang/golang_fix_01.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// This is a package comment
package main

import "fmt"

func main() {
fmt.Println("hello world")
nicolas()
}
8 changes: 8 additions & 0 deletions .automation/test/golang/golang_fix_02.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// This is a package comment
package main

import "fmt"

func nicolas() {
fmt.Println("hello world")
}
45 changes: 8 additions & 37 deletions .github/linters/.golangci.yml
Original file line number Diff line number Diff line change
@@ -1,40 +1,11 @@
---
#########################
#########################
## Golang Linter rules ##
#########################
#########################

# configure golangci-lint
# see https://github.com/golangci/golangci-lint/blob/master/.golangci.example.yml
issues:
exclude-rules:
- path: _test\.go
linters:
- dupl
- gosec
- goconst
linters:
disable-all: true
enable:
- golint
- gosec
- unconvert
- gocyclo
- goconst
- goimports
- maligned
- gofmt
- gocritic
linters-settings:
errcheck:
# report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`;
# default is false: such cases aren't reported by default.
check-blank: true
govet:
# report about shadowed variables
check-shadowing: true
gocyclo:
# minimal code complexity to report, 30 by default
min-complexity: 15
maligned:
# print struct with more effective memory layout or not, false by default
suggest-new: true
- gosimple
- govet
- ineffassign
- staticcheck
- typecheck
- unused
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

Note: Can be used with `oxsecurity/megalinter@beta` in your GitHub Action mega-linter.yml file, or with `oxsecurity/megalinter:beta` docker image

- cljstyle: Remove default value for configuration file name
- Linter enhancements & fixes
- cljstyle: Remove default value for configuration file name
- golangci-lint : Add autofix capability using **--fix** argument

- Linter versions upgrades
- [clj-kondo](https://github.com/borkdude/clj-kondo) from 2023.05.18 to **2023.05.26** on 2023-06-01
Expand Down
45 changes: 8 additions & 37 deletions TEMPLATES/.golangci.yml
Original file line number Diff line number Diff line change
@@ -1,40 +1,11 @@
---
#########################
#########################
## Golang Linter rules ##
#########################
#########################

# configure golangci-lint
# see https://github.com/golangci/golangci-lint/blob/master/.golangci.example.yml
issues:
exclude-rules:
- path: _test\.go
linters:
- dupl
- gosec
- goconst
linters:
disable-all: true
enable:
- golint
- gosec
- unconvert
- gocyclo
- goconst
- goimports
- maligned
- gofmt
- gocritic
linters-settings:
errcheck:
# report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`;
# default is false: such cases aren't reported by default.
check-blank: true
govet:
# report about shadowed variables
check-shadowing: true
gocyclo:
# minimal code complexity to report, 30 by default
min-complexity: 15
maligned:
# print struct with more effective memory layout or not, false by default
suggest-new: true
- gosimple
- govet
- ineffassign
- staticcheck
- typecheck
- unused
1 change: 1 addition & 0 deletions megalinter/descriptors/go.megalinter-descriptor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ linters:
cli_lint_mode: list_of_files
cli_lint_extra_args:
- "run"
cli_lint_fix_arg_name: --fix
cli_version_arg_name: "version"
version_extract_regex: "((\\d+(\\.\\d+)+)|(master))"
examples:
Expand Down