how skip file in golangci-lint?
Asked Answered
D

2

5

I try go1.16

import "embed"

I get

> golangci-lint run ./...
> Can't run linter goanalysis_metalinter: bodyclose: failed prerequisites ... could not import embed

how skip file/package in golangci-lint?

Disband answered 1/2, 2021 at 0:52 Comment(0)
P
8

Using a config file

You can customize the behavior with a config file. Docs are here https://golangci-lint.run/usage/configuration/. Make a .golangci.yml file that looks like this:

run:
  skip-files:
    - main.go

//nolint

You can add //nolint to the top of the file.

//nolint
package foo

See https://golangci-lint.run/usage/false-positives/

Pisces answered 1/2, 2021 at 1:27 Comment(3)
I think the problem may be related to these issues: - 1466 - 913Disband
Ah, I see. Yea, I just ran my solution with a pkg does not exist, and it does not ignore it properly.Pisces
Seems run.skip-files is deprecated. issues.exclude-files instead.Andraandrade
A
0

2024 SEPT Update

You may want to try linters.disable.body-close. But this will simply disable the linter, whether the code works or not depends on you.

linters:
  disable:
    - bodyclose

An update on the previous answer by @steven-masley

run.skip-files is deprecated and replaced with issues.exclude-files as of 2024 March by this PR. run.skip-dirs is also replaced by issues.exclude-dirs.

Both run.skip-* and issues.exclude-* will still analyze the files, but simply not report them. Originally run.skip-* has caused confusion to some (e.g. "why is it still taking so long even if I skipped a large file?"), which is why it has been replaced with issues.exclude-*. (I personally don't see a huge difference.)

So if you have a large file you want to "actually" skip, you may want to refer to this answer.

Andraandrade answered 6/9 at 4:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.