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

Add golangci-lint linter to enforce that the io/ioutil package is not used anymore #34

Merged

Conversation

rm3l
Copy link
Member

@rm3l rm3l commented Oct 24, 2023

What does this PR do?

This PR 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

Which issue(s) does this PR fix

Fixes devfile/api#1257

PR acceptance criteria

  • Unit/Functional tests

  • Documentation

How to test changes / Special notes to the reviewer

# Install golangci-lint
$ make lint_install

# Run linter. It should pass.
$ make lint        
golangci-lint run ./... --timeout 15m

$ echo $?
0

Below is an example of error reported should io/ioutil be used again:

☸ in ~/w/p/d/alizer on  1257-replace-alizer-io-ioutil-dependency--linter-checks (REVERTING) [$+⇡] via 🐹 v1.19.13 
$ make lint        
golangci-lint run ./... --timeout 15m
pkg/apis/enricher/framework/dotnet/dotnet_detector.go:18:2: import 'io/ioutil' is not allowed from list 'main': Deprecated since Go 1.16. Use the implementations from 'io' or 'os' packages instead. (depguard)
        "io/ioutil"
        ^
pkg/apis/recognizer/devfile_recognizer.go:19:2: import 'io/ioutil' is not allowed from list 'main': Deprecated since Go 1.16. Use the implementations from 'io' or 'os' packages instead. (depguard)
        "io/ioutil"
        ^
pkg/utils/detector.go:23:2: import 'io/ioutil' is not allowed from list 'main': Deprecated since Go 1.16. Use the implementations from 'io' or 'os' packages instead. (depguard)
        "io/ioutil"
        ^
test/check_registry/check_registry.go:6:2: import 'io/ioutil' is not allowed from list 'main': Deprecated since Go 1.16. Use the implementations from 'io' or 'os' packages instead. (depguard)
        "io/ioutil"
        ^
make: *** [Makefile:39: lint] Error 1

…outil' is not used anymore

Instead of using individual linters, we rely on golangci-lint,
which is a Go linters aggregrator that runs linters in parallel.

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
will be done in a subsequent issue/PR.

[1] https://golangci-lint.run/
[2] https://golangci-lint.run/usage/linters/#depguard

Signed-off-by: Armel Soro <asoro@redhat.com>
Signed-off-by: Armel Soro <asoro@redhat.com>
Copy link
Contributor

@thepetk thepetk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@openshift-ci
Copy link

openshift-ci bot commented Oct 24, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: rm3l, thepetk

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@rm3l rm3l changed the title Add linter to enforce that the io/ioutil package is not used anymore Add golangci-lint linter to enforce that the io/ioutil package is not used anymore Oct 24, 2023
@rm3l rm3l merged commit b3ac16d into devfile:main Oct 24, 2023
4 checks passed
@rm3l rm3l deleted the 1257-replace-alizer-io-ioutil-dependency--linter-checks branch October 24, 2023 14:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Replace Alizer io/ioutil dependency
2 participants