-
Notifications
You must be signed in to change notification settings - Fork 285
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[dot-imports] support allow list of packages
Add the ability to allow list of packages to be dot imported. Add a new don-imports configuration: * `allowedPackages`: (string) comma-separated list of allowed dot import packages Example: ```toml [rule.dot-imports] arguments = [{ allowedPackages = "github.com/onsi/ginkgo/v2,github.com/onsi/gomega" }] ```
- Loading branch information
Showing
4 changed files
with
104 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/mgechev/revive/lint" | ||
"github.com/mgechev/revive/rule" | ||
) | ||
|
||
func TestDotImports(t *testing.T) { | ||
args := []any{map[string]any{ | ||
"allowedPackages": []any{"errors", "context", "github.com/BurntSushi/toml"}, | ||
}} | ||
|
||
testRule(t, "import-dot", &rule.DotImportsRule{}, &lint.RuleConfig{ | ||
Arguments: args, | ||
}) | ||
} |
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,18 @@ | ||
// Test that dot imports are flagged. | ||
|
||
// Package pkg ... | ||
package pkg | ||
|
||
import ( | ||
. "context" // in allowedPackages (standard library => just the name without full path) | ||
. "errors" // in allowedPackages (standard library => just the name without full path) | ||
. "fmt" // MATCH /should not use dot imports/ | ||
|
||
. "github.com/BurntSushi/toml" // in allowedPackages (not in the standard library) | ||
) | ||
|
||
var _ Stringer // from "fmt" | ||
var _ = New("fake error") | ||
var _ = Background() | ||
|
||
var _ = Position{} // check non a package not in the standard library |