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

Linter: revive, Rule: max-public-structs - Warns on files declaring too many public structs. Should we enable it? #15822

Closed
zak-pawel opened this issue Sep 2, 2024 · 7 comments · Fixed by #15895
Assignees
Labels

Comments

@zak-pawel
Copy link
Collaborator

Description

This issue starts a discussion about enabling:

  • linter: revive - Fast, configurable, extensible, flexible, and beautiful linter for Go. Drop-in replacement of golint. Revive provides a framework for development of custom rules, and lets you define a strict preset for enhancing your development & code review processes.
  • rule: max-public-structs - Packages declaring too many public structs can be hard to understand/use, and could be a symptom of bad design.
    This rule warns on files declaring more than a configured, maximum number of public structs.

Configuration:

(int) the maximum allowed public structs

Example configuration:

      - name: max-public-structs
        exclude: ["TEST"]
        arguments: [5]

Expected output

Decision about enabling or not enabling this rule.

Findings

For this rule (with above configuration), the following findings were found in the current codebase:

internal/content_coding.go:1:1                                         revive  max-public-structs: you have exceeded the maximum number of public struct declarations
metric.go:1:1                                                          revive  max-public-structs: you have exceeded the maximum number of public struct declarations
plugins/common/jolokia2/client.go:1:1                                  revive  max-public-structs: you have exceeded the maximum number of public struct declarations
plugins/common/opcua/input/input_client.go:1:1                         revive  max-public-structs: you have exceeded the maximum number of public struct declarations
plugins/inputs/activemq/activemq.go:2:1                                revive  max-public-structs: you have exceeded the maximum number of public struct declarations
plugins/inputs/ctrlx_datalayer/ctrlx_datalayer_subscription.go:1:1     revive  max-public-structs: you have exceeded the maximum number of public struct declarations
plugins/inputs/dcos/client.go:1:1                                      revive  max-public-structs: you have exceeded the maximum number of public struct declarations
plugins/inputs/graylog/graylog.go:2:1                                  revive  max-public-structs: you have exceeded the maximum number of public struct declarations
plugins/inputs/kafka_consumer/kafka_consumer.go:2:1                    revive  max-public-structs: you have exceeded the maximum number of public struct declarations
plugins/inputs/kubernetes/kubernetes_metrics.go:1:1                    revive  max-public-structs: you have exceeded the maximum number of public struct declarations
plugins/inputs/logstash/logstash.go:2:1                                revive  max-public-structs: you have exceeded the maximum number of public struct declarations
plugins/inputs/mailchimp/chimp_api.go:1:1                              revive  max-public-structs: you have exceeded the maximum number of public struct declarations
plugins/inputs/mongodb/mongostat.go:8:1                                revive  max-public-structs: you have exceeded the maximum number of public struct declarations
plugins/inputs/monit/monit.go:2:1                                      revive  max-public-structs: you have exceeded the maximum number of public struct declarations
plugins/inputs/nginx_plus/nginx_plus.go:2:1                            revive  max-public-structs: you have exceeded the maximum number of public struct declarations
plugins/inputs/nginx_plus_api/nginx_plus_api_types.go:1:1              revive  max-public-structs: you have exceeded the maximum number of public struct declarations
plugins/inputs/nomad/nomad_metrics.go:1:1                              revive  max-public-structs: you have exceeded the maximum number of public struct declarations
plugins/inputs/nsq/nsq.go:24:1                                         revive  max-public-structs: you have exceeded the maximum number of public struct declarations
plugins/inputs/nvidia_smi/schema_v11/types.go:1:1                      revive  max-public-structs: you have exceeded the maximum number of public struct declarations
plugins/inputs/opensearch_query/aggregation.response.go:1:1            revive  max-public-structs: you have exceeded the maximum number of public struct declarations
plugins/inputs/proxmox/structs.go:1:1                                  revive  max-public-structs: you have exceeded the maximum number of public struct declarations
plugins/inputs/rabbitmq/rabbitmq.go:2:1                                revive  max-public-structs: you have exceeded the maximum number of public struct declarations
plugins/inputs/redfish/redfish.go:2:1                                  revive  max-public-structs: you have exceeded the maximum number of public struct declarations
plugins/inputs/rethinkdb/rethinkdb_data.go:1:1                         revive  max-public-structs: you have exceeded the maximum number of public struct declarations
plugins/inputs/sflow/types.go:1:1                                      revive  max-public-structs: you have exceeded the maximum number of public struct declarations
plugins/inputs/solr/types.go:1:1                                       revive  max-public-structs: you have exceeded the maximum number of public struct declarations
plugins/inputs/stackdriver/stackdriver.go:2:1                          revive  max-public-structs: you have exceeded the maximum number of public struct declarations
plugins/inputs/tomcat/tomcat.go:2:1                                    revive  max-public-structs: you have exceeded the maximum number of public struct declarations
plugins/inputs/webhooks/artifactory/artifactory_webhook_models.go:1:1  revive  max-public-structs: you have exceeded the maximum number of public struct declarations
plugins/inputs/webhooks/github/github_webhooks_models.go:1:1           revive  max-public-structs: you have exceeded the maximum number of public struct declarations
plugins/inputs/webhooks/rollbar/rollbar_webhooks_events.go:1:1         revive  max-public-structs: you have exceeded the maximum number of public struct declarations
plugins/inputs/xtremio/xtremio_types.go:1:1                            revive  max-public-structs: you have exceeded the maximum number of public struct declarations
plugins/inputs/zipkin/codec/codec.go:1:1                               revive  max-public-structs: you have exceeded the maximum number of public struct declarations
plugins/outputs/influxdb/http.go:1:1                                   revive  max-public-structs: you have exceeded the maximum number of public struct declarations
plugins/outputs/sensu/sensu.go:2:1                                     revive  max-public-structs: you have exceeded the maximum number of public struct declarations
plugins/parsers/json_v2/parser.go:1:1                                  revive  max-public-structs: you have exceeded the maximum number of public struct declarations
plugins/parsers/wavefront/element.go:1:1                               revive  max-public-structs: you have exceeded the maximum number of public struct declarations
plugins/serializers/prometheus/collection.go:1:1                       revive  max-public-structs: you have exceeded the maximum number of public struct declarations
@srebhan
Copy link
Member

srebhan commented Sep 3, 2024

If we could limit the linter to plugins/{inputs,outputs,processors,aggregators,parsers,serializers} I think this might be valueable...

@DStrand1
Copy link
Member

DStrand1 commented Sep 3, 2024

I'm split on this... on the one hand I can understand where it could be poorly written code, but on the other hand, some plugins have a lot of data to handle, like nvidia_smi for example, and I think more often than not I think it would be cases like this. I would lean towards no, but not be against it if both of you think it is worthwhile

@srebhan
Copy link
Member

srebhan commented Sep 4, 2024

@DStrand1 I think most of those declarations can be internal as well! Unmarshalling JSON also works for non-exported structures, it's just the struct-fields that need to be "public"... Where do you see issues? Could you point to a concrete example?

@Hipska
Copy link
Contributor

Hipska commented Sep 11, 2024

I'm also wondering why plugins should be allowed up to 5 exported structs? They all should only have 1? (the plugin itself)

@srebhan
Copy link
Member

srebhan commented Sep 11, 2024

There might be an interface to mock the test...

@Hipska
Copy link
Contributor

Hipska commented Sep 11, 2024

But that doesn't need to be exported?

@srebhan
Copy link
Member

srebhan commented Sep 11, 2024

Well you might want to run tests in a separate package like

package foo_test

for various reasons and need to be able to fulfill the interface...

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

Successfully merging a pull request may close this issue.

4 participants