Skip to content

Commit

Permalink
Add tests to main configuration
Browse files Browse the repository at this point in the history
Signed-off-by: Will Dixon <[email protected]>
  • Loading branch information
dixonwille committed Oct 31, 2023
1 parent e9b5e24 commit 7052316
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 101 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@
*.out

.idea
.null-ls*.go
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ The following is an example configuration file.
"$all",
"!$test"
],
"listMode": "Strict",
"allow": [
"$gostd",
"github.com/OpenPeeDeeP"
Expand All @@ -36,6 +37,7 @@ The following is an example configuration file.
"files": [
"$test"
],
"listMode": "Lax",
"deny": {
"github.com/stretchr/testify": "Please use standard library for tests"
}
Expand All @@ -48,6 +50,7 @@ the linter's output.
- `files` - list of file globs that will match this list of settings to compare against
- `allow` - list of allowed packages
- `deny` - map of packages that are not allowed where the value is a suggestion
= `listMode` - the mode to use for package matching

Files are matched using [Globs](https://github.com/gobwas/glob). If the files
list is empty, then all files will match that list. Prefixing a file
Expand All @@ -67,6 +70,21 @@ A Prefix List just means that a package will match a value, if the value is a
prefix of the package. Example `github.com/OpenPeeDeeP/depguard` package will match
a value of `github.com/OpenPeeDeeP` but won't match `github.com/OpenPeeDeeP/depguard/v2`.

ListMode is used to determine the package matching priority. There are three
different modes; Original, Strict, and Lax.

Original is the original way that the package was written to use. It is not recommended
to stay with this and is only here for backwards compatibility.

Strict, at its roots, is everything is denied unless in allowed.

Lax, at its roots, is everything is allowed unless it is denied.

There are cases where a package can be matched in both the allow and denied lists.
You may allow a subpackage but deny the root or vice versa. The `settings_tests.go` file
has many scenarios listed out under `TestListImportAllowed`. These tests will stay
up to date as features are added.

### Variables

There are variable replacements for each type of list (file or package). This is
Expand Down
5 changes: 3 additions & 2 deletions cmd/depguard/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ var testfiles embed.FS

var expectedConfigStruct = &depguard.LinterSettings{
"main": &depguard.List{
Files: []string{"$all", "!$test"},
Allow: []string{"$gostd", "github.com/"},
ListMode: "Strict",
Files: []string{"$all", "!$test"},
Allow: []string{"$gostd", "github.com/"},
Deny: map[string]string{
"reflect": "Who needs reflection",
"github.com/OpenPeeDeeP": "Use Something Else",
Expand Down
3 changes: 2 additions & 1 deletion cmd/depguard/testfiles/.depguard.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"$all",
"!$test"
],
"listMode": "Strict",
"allow": [
"$gostd",
"github.com/"
Expand All @@ -24,4 +25,4 @@
"github.com/OpenPeeDeeP/": "Use Something Else"
}
}
}
}
3 changes: 2 additions & 1 deletion cmd/depguard/testfiles/.depguard.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ files = [
"$all",
"!$test"
]
listMode = "Strict"
allow = [
"$gostd",
"github.com/"
Expand All @@ -19,4 +20,4 @@ allow = [
"github.com/test"
]
[tests.deny]
"github.com/OpenPeeDeeP/" = "Use Something Else"
"github.com/OpenPeeDeeP/" = "Use Something Else"
3 changes: 2 additions & 1 deletion cmd/depguard/testfiles/.depguard.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ main:
files:
- "$all"
- "!$test"
listMode: Strict
allow:
- "$gostd"
- github.com/
Expand All @@ -14,4 +15,4 @@ tests:
allow:
- github.com/test
deny:
github.com/OpenPeeDeeP/: Use Something Else
github.com/OpenPeeDeeP/: Use Something Else
Loading

0 comments on commit 7052316

Please sign in to comment.