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 "nosleep" linter #3958

Open
powerman opened this issue Jul 19, 2023 · 4 comments
Open

Add "nosleep" linter #3958

powerman opened this issue Jul 19, 2023 · 4 comments
Labels
linter: idea idea of a linter

Comments

@powerman
Copy link

Your feature request related to a problem? Please describe.

Using time.Sleep in tests is a mistake in most of cases.

Describe the solution you'd like.

Linter should detect time.Sleep in tests.

Describe alternatives you've considered.

TBH as golangci-link contains nearly hundred of linters it's hard to say is some of existing ones can be configured to do this.

Additional context.

https://xeiaso.net/blog/nosleep

@powerman powerman added the enhancement New feature or improvement label Jul 19, 2023
@dshemin
Copy link

dshemin commented Aug 24, 2023

Hi!

You can use forbidigo linter for this case.
Just put this lines to config:

linters:
  # ...
  enable:
    # ...
    - forbidigo
    # ...
# ...
linters-settings:
  # ...
  forbidigo:
      forbid:
          - p: time.Sleep
            msg: "Avoid time.Sleep in you code please"
  #...

@powerman
Copy link
Author

Isn't this will apply both to tests and code, instead of just tests?

@bombsimon
Copy link
Member

bombsimon commented Aug 27, 2023

You can use the issues section to configure files to include/exclude:

issues:
  exclude-rules:
    - path-except: _test\.go
      linters:
        - forbidigo

@powerman
Copy link
Author

Yes, but this will exclude all rules of the linter, not just this one.
Probably it's possible to except using text: instead of linters:, but it feels like a workaround: error message text to match may change in future versions, linter will still spend time applying this rule to non-tests, etc.

@Antonboom Antonboom added the linter: idea idea of a linter label Oct 1, 2023
@ldez ldez removed the enhancement New feature or improvement label Mar 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
linter: idea idea of a linter
Projects
None yet
Development

No branches or pull requests

5 participants