Skip to content

Commit 5a2d556

Browse files
committed
importas
1 parent 5c6f570 commit 5a2d556

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@
172172
+ [➡ Detect global variables with `gochecknoglobals`](#-detect-global-variables-with-gochecknoglobals)
173173
+ [➡ Detect slices that could be preallocated with `prealloc`](#-detect-slices-that-could-be-preallocated-with-prealloc)
174174
+ [➡ Detect unnecessary import aliases with `unimport`](#-detect-unnecessary-import-aliases-with-unimport)
175+
+ [➡ Detect unexpected import aliases with `importas`](#-detect-unexpected-import-aliases-with-importas)
175176
+ [➡ Detect naked returns with `nakedret`](#-detect-naked-returns-with-nakedret)
176177
+ [➡ Detect mixing pointer and value method receivers with `smrcptr`](#-detect-mixing-pointer-and-value-method-receivers-with-smrcptr)
177178
+ [➡ Detect vertical function ordering with `vertfn`](#-detect-vertical-function-ordering-with-vertfn)
@@ -3113,6 +3114,32 @@ Requirements
31133114
go install github.com/alexkohler/unimport@latest
31143115
```
31153116

3117+
### [⏫](#contents)➡ Detect unexpected import aliases with [importas](https://github.com/julz/importas)
3118+
3119+
Ensure that import aliases take one of the allowed values. — [@julz](https://github.com/julz)
3120+
3121+
3122+
```
3123+
importas -alias knative.dev/serving/pkg/apis/autoscaling/v1alpha1:autoscalingv1alpha1 -alias knative.dev/serving/pkg/apis/serving/v1:servingv1 ./...
3124+
```
3125+
3126+
```go
3127+
package main
3128+
3129+
import (
3130+
v1alpha1 "knative.dev/serving/pkg/apis/autoscaling/v1alpha1" // want `import "knative.dev/serving/pkg/apis/autoscaling/v1alpha1" imported as "v1alpha1" but must be "autoscalingv1alpha1" according to config`
3131+
v1 "knative.dev/serving/pkg/apis/serving/v1" // want `import "knative.dev/serving/pkg/apis/serving/v1" imported as "v1" but must be "servingv1" according to config`
3132+
)
3133+
3134+
func main() {
3135+
...
3136+
```
3137+
3138+
Requirements
3139+
```
3140+
go install github.com/julz/importas/cmd/importas@latest
3141+
```
3142+
31163143
### [⏫](#contents)➡ Detect naked returns with [nakedret](https://github.com/alexkohler/nakedret)
31173144

31183145
It is common guideline to avoid [naked returns](https://github.com/golang/go/wiki/CodeReviewComments#named-result-parameters). Naked return is when function has named return, and return statement does not specify value. This tool is useful for investigations. — [@alexkohler](https://github.com/alexkohler)

page.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2118,6 +2118,26 @@ groups:
21182118
pkg/apis/apps/v1beta1/zz_generated.conversion.go:31 unnecessary import alias runtime
21192119
requirements:
21202120
- go install github.com/alexkohler/unimport@latest
2121+
- title: Detect unexpected import aliases
2122+
description: Ensure that import aliases take one of the allowed values.
2123+
url: https://github.com/julz/importas
2124+
name: importas
2125+
author: https://github.com/julz
2126+
example_content_ext: go
2127+
example_content: |
2128+
package main
2129+
2130+
import (
2131+
v1alpha1 "knative.dev/serving/pkg/apis/autoscaling/v1alpha1" // want `import "knative.dev/serving/pkg/apis/autoscaling/v1alpha1" imported as "v1alpha1" but must be "autoscalingv1alpha1" according to config`
2132+
v1 "knative.dev/serving/pkg/apis/serving/v1" // want `import "knative.dev/serving/pkg/apis/serving/v1" imported as "v1" but must be "servingv1" according to config`
2133+
)
2134+
2135+
func main() {
2136+
...
2137+
commands:
2138+
- importas -alias knative.dev/serving/pkg/apis/autoscaling/v1alpha1:autoscalingv1alpha1 -alias knative.dev/serving/pkg/apis/serving/v1:servingv1 ./...
2139+
requirements:
2140+
- go install github.com/julz/importas/cmd/importas@latest
21212141
- title: Detect naked returns
21222142
description: "It is common guideline to avoid [naked returns](https://github.com/golang/go/wiki/CodeReviewComments#named-result-parameters). Naked return is when function has named return, and return statement does not specify value. This tool is useful for investigations."
21232143
url: https://github.com/alexkohler/nakedret

0 commit comments

Comments
 (0)