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

New Rule: Avoid spec Pollution #141

Merged
merged 1 commit into from
Mar 18, 2024
Merged

New Rule: Avoid spec Pollution #141

merged 1 commit into from
Mar 18, 2024

Conversation

nunnatsa
Copy link
Owner

Description

Does not allow variable assignments in container nodes. See here for more details: https://onsi.github.io/ginkgo/#avoid-spec-pollution-dont-initialize-variables-in-container-nodes

This rule is disabled by default. use the --forbid-spec-pollution=true flag to enable it.

For example, this code will trigger a warning:

var _ = Describe("description", func(){
    var x = 10
    ...
})

Instead, use BeforeEach(); e.g.

var _ = Describe("description", func (){
    var x int

    BeforeEach(func (){
        x = 10
    })
    ...
})

Closes: #136

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

  • Added test case and related test data
  • Update the functional test

Checklist:

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules
  • I ran golangci-lint

Does not allow variable assignments in container nodes. See here for
more details: https://onsi.github.io/ginkgo/#avoid-spec-pollution-dont-initialize-variables-in-container-nodes

This rule is disabled by default. use the `--forbid-spec-pollution=true`
flag to enable it.

For example, this code will trigger a warning:
```go
var _ = Describe("description", func(){
    var x = 10
    ...
})
```

Instead, use `BeforeEach()`; e.g.
```go
var _ = Describe("description", func (){
    var x int

    BeforeEach(func (){
        x = 10
    })
    ...
})
```
@coveralls
Copy link
Collaborator

Pull Request Test Coverage Report for Build 8324983153

Details

  • 2 of 22 (9.09%) changed or added relevant lines in 3 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage decreased (-3.2%) to 63.95%

Changes Missing Coverage Covered Lines Changed/Added Lines %
internal/ginkgohandler/handler.go 0 20 0.0%
Files with Coverage Reduction New Missed Lines %
internal/ginkgohandler/handler.go 1 47.46%
Totals Coverage Status
Change from base Build 8321952766: -3.2%
Covered Lines: 204
Relevant Lines: 319

💛 - Coveralls

@nunnatsa nunnatsa merged commit 8b053db into main Mar 18, 2024
1 check passed
@nunnatsa nunnatsa deleted the vars-in-containers branch March 18, 2024 10:30
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

Successfully merging this pull request may close these issues.

[Enhancement] Linter to avoid spec pollution
2 participants