Skip to content

Commit

Permalink
golangci-lint: add capability to autofix (#2700)
Browse files Browse the repository at this point in the history
* golangci-lint: add capability to fix

* Change default golangci config

* [MegaLinter] Apply linters fixes

* Change test case

* Fix go auto-fix tests

---------

Co-authored-by: nvuillam <nicolas.vuillamy@gmail.com>
Co-authored-by: nvuillam <nvuillam@users.noreply.github.com>
  • Loading branch information
3 people authored Jun 7, 2023
1 parent 152ac28 commit baabfbb
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 75 deletions.
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

0 comments on commit baabfbb

Please sign in to comment.