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

Ignore function lines lint #7

Closed
liubog2008 opened this issue Aug 25, 2020 · 7 comments
Closed

Ignore function lines lint #7

liubog2008 opened this issue Aug 25, 2020 · 7 comments

Comments

@liubog2008
Copy link

Sometimes we need to init a huge structure which must consume more than 60 lines. It can't be split to multiple function.

@robinknaapen
Copy link
Contributor

@liubog2008

Could you provide an example please? I am having a hard time understanding your issue

@liubog2008
Copy link
Author

func initData() *Data {
    return &Data {
      ... // more than 60 lines
    }
}

@liubog2008
Copy link
Author

especially in *_test.go

@robinknaapen
Copy link
Contributor

@liubog2008

There are multiple options:

This will disable the function is to long warning for funlen in test files

exclude-rules:
  - path: "_test.go$"   # Files that this rule applies to
    text: "is too long" # Ignore when the warning includes this text
    linters:            # All linters that this rule applies to
      - funlen

You could increase the function length setting and keep the statements setting default... Note that this applies to all files in your project

linters-settings:
  funlen: # tweak these to your liking
    lines: 60
    statements: 40

You could //nolint: funlen the specific functions

//nolint: funlen
func initData() *Data {
    return &Data{
        ... // more than 60 lines
    }
}

@liubog2008
Copy link
Author

Could you add an option to just disable lines lint?

e.g.

linters-settings:
  funlen: # tweak these to your liking
    lines: -1
    statements: 40

@NiseVoid
Copy link
Contributor

This could be achieved by using the first example but without the path filter:

exclude-rules:
  - text: "is too long" # Ignore when the warning includes this text
    linters:            # All linters that this rule applies to
      - funlen

I could make a change to accept -1 to disable either lines or statements, but it would probably take a while to be in a golangci-lint release

@liubog2008
Copy link
Author

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants