Skip to content

Commit

Permalink
Add golangci-lint linter to enforce that the io/ioutil package is n…
Browse files Browse the repository at this point in the history
…ot used anymore (#34)

This makes use of the `golangci-lint` [1] linters aggregator, configured with the `depguard`[2] linter to enforce that the deprecated `io/ioutil` [3] package is not used anymore in the code.

NOTE: Ideally, we should use all linters enabled by default by `golangci-lint`. But doing so reports a lot of issues, not relevant to the issue here (which is to enforce that 'io/ioutil' is not used anymore).
Enabling the default linters and fixing the issues reported can be done in a subsequent issue/PR.

[1] https://golangci-lint.run/
[2] https://golangci-lint.run/usage/linters/#depguard
[3] https://pkg.go.dev/io/ioutil#pkg-overview

Signed-off-by: Armel Soro <asoro@redhat.com>
  • Loading branch information
rm3l authored Oct 24, 2023
1 parent 83ea268 commit b3ac16d
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ jobs:
- name: Run Go tests
run: make test

- name: Lint
run: |
make lint_install
make lint
- name: Run Gosec Security Scanner
run: |
make gosec_install
Expand Down
44 changes: 44 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Refer to golangci-lint's reference config file for more options and information:
# https://github.com/golangci/golangci-lint/blob/master/.golangci.reference.yml

run:
# Timeout for analysis, e.g. 30s, 5m.
# Default: 1m
timeout: 5m

# Allowed values: readonly|vendor|mod
# By default, it isn't set.
modules-download-mode: readonly

skip-dirs:
- resources/projects

linters:
# Disable all linters.
# Default: false
# TODO(rm3l): all default linters are disabled in the context of https://github.com/devfile/api/issues/1257 (to just enforce that io/ioutil is not used anymore),
# but we should think about enabling all the default linters and fix the issues reported.
disable-all: true
enable:
# Go linter that checks if package imports are in a list of acceptable packages
- depguard

linters-settings:
depguard:
rules:
# Name of a rule.
main:
deny:
- pkg: "io/ioutil"
desc: "Deprecated since Go 1.16. Use the implementations from 'io' or 'os' packages instead."

issues:
# Maximum issues count per one linter.
# Set to 0 to disable.
# Default: 50
max-issues-per-linter: 0

# Maximum count of issues with the same text.
# Set to 0 to disable.
# Default: 3
max-same-issues: 0
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,12 @@ gosec_install: ## Install gosec utility
.PHONY: gosec
gosec: ## Run go security checks
./scripts/run_gosec.sh

.PHONY: lint
lint: ## Run golangci-lint linter tool
golangci-lint run ./... --timeout 15m

.PHONY: lint_install
lint_install: ## Install golangci-lint linter tool
@# TODO(rm3l): recent versions of golangci-lint require Go >= 1.20. Update when we start using Go 1.20+
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.53.3

0 comments on commit b3ac16d

Please sign in to comment.