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

rule.exported: add feature to disable selected warnings for rule (const,method,function) #1047

Merged

Conversation

mfederowicz
Copy link
Contributor

related with #1045

for rule.exported add feature to read array/list of types which we want to ignore in processing time

[rule.exported]                                                                                                                                                            
  ▎ arguments = [
"checkPrivateReceivers", 
["function","method","type","var"]
]

of course thouse are types discovered when rule.exported is enabled in config, if we set some other additional flags outside of that list it can results with panic/error

test/exported_test.go Outdated Show resolved Hide resolved
@zak-pawel
Copy link

It would be very nice to see this feature merged. I would especially need turning off warnings for types.

…kind-warnings

# Conflicts:
#	rule/exported.go
@mfederowicz
Copy link
Contributor Author

hi @denisvmedia I resolved conflicts from master, and if you have and sugestions (changes) let me know :)

@chavacava
Copy link
Collaborator

Hi @zak-pawel could you please elaborate on the reasons for turning off warnings for types? (I've quickly read the thread on telegraph repo)

Copy link
Collaborator

@chavacava chavacava left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've left some comments on the implementation details but, in general, IMO the semantics of the new configuration is not clear or, not rightly implemented.
For example, from the configuration documentation we understand that setting "type" will avoid generating any warning on types at all. Then, by reading the implementation we can see that some warning on types will be generated (those of the form "exported type %v should have comment or be unexported")


Example:

```toml
[rule.exported]
arguments = ["checkPrivateReceivers", "disableStutteringCheck", "checkPublicInterface"]
arguments = ["checkPrivateReceivers", "disableStutteringCheck", "checkPublicInterface", ["function","method","type","var"]]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the configuration entry gives no clue about the "ignore" nature of the list.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok i try struct with dedicated fields but in toml there is problem with notation like:

IgnoredWarnings{field:true,field2:true}

you can only use like this:

{field:true,field2:true} or list ["val","val2","val3"]

but there is no option to name/prefix that (or maybe I dont know the magic yet :()

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think what @chavacava is asking is to have a better naming of the setting, e.g. disableFunctionDocumentationCheck instead of function...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think what @chavacava is asking is to have a better naming of the setting, e.g. disableFunctionDocumentationCheck instead of function...

ok so each element of ["function","method","type","var"] as dedicated flag

arguments = ["disableFunctionCheck", "disableMethodCheck", "disableTypeCheck", "disableVarCheck"]

that was my first idea, but thinks using array/slice will be simpler (one place to modify) :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok maybe we can walk that way:

arguments = ["disableFunctionCheck", "disableMethodCheck", "disableTypeCheck", "disableVarCheck"]

and of course modify my commited code to use that flags insted of additional array in config what you think @chavacava ?

rule/exported.go Outdated Show resolved Hide resolved
rule/exported.go Outdated Show resolved Hide resolved
rule/exported.go Show resolved Hide resolved
rule/exported.go Outdated Show resolved Hide resolved
rule/exported.go Outdated Show resolved Hide resolved
rule/exported.go Outdated Show resolved Hide resolved
test/exported_test.go Show resolved Hide resolved
test/exported_test.go Outdated Show resolved Hide resolved
rule/exported.go Outdated Show resolved Hide resolved
@srebhan
Copy link

srebhan commented Oct 1, 2024

@chavacava let me elaborate a bit on

Hi @zak-pawel could you please elaborate on the reasons for turning off warnings for types? (I've quickly read the thread on telegraph repo)

Telegraf has a "plugin-like" structure, where each "plugin" fulfills a set of interfaces and by now we exported the plugin struct as well as the interface functions by convention. We now want to use the checker to make sure each plugin only exports the plugin type and the interface functions! However, each of the plugin types has to implement certain functions like Gather() for inputs and we now do have 200+ plugins all implementing Gather(). Guess what the comment for this function is in 99.9999% of all cases? // Gather or Gather gathers data. There is no value in adding these kind of comments. Similar for the plugin struct... Currently, we can only keep the exported rule disabled or add churn to our 300+ plugins... Therefore we would prefer to disable those checks while keeping the ability to impose the convention of only exporting the plugin struct and the interface functions. :-)

@chavacava
Copy link
Collaborator

Hi @srebhan thank you for the details on your use case.
As I understand, the "zero-value added" comments problem concerns the code related with plugins. If my understanding is right you ask for the ability to disabling certain warnings of the rule. By doing that you will mute unnecessary warnings on plugins code but... it will also disable warnings on all the code base (and, for example, it will not warn on malformed comments or undocumented public methods). Is that what you need?
Is disabling the rule as per (plugin) file not an option?

@srebhan
Copy link

srebhan commented Oct 1, 2024

@chavacava we are currently solely checking the plugins with this rule. Disabling the whole rule defeats the purpose as we actually want the exported rule to warn about exported structs and functions only whitelisting the known interface functions. This way the rule will warn about any unexpected exports which is exactly what we want. We only need to shut-up the comment warnings for the plugins...

@chavacava
Copy link
Collaborator

@zak-pawel @srebhan
I've made some refactoring in the PR, please check if the rule+configuration behave as you expect for your use case

cc: @mfederowicz

@zak-pawel
Copy link

@chavacava I tested it on the Telegraf code, and it looks like the individual switches correctly disable the respective checks. Thanks!

@chavacava chavacava merged commit ff7b0ad into mgechev:master Oct 2, 2024
3 of 4 checks passed
@chavacava
Copy link
Collaborator

Thanks for the PR @mfederowicz

@mfederowicz
Copy link
Contributor Author

@chavacava no problem, but forgot to add var testdata, created quick update: #1055 :P

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants