-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
passes/R006: Add
-package-aliases
flag (#239)
Certain providers may wish to shim `helper/resource` functionality to prevent multiple module version issues while upgrading. When using type aliasing for `RetryError` and method expressions for `RetryableError` (or a passthrough implementation), the `R006` pass cannot be satisfied due to the mismatched package naming of `RetryableError`. Instead, we can allow callers to declare their alias/shim package paths to additionally ignore reports. The only requirement is that the shimmed method expression or function name must still be `RetryableError`.
- Loading branch information
Showing
13 changed files
with
191 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package a | ||
|
||
import ( | ||
"a/methodexpression" | ||
) | ||
|
||
func fmethodexpression() *methodexpression.RetryError { // want "RetryFunc should include RetryableError\\(\\) handling or be removed" | ||
return methodexpression.RetryableError(nil) | ||
} |
9 changes: 9 additions & 0 deletions
9
passes/R006/testdata/src/a/methodexpression/methodexpression.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package methodexpression | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
) | ||
|
||
type RetryError = resource.RetryError | ||
|
||
var RetryableError = resource.RetryableError |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package a | ||
|
||
import ( | ||
"a/resource" | ||
) | ||
|
||
func foutside() *resource.RetryError { | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package resource | ||
|
||
type RetryError struct{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package a | ||
|
||
import ( | ||
"errors" | ||
"time" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/helper/resource" | ||
) | ||
|
||
//lintignore:R006 | ||
func commentIgnore() *resource.RetryError { | ||
return nil | ||
} | ||
|
||
func failingAnonymousRetryFunc() { | ||
_ = resource.Retry(1*time.Minute, func() *resource.RetryError { // want "RetryFunc should include RetryableError\\(\\) handling or be removed" | ||
return nil | ||
}) | ||
} | ||
|
||
func failingNoCallExpr() *resource.RetryError { // want "RetryFunc should include RetryableError\\(\\) handling or be removed" | ||
return nil | ||
} | ||
|
||
func failingOnlyNonRetryableError() *resource.RetryError { // want "RetryFunc should include RetryableError\\(\\) handling or be removed" | ||
return resource.NonRetryableError(errors.New("")) | ||
} | ||
|
||
func passingAnonymousRetryFunc() { | ||
_ = resource.Retry(1*time.Minute, func() *resource.RetryError { | ||
return resource.RetryableError(errors.New("")) | ||
}) | ||
} | ||
|
||
func passingMultipleCallExpr() *resource.RetryError { | ||
_ = resource.RetryableError(errors.New("")) | ||
_ = resource.NonRetryableError(errors.New("")) | ||
|
||
return nil | ||
} | ||
|
||
func passingRetryableError() *resource.RetryError { | ||
return resource.RetryableError(errors.New("")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package a | ||
|
||
import ( | ||
"errors" | ||
"time" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
) | ||
|
||
//lintignore:R006 | ||
func commentIgnore_v2() *resource.RetryError { | ||
return nil | ||
} | ||
|
||
func failingAnonymousRetryFunc_v2() { | ||
_ = resource.Retry(1*time.Minute, func() *resource.RetryError { // want "RetryFunc should include RetryableError\\(\\) handling or be removed" | ||
return nil | ||
}) | ||
} | ||
|
||
func failingNoCallExpr_v2() *resource.RetryError { // want "RetryFunc should include RetryableError\\(\\) handling or be removed" | ||
return nil | ||
} | ||
|
||
func failingOnlyNonRetryableError_v2() *resource.RetryError { // want "RetryFunc should include RetryableError\\(\\) handling or be removed" | ||
return resource.NonRetryableError(errors.New("")) | ||
} | ||
|
||
func passingAnonymousRetryFunc_v2() { | ||
_ = resource.Retry(1*time.Minute, func() *resource.RetryError { | ||
return resource.RetryableError(errors.New("")) | ||
}) | ||
} | ||
|
||
func passingMultipleCallExpr_v2() *resource.RetryError { | ||
_ = resource.RetryableError(errors.New("")) | ||
_ = resource.NonRetryableError(errors.New("")) | ||
|
||
return nil | ||
} | ||
|
||
func passingRetryableError_v2() *resource.RetryError { | ||
return resource.RetryableError(errors.New("")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package a | ||
|
||
import ( | ||
"a/methodexpression" | ||
) | ||
|
||
func fmethodexpression() *methodexpression.RetryError { | ||
return methodexpression.RetryableError(nil) | ||
} |
9 changes: 9 additions & 0 deletions
9
passes/R006/testdata/src/packagealiases/methodexpression/methodexpression.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package methodexpression | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
) | ||
|
||
type RetryError = resource.RetryError | ||
|
||
var RetryableError = resource.RetryableError |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../../vendor |