influxdata / telegraf

Agent for collecting, processing, aggregating, and writing metrics, logs, and other arbitrary data.
https://influxdata.com/telegraf
MIT License
14.67k stars 5.59k forks source link

Linter: revive, Rule: `import-alias-naming` - Enforces clear and lowercase import alias names. Should we enable it? #15820

Closed zak-pawel closed 1 month ago

zak-pawel commented 2 months ago

Description

This issue starts a discussion about enabling:

Configuration:

Configuration (1): (string) as plain string accepts allow regexp pattern for aliases (default: ^[a-z][a-z0-9]{0,}$).

Configuration (2): (map[string]string) as a map accepts two values:

Note: If both allowRegex and denyRegex are provided, the alias must comply with both of them. If none are given (i.e. an empty map), the default value ^[a-z][a-z0-9]{0,}$ for allowRegex is used. Unknown keys will result in an error.

Example configuration:

Example (1):

      - name: import-alias-naming
        arguments:
          - "^[a-z][a-z0-9]{0,}$"

Example (2):

      - name: import-alias-naming
        arguments:
          - allowRegex: "^[a-z][a-z0-9]{0,}$"
            denyRegex: '^v\d+$'

Expected output

Decision about enabling or not enabling this rule.

Findings

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

internal/internal.go:7:2                                              revive  import-alias-naming: import name (cryptoRand) must match the regular expression: ^[a-z][a-z0-9]{0,}$
plugins/aggregators/histogram/histogram.go:11:2                       revive  import-alias-naming: import name (telegrafConfig) must match the regular expression: ^[a-z][a-z0-9]{0,}$
plugins/aggregators/histogram/histogram_test.go:11:2                  revive  import-alias-naming: import name (telegrafConfig) must match the regular expression: ^[a-z][a-z0-9]{0,}$
plugins/common/aws/credentials.go:6:2                                 revive  import-alias-naming: import name (awsV2) must match the regular expression: ^[a-z][a-z0-9]{0,}$
plugins/common/aws/credentials.go:7:2                                 revive  import-alias-naming: import name (configV2) must match the regular expression: ^[a-z][a-z0-9]{0,}$
plugins/common/aws/credentials.go:8:2                                 revive  import-alias-naming: import name (credentialsV2) must match the regular expression: ^[a-z][a-z0-9]{0,}$
plugins/common/aws/credentials.go:9:2                                 revive  import-alias-naming: import name (stscredsV2) must match the regular expression: ^[a-z][a-z0-9]{0,}$
plugins/common/http/config.go:15:2                                    revive  import-alias-naming: import name (oauthConfig) must match the regular expression: ^[a-z][a-z0-9]{0,}$
plugins/common/kafka/config.go:12:2                                   revive  import-alias-naming: import name (tgConf) must match the regular expression: ^[a-z][a-z0-9]{0,}$
plugins/common/proxy/connect.go:11:2                                  revive  import-alias-naming: import name (netProxy) must match the regular expression: ^[a-z][a-z0-9]{0,}$
plugins/common/proxy/dialer.go:8:2                                    revive  import-alias-naming: import name (netProxy) must match the regular expression: ^[a-z][a-z0-9]{0,}$
plugins/common/shim/config_test.go:10:2                               revive  import-alias-naming: import name (tgConfig) must match the regular expression: ^[a-z][a-z0-9]{0,}$
plugins/common/shim/processor_test.go:16:2                            revive  import-alias-naming: import name (influxSerializer) must match the regular expression: ^[a-z][a-z0-9]{0,}$
plugins/inputs/apcupsd/apcupsd.go:12:2                                revive  import-alias-naming: import name (apcupsdClient) must match the regular expression: ^[a-z][a-z0-9]{0,}$
plugins/inputs/cisco_telemetry_mdt/cisco_telemetry_mdt_test.go:14:2   revive  import-alias-naming: import name (telemetryBis) must match the regular expression: ^[a-z][a-z0-9]{0,}$
plugins/inputs/cloudwatch/cloudwatch.go:17:2                          revive  import-alias-naming: import name (cwClient) must match the regular expression: ^[a-z][a-z0-9]{0,}$
plugins/inputs/cloudwatch/cloudwatch.go:25:2                          revive  import-alias-naming: import name (internalMetric) must match the regular expression: ^[a-z][a-z0-9]{0,}$
plugins/inputs/cloudwatch/cloudwatch.go:27:2                          revive  import-alias-naming: import name (internalProxy) must match the regular expression: ^[a-z][a-z0-9]{0,}$
plugins/inputs/cloudwatch/cloudwatch_test.go:11:2                     revive  import-alias-naming: import name (cwClient) must match the regular expression: ^[a-z][a-z0-9]{0,}$
plugins/inputs/couchbase/couchbase.go:13:2                            revive  import-alias-naming: import name (couchbaseClient) must match the regular expression: ^[a-z][a-z0-9]{0,}$
plugins/inputs/cpu/cpu.go:10:2                                        revive  import-alias-naming: import name (cpuUtil) must match the regular expression: ^[a-z][a-z0-9]{0,}$
plugins/inputs/cpu/cpu_test.go:7:2                                    revive  import-alias-naming: import name (cpuUtil) must match the regular expression: ^[a-z][a-z0-9]{0,}$
plugins/inputs/ctrlx_datalayer/ctrlx_datalayer.go:27:2                revive  import-alias-naming: import name (jsonParser) must match the regular expression: ^[a-z][a-z0-9]{0,}$
plugins/inputs/disk/disk_test.go:12:2                                 revive  import-alias-naming: import name (diskUtil) must match the regular expression: ^[a-z][a-z0-9]{0,}$
plugins/inputs/docker/client.go:12:2                                  revive  import-alias-naming: import name (dockerClient) must match the regular expression: ^[a-z][a-z0-9]{0,}$
plugins/inputs/docker/docker.go:20:2                                  revive  import-alias-naming: import name (typeContainer) must match the regular expression: ^[a-z][a-z0-9]{0,}$
plugins/inputs/docker/docker_test.go:14:2                             revive  import-alias-naming: import name (typeContainer) must match the regular expression: ^[a-z][a-z0-9]{0,}$
plugins/inputs/docker_log/docker_log.go:19:2                          revive  import-alias-naming: import name (typeContainer) must match the regular expression: ^[a-z][a-z0-9]{0,}$
plugins/inputs/ethtool/namespace_linux.go:8:2                         revive  import-alias-naming: import name (ethtoolLib) must match the regular expression: ^[a-z][a-z0-9]{0,}$
plugins/inputs/eventhub_consumer/eventhub_consumer.go:12:2            revive  import-alias-naming: import name (eventhubClient) must match the regular expression: ^[a-z][a-z0-9]{0,}$
plugins/inputs/exec/run_notwinodws.go:9:2                             revive  import-alias-naming: import name (osExec) must match the regular expression: ^[a-z][a-z0-9]{0,}$
plugins/inputs/execd/execd_test.go:22:2                               revive  import-alias-naming: import name (influxSerializer) must match the regular expression: ^[a-z][a-z0-9]{0,}$
plugins/inputs/github/github.go:14:2                                  revive  import-alias-naming: import name (githubLib) must match the regular expression: ^[a-z][a-z0-9]{0,}$
plugins/inputs/gnmi/gnmi.go:15:2                                      revive  import-alias-naming: import name (gnmiLib) must match the regular expression: ^[a-z][a-z0-9]{0,}$
plugins/inputs/gnmi/gnmi_test.go:14:2                                 revive  import-alias-naming: import name (gnmiLib) must match the regular expression: ^[a-z][a-z0-9]{0,}$
plugins/inputs/gnmi/gnmi_test.go:15:2                                 revive  import-alias-naming: import name (gnmiExt) must match the regular expression: ^[a-z][a-z0-9]{0,}$
plugins/inputs/gnmi/gnmi_test.go:25:2                                 revive  import-alias-naming: import name (jnprHeader) must match the regular expression: ^[a-z][a-z0-9]{0,}$
plugins/inputs/gnmi/handler.go:16:2                                   revive  import-alias-naming: import name (gnmiLib) must match the regular expression: ^[a-z][a-z0-9]{0,}$
plugins/inputs/gnmi/handler.go:17:2                                   revive  import-alias-naming: import name (gnmiExt) must match the regular expression: ^[a-z][a-z0-9]{0,}$
plugins/inputs/gnmi/handler.go:29:2                                   revive  import-alias-naming: import name (jnprHeader) must match the regular expression: ^[a-z][a-z0-9]{0,}$
plugins/inputs/gnmi/path.go:6:2                                       revive  import-alias-naming: import name (gnmiLib) must match the regular expression: ^[a-z][a-z0-9]{0,}$
plugins/inputs/gnmi/update_fields.go:9:2                              revive  import-alias-naming: import name (gnmiLib) must match the regular expression: ^[a-z][a-z0-9]{0,}$
plugins/inputs/gnmi/update_fields.go:10:2                             revive  import-alias-naming: import name (gnmiValue) must match the regular expression: ^[a-z][a-z0-9]{0,}$
plugins/inputs/intel_powerstat/intel_powerstat.go:17:2                revive  import-alias-naming: import name (cpuUtil) must match the regular expression: ^[a-z][a-z0-9]{0,}$
plugins/inputs/kafka_consumer/kafka_consumer_test.go:21:2             revive  import-alias-naming: import name (kafkaOutput) must match the regular expression: ^[a-z][a-z0-9]{0,}$
plugins/inputs/kafka_consumer/kafka_consumer_test.go:24:2             revive  import-alias-naming: import name (influxSerializer) must match the regular expression: ^[a-z][a-z0-9]{0,}$
plugins/inputs/kube_inventory/daemonset.go:6:2                        revive  import-alias-naming: import name (v1) must NOT match the regular expression: ^v\d+$
plugins/inputs/kube_inventory/daemonset_test.go:9:2                   revive  import-alias-naming: import name (v1) must NOT match the regular expression: ^v\d+$
plugins/inputs/kube_inventory/deployment.go:6:2                       revive  import-alias-naming: import name (v1) must NOT match the regular expression: ^v\d+$
plugins/inputs/kube_inventory/deployment_test.go:9:2                  revive  import-alias-naming: import name (v1) must NOT match the regular expression: ^v\d+$
plugins/inputs/kube_inventory/endpoint_test.go:7:2                    revive  import-alias-naming: import name (v1) must NOT match the regular expression: ^v\d+$
plugins/inputs/kube_inventory/statefulset.go:6:2                      revive  import-alias-naming: import name (v1) must NOT match the regular expression: ^v\d+$
plugins/inputs/kube_inventory/statefulset_test.go:9:2                 revive  import-alias-naming: import name (v1) must NOT match the regular expression: ^v\d+$
plugins/inputs/kubernetes/kubernetes.go:15:2                          revive  import-alias-naming: import name (v1) must NOT match the regular expression: ^v\d+$
plugins/inputs/logstash/logstash.go:20:2                              revive  import-alias-naming: import name (jsonParser) must match the regular expression: ^[a-z][a-z0-9]{0,}$
plugins/inputs/mysql/mysql.go:23:2                                    revive  import-alias-naming: import name (v1) must NOT match the regular expression: ^v\d+$
plugins/inputs/mysql/mysql.go:24:2                                    revive  import-alias-naming: import name (v2) must NOT match the regular expression: ^v\d+$
plugins/inputs/openstack/openstack.go:29:2                            revive  import-alias-naming: import name (cinder_services) must match the regular expression: ^[a-z][a-z0-9]{0,}$
plugins/inputs/openstack/openstack.go:36:2                            revive  import-alias-naming: import name (nova_services) must match the regular expression: ^[a-z][a-z0-9]{0,}$
plugins/inputs/p4runtime/p4runtime.go:14:2                            revive  import-alias-naming: import name (p4ConfigV1) must match the regular expression: ^[a-z][a-z0-9]{0,}$
plugins/inputs/p4runtime/p4runtime_test.go:10:2                       revive  import-alias-naming: import name (p4ConfigV1) must match the regular expression: ^[a-z][a-z0-9]{0,}$
plugins/inputs/riemann_listener/riemann_listener.go:20:2              revive  import-alias-naming: import name (riemangoProto) must match the regular expression: ^[a-z][a-z0-9]{0,}$
plugins/inputs/x509_cert/x509_cert_test.go:30:2                       revive  import-alias-naming: import name (_tls) must match the regular expression: ^[a-z][a-z0-9]{0,}$
plugins/inputs/zipkin/handler.go:13:2                                 revive  import-alias-naming: import name (json_v1) must match the regular expression: ^[a-z][a-z0-9]{0,}$
plugins/outputs/azure_data_explorer/azure_data_explorer_test.go:20:2  revive  import-alias-naming: import name (telegrafJson) must match the regular expression: ^[a-z][a-z0-9]{0,}$
plugins/outputs/cloudwatch_logs/cloudwatch_logs_test.go:12:2          revive  import-alias-naming: import name (cloudwatchlogsV2) must match the regular expression: ^[a-z][a-z0-9]{0,}$
plugins/outputs/dynatrace/dynatrace.go:15:2                           revive  import-alias-naming: import name (dtMetric) must match the regular expression: ^[a-z][a-z0-9]{0,}$
plugins/outputs/exec/exec_test.go:16:2                                revive  import-alias-naming: import name (influxParser) must match the regular expression: ^[a-z][a-z0-9]{0,}$
plugins/outputs/execd/execd_test.go:22:2                              revive  import-alias-naming: import name (influxSerializer) must match the regular expression: ^[a-z][a-z0-9]{0,}$
plugins/outputs/http/http.go:17:2                                     revive  import-alias-naming: import name (awsV2) must match the regular expression: ^[a-z][a-z0-9]{0,}$
plugins/outputs/http/http.go:18:2                                     revive  import-alias-naming: import name (v4) must NOT match the regular expression: ^v\d+$
plugins/outputs/mqtt/mqtt_test.go:19:2                                revive  import-alias-naming: import name (influxSerializer) must match the regular expression: ^[a-z][a-z0-9]{0,}$
plugins/outputs/prometheus_client/prometheus_client.go:27:2           revive  import-alias-naming: import name (v1) must NOT match the regular expression: ^v\d+$
plugins/outputs/prometheus_client/prometheus_client.go:28:2           revive  import-alias-naming: import name (v2) must NOT match the regular expression: ^v\d+$
plugins/processors/dedup/dedup.go:13:2                                revive  import-alias-naming: import name (influxSerializer) must match the regular expression: ^[a-z][a-z0-9]{0,}$
plugins/processors/execd/execd_test.go:22:2                           revive  import-alias-naming: import name (influxSerializer) must match the regular expression: ^[a-z][a-z0-9]{0,}$
testutil/metric.go:12:2                                               revive  import-alias-naming: import name (telegrafMetric) must match the regular expression: ^[a-z][a-z0-9]{0,}$
srebhan commented 2 months ago

I would go with the allowed (i.e. whitelisting) setup using "^[a-z][a-z0-9_]*[a-z0-9]+$" What do you think?

zak-pawel commented 2 months ago

So basically snake_case. Yes, makes sense.