Skip to content

📖 Update README.md - With instructions for GolangCI 2x #109

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
95 changes: 63 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,66 @@ If you do not have `golangci-lint` installed, review the `golangci-lint` [instal

[golangci-lint-install]: https://golangci-lint.run/welcome/install/

### Using with golangci-lint v2 Plugin

Kube API Linter can be used as a plugin with `golangci-lint` v2. This setup allows integrating Kube API Linter alongside other static analysis tools within the same linter workflow.

More information about golangci-lint plugins can be found in the [golangci-lint plugin documentation][golangci-lint-plugin-docs].

#### Plugin Setup

First, build the plugin `.so` file:

```shell
go build -buildmode=plugin -o ./bin/kube-api-linter.so sigs.k8s.io/kube-api-linter/pkg/plugin
```

This will generate a `kube-api-linter.so` plugin in the `bin` directory.

#### Configuration

Update your `.golangci.yml` with the following snippet:

```yaml
version: "2"

linters:
enable:
- kubeapilinter
...

settings:
revive:
rules:
- name: comment-spacings
- name: import-shadowing
custom:
kubeapilinter:
path: "./bin/kube-api-linter.so"
description: "Kube API Linter plugin"
original-url: "sigs.k8s.io/kube-api-linter"
settings:
linters: {}
lintersConfig: {}

exclusions:
rules:
# Only run kubeapilinter inside the 'api/' directory
# Prevents running API-specific checks on unrelated packages like controllers or tests
- path-except: "^api/"
linters:
- kubeapilinter
Comment on lines +64 to +70

Choose a reason for hiding this comment

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

Is the formatting off for the exclusions stanza here? It looks like it needs to be linters.exclusions when I was looking at integrating this linter in my repository that uses the 2.x golangci-lint version.

...
```

This approach allows full integration of Kube API Linter as a plugin, scoped correctly to relevant directories, while using `golangci-lint` v2 and coexisting with other linters.

**NOTE** For GolangCi Versions lower than 2x you might can do as follows:

You will need to create a `.custom-gcl.yml` file to describe the custom linters you want to run. The following is an example of a `.custom-gcl.yml` file:

```yaml
version: v1.64.8
version: v1.64.8 # GolangCi version
name: golangci-kube-api-linter
destination: ./bin
plugins:
Expand Down Expand Up @@ -63,6 +119,12 @@ issues:
- kubeapilinter
```

#### Optional Configurations

##### Enabling Specific Linters (Valid for Versions < 2.x)

> **Note**: The following configuration is only supported when using the **module integration** via `.custom-gcl.yml` and is **not valid in plugin mode** (`.so` files with `golangci-lint` v2.x+).
Comment on lines +124 to +126
Copy link
Contributor

Choose a reason for hiding this comment

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

This isn't true, you can do exactly the same configuration between both versions

Copy link
Member Author

@camilamacedo86 camilamacedo86 Jul 7, 2025

Choose a reason for hiding this comment

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

I tried it, but it did not work out.
Now, with your message, I found: https://github.com/golangci/golangci-lint/blob/main/.custom-gcl.reference.yml

It might changed the format. I will try out after.
Thanks!


If you wish to only run selected linters you can do so by specifying the linters you want to enable in the `linters` section:

```yaml
Expand Down Expand Up @@ -93,37 +155,6 @@ Where fixes are available within a rule, these can be applied automatically with
golangci-kube-api-linter run path/to/api/types --fix
```

### Golangci-lint Plugin

The Kube API Linter can also be used as a plugin for `golangci-lint`.
To do this, you will need to install the `golangci-lint` binary and then install the Kube API Linter plugin.

More information about golangci-lint plugins can be found in the [golangci-lint plugin documentation][golangci-lint-plugin-docs].

[golangci-lint-plugin-docs]: https://golangci-lint.run/plugins/go-plugins/

```shell
go build -buildmode=plugin -o bin/kube-api-linter.so sigs.k8s.io/kube-api-linter/pkg/plugin
```

This will create a `kube-api-linter.so` file in the `bin` directory.

The `golangci-lint` configuration is similar to the module configuration, however, you will need to specify the plugin path instead.

```yaml
linters-settings:
custom:
kubeapilinter:
path: "bin/kube-api-linter.so"
description: Kube API LInter lints Kube like APIs based on API conventions and best practices.
original-url: sigs.k8s.io/kube-api-linter
settings:
linters: {}
lintersConfig: {}
Comment on lines -114 to -122
Copy link
Contributor

Choose a reason for hiding this comment

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

Looking at the diff above, it seems we just need to update this section slightly, and the rest remains true and the same?

```

The rest of the configuration is the same as the module configuration, except the standard `golangci-lint` binary is invoked, rather than a custom binary.

#### VSCode integration

Since VSCode already integrates with `golangci-lint` via the [Go][vscode-go] extension, you can use the `golangci-kal` binary as a linter in VSCode.
Expand Down