-
Notifications
You must be signed in to change notification settings - Fork 298
rule: allow lowercased and kebab-cased options #1272
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
rule: allow lowercased and kebab-cased options #1272
Conversation
abcc9f3
to
79142d4
Compare
1be8855
to
8bd4a2f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
7fc1ea6
to
7b6e1fe
Compare
7b6e1fe
to
dfead4b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A lot of nitpicking from me.
Sent with love anyway.
I appreciate a lot the changes you made.
My feedbacks could also be addressed in another PR maybe.
@@ -241,7 +241,7 @@ func (r *AddConstantRule) Configure(arguments lint.Arguments) error { | |||
return fmt.Errorf("invalid argument to the add-constant rule, expecting string representation of an integer. Got '%v'", v) | |||
} | |||
r.strLitLimit = limit | |||
case "ignoreFuncs": | |||
case normalizeRuleOption("ignoreFuncs"): | |||
excludes, ok := v.(string) | |||
if !ok { | |||
return fmt.Errorf("invalid argument to the ignoreFuncs parameter of add-constant rule, string expected. Got '%v' (%T)", v, v) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here and everywhere, I would use the provided parameter with its exact syntax
return fmt.Errorf("invalid argument to the ignoreFuncs parameter of add-constant rule, string expected. Got '%v' (%T)", v, v) | |
return fmt.Errorf("invalid argument to the %s parameter of add-constant rule, string expected. Got '%v' (%T)", k, v, v) |
So if someone uses :
- ignoreFuncs the error message is about ignoreFuncs
- ignore-funcs the error message is also clearer
It's not about updating an error message that can be caught with golangci-lint issues filtering, so we can update it.
@@ -241,7 +241,7 @@ func (r *AddConstantRule) Configure(arguments lint.Arguments) error { | |||
return fmt.Errorf("invalid argument to the add-constant rule, expecting string representation of an integer. Got '%v'", v) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here (and everywhere else maybe), we could/should use a better error message like the one used for ignoreFuncs
return fmt.Errorf("invalid argument to the add-constant rule, expecting string representation of an integer. Got '%v'", v) | |
return fmt.Errorf("invalid argument to the maxLit parameter of add-constant rule, expecting string representation of an integer. Got '%v'", v) |
But I would encourage you using what I suggested here
return fmt.Errorf("invalid argument to the add-constant rule, expecting string representation of an integer. Got '%v'", v) | |
return fmt.Errorf("invalid argument to the %v parameter of add-constant rule, expecting string representation of an integer. Got '%v'", k, v) |
// Arguments = [{allowRegex="^_"}] | ||
allowRegexStr, ok := v.(string) | ||
if !ok { | ||
return fmt.Errorf("error configuring [unused-receiver] rule: allowRegex is not string but [%T]", v) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here we have another style, brackets are used
So we have plain text, single quote, double quote, brackets...
@@ -279,7 +285,7 @@ func getList(arg any, argName string) ([]string, error) { | |||
for _, v := range args { | |||
val, ok := v.(string) | |||
if !ok { | |||
return nil, fmt.Errorf("invalid %s values of the var-naming rule. Expecting slice of strings but got element of type %T", val, arg) | |||
return nil, fmt.Errorf("invalid %v values of the var-naming rule. Expecting slice of strings but got element of type %T", v, arg) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here another oddity, that can be seen in the unit test file you added
wantErr: errors.New("invalid argument to the var-naming rule. Expecting a allowlist of type slice with initialisms, got int"),
(...)
wantErr: errors.New("invalid 123 values of the var-naming rule. Expecting slice of strings but got element of type []interface {}"),
The first error message mention the name of the argument, the second doesn't
Maybe something like this, that remove the "a", because "a allowList" sounds bad.
return nil, fmt.Errorf("invalid %v values of the var-naming rule. Expecting slice of strings but got element of type %T", v, arg) | |
return nil, fmt.Errorf("invalid %v values of the var-naming rule. Expecting '%v' parameter to be a slice of strings but got element of type %T", argName, v, arg) |
Also, one question, I saw you worked on golangci-lint too do you plan to update the exanples in json schema too golangci-lint reference.yaml ? Also, how much work do you think it could be to add for each rule the list of parameter it supports. |
Thanks for the review! I’ve fixed half of the comments. The other comments are about making error messages consistent and should be addressed in a separate PR to avoid overcomplicating this one. In this PR, I tried to leave them unchanged.
The PR golangci/golangci-lint#5562 adds missing parameters to the golangci-lint documantation. We will create a PR to switch from
No, I'm not. Ludovic usually updates the schema. |
0c9891c
to
0a85f9e
Compare
Co-authored-by: ccoVeille <[email protected]>
6d99aa1
to
200264f
Compare
Thanks @alexandear and @ccoVeille ! |
* rule: tests for Configure with named options; fix errors * rule: refactor and add tests for ifelse rules * rule: allow lowercased and kebab-cased options * test: update integration tests with lowercased params * docs: update rules descriptions * rule: simplify Configure implementation with one option * gofmt and fix lint * review: add isRuleOption, update grammar in doc, simplify regex Co-authored-by: ccoVeille <[email protected]> --------- Co-authored-by: ccoVeille <[email protected]>
This PR allows rule options to be specified in lowercase and kebab case. Previously, the
context-as-argument
rule accepts camelCased argumentallowTypesBefore
. Now, it also accepts kebab-casedallow-types-before
and the fully lowercasedallowtypesbefore
option.This PR addresses the following issues:
camelCase
for options, butcontext-keys-type
useskebab-cased
options likecall-chain
,method-call
, andimmediate-recover
.I've refactored
early-return
,indent-error-flow
, andsuperfluous-else
rules by adding theConfigure
method.I’ve added tests to ensure this PR does not introduce regressions.
Also, updated documentation.
To simplify the review process, I have broken the changes into separate commits, each representing a distinct logical update.