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

fix 968 by removing references to black and white lists #969

Merged
merged 4 commits into from
Feb 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ List of all available rules. The rules ported from `golint` are left unchanged a
| [`exported`](./RULES_DESCRIPTIONS.md#exported) | []string | Naming and commenting conventions on exported symbols. | yes | no |
| [`if-return`](./RULES_DESCRIPTIONS.md#if-return) | n/a | Redundant if when returning an error. | no | no |
| [`increment-decrement`](./RULES_DESCRIPTIONS.md#increment-decrement) | n/a | Use `i++` and `i--` instead of `i += 1` and `i -= 1`. | yes | no |
| [`var-naming`](./RULES_DESCRIPTIONS.md#var-naming) | whitelist & blacklist of initialisms | Naming rules. | yes | no |
| [`var-naming`](./RULES_DESCRIPTIONS.md#var-naming) | allowlist & blocklist of initialisms | Naming rules. | yes | no |
| [`package-comments`](./RULES_DESCRIPTIONS.md#package-comments) | n/a | Package commenting conventions. | yes | no |
| [`range`](./RULES_DESCRIPTIONS.md#range) | n/a | Prevents redundant variables when iterating over a collection. | yes | no |
| [`receiver-naming`](./RULES_DESCRIPTIONS.md#receiver-naming) | n/a | Conventions around the naming of receivers. | yes | no |
Expand All @@ -504,7 +504,7 @@ List of all available rules. The rules ported from `golint` are left unchanged a
| [`bool-literal-in-expr`](./RULES_DESCRIPTIONS.md#bool-literal-in-expr)| n/a | Suggests removing Boolean literals from logic expressions | no | no |
| [`redefines-builtin-id`](./RULES_DESCRIPTIONS.md#redefines-builtin-id)| n/a | Warns on redefinitions of builtin identifiers | no | no |
| [`function-result-limit`](./RULES_DESCRIPTIONS.md#function-result-limit) | int (defaults to 3)| Specifies the maximum number of results a function can return | no | no |
| [`imports-blacklist`](./RULES_DESCRIPTIONS.md#imports-blacklist) | []string | Disallows importing the specified packages | no | no |
| [`imports-blocklist`](./RULES_DESCRIPTIONS.md#imports-blocklist) | []string | Disallows importing the specified packages | no | no |
| [`range-val-in-closure`](./RULES_DESCRIPTIONS.md#range-val-in-closure)| n/a | Warns if range value is used in a closure dispatched as goroutine| no | no |
| [`range-val-address`](./RULES_DESCRIPTIONS.md#range-val-address)| n/a | Warns if address of range value is used dangerously | no | yes |
| [`waitgroup-by-value`](./RULES_DESCRIPTIONS.md#waitgroup-by-value) | n/a | Warns on functions taking sync.WaitGroup as a by-value parameter | no | no |
Expand Down Expand Up @@ -547,7 +547,7 @@ Here you can find how you can configure some existing rules:

### `var-naming`

This rule accepts two slices of strings, a whitelist and a blacklist of initialisms. By default, the rule behaves exactly as the alternative in `golint` but optionally, you can relax it (see [golint/lint/issues/89](https://github.com/golang/lint/issues/89))
This rule accepts two slices of strings, an allowlist and a blocklist of initialisms. By default, the rule behaves exactly as the alternative in `golint` but optionally, you can relax it (see [golint/lint/issues/89](https://github.com/golang/lint/issues/89))

```toml
[rule.var-naming]
Expand Down
12 changes: 6 additions & 6 deletions RULES_DESCRIPTIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ List of all available rules.
- [if-return](#if-return)
- [import-alias-naming](#import-alias-naming)
- [import-shadowing](#import-shadowing)
- [imports-blacklist](#imports-blacklist)
- [imports-blocklist](#imports-blocklist)
- [increment-decrement](#increment-decrement)
- [indent-error-flow](#indent-error-flow)
- [line-length-limit](#line-length-limit)
Expand Down Expand Up @@ -570,16 +570,16 @@ name of an imported package. This rule spots identifiers that shadow an import.

_Configuration_: N/A

## imports-blacklist
## imports-blocklist

_Description_: Warns when importing black-listed packages.
_Description_: Warns when importing block-listed packages.

_Configuration_: black-list of package names (or regular expression package names).
_Configuration_: block-list of package names (or regular expression package names).

Example:

```toml
[imports-blacklist]
[imports-blocklist]
arguments =["crypto/md5", "crypto/sha1", "crypto/**/pkix"]
```

Expand Down Expand Up @@ -928,7 +928,7 @@ _Description_: This rule warns when [initialism](https://github.com/golang/go/wi

_Configuration_: This rule accepts two slices of strings and one optional slice with single map with named parameters.
(it's due to TOML hasn't "slice of any" and we keep backward compatibility with previous config version)
First slice is a whitelist and second one is a blacklist of initialisms.
First slice is an allowlist and second one is a blocklist of initialisms.
In map, you can add "upperCaseConst=true" parameter to allow `UPPER_CASE` for `const`
By default, the rule behaves exactly as the alternative in `golint` but optionally, you can relax it (see [golint/lint/issues/89](https://github.com/golang/lint/issues/89))

Expand Down
13 changes: 11 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ var allRules = append([]lint.Rule{
&rule.ModifiesValRecRule{},
&rule.ConstantLogicalExprRule{},
&rule.BoolLiteralRule{},
&rule.ImportsBlacklistRule{},
&rule.ImportsBlocklistRule{},
&rule.FunctionResultsLimitRule{},
&rule.MaxPublicStructsRule{},
Expand Down Expand Up @@ -132,7 +131,8 @@ func GetLintingRules(config *lint.Config, extraRules []lint.Rule) ([]lint.Rule,

var lintingRules []lint.Rule
for name, ruleConfig := range config.Rules {
r, ok := rulesMap[name]
actualName := actualRuleName(name)
r, ok := rulesMap[actualName]
if !ok {
return nil, fmt.Errorf("cannot find rule: %s", name)
}
Expand All @@ -147,6 +147,15 @@ func GetLintingRules(config *lint.Config, extraRules []lint.Rule) ([]lint.Rule,
return lintingRules, nil
}

func actualRuleName(name string) string {
switch name {
case "imports-blacklist":
return "imports-blocklist"
default:
return name
}
}

func parseConfig(path string, config *lint.Config) error {
file, err := os.ReadFile(path)
if err != nil {
Expand Down
73 changes: 0 additions & 73 deletions rule/imports-blacklist.go

This file was deleted.

4 changes: 2 additions & 2 deletions rule/var-naming.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ func (r *VarNamingRule) configure(arguments lint.Arguments) {

r.configured = true
if len(arguments) >= 1 {
r.allowlist = getList(arguments[0], "whitelist")
r.allowlist = getList(arguments[0], "allowlist")
}

if len(arguments) >= 2 {
r.blocklist = getList(arguments[1], "blacklist")
r.blocklist = getList(arguments[1], "blocklist")
}

if len(arguments) >= 3 {
Expand Down
34 changes: 0 additions & 34 deletions test/import-blacklist_test.go

This file was deleted.

8 changes: 0 additions & 8 deletions testdata/imports-blacklist-original.go

This file was deleted.

19 changes: 0 additions & 19 deletions testdata/imports-blacklist.go

This file was deleted.

Loading