diff --git a/README.md b/README.md index daadbc168..d6a671532 100644 --- a/README.md +++ b/README.md @@ -534,6 +534,7 @@ List of all available rules. The rules ported from `golint` are left unchanged a | [`comment-spacings`](./RULES_DESCRIPTIONS.md#comment-spacings) | []string | Warns on malformed comments | no | no | | [`redundant-import-alias`](./RULES_DESCRIPTIONS.md#redundant-import-alias) | n/a | Warns on import aliases matching the imported package name | no | no | | [`import-alias-naming`](./RULES_DESCRIPTIONS.md#import-alias-naming) | string (defaults to ^[a-z][a-z0-9]{0,}$) | Conventions around the naming of import aliases. | no | no | +| [`enforce-map-style`](./RULES_DESCRIPTIONS.md#enforce-map-style) | string (defaults to "any") | Enforces consistent usage of `make(map[type]type)` or `map[type]type{}` for map initialization. Does not affect `make(map[type]type, size)` constructions. | no | no | ## Configurable rules diff --git a/RULES_DESCRIPTIONS.md b/RULES_DESCRIPTIONS.md index 4561e200e..36aae042b 100644 --- a/RULES_DESCRIPTIONS.md +++ b/RULES_DESCRIPTIONS.md @@ -332,6 +332,22 @@ _Description_: Sometimes `gofmt` is not enough to enforce a common formatting of _Configuration_: N/A +## enforce-map-style + +_Description_: This rule enforces consistent usage of `make(map[type]type)` or `map[type]type{}` for map initialization. It does not affect `make(map[type]type, size)` constructions. + +_Configuration_: (string) Specifies the enforced style for map initialization. The options are: +- "any": No enforcement (default). +- "make": Enforces the usage of `make(map[type]type)`. +- "literal": Enforces the usage of `map[type]type{}`. + +Example: + +```toml +[rule.enforce-map-style] + arguments = ["make"] +``` + ## error-naming _Description_: By convention, for the sake of readability, variables of type `error` must be named with the prefix `err`. diff --git a/rule/enforce-map-style.go b/rule/enforce-map-style.go index 2c7347060..48b3bd33e 100644 --- a/rule/enforce-map-style.go +++ b/rule/enforce-map-style.go @@ -73,6 +73,11 @@ func (r *EnforceMapStyleRule) configure(arguments lint.Arguments) { func (r *EnforceMapStyleRule) Apply(file *lint.File, arguments lint.Arguments) []lint.Failure { r.configure(arguments) + if r.enforceMapStyle == enforceMapStyleTypeAny { + // this linter is not configured + return nil + } + var failures []lint.Failure astFile := file.AST