prometheus/documentation/examples
beorn7 5b53aa1108 style: Replace else if cascades with switch
Wiser coders than myself have come to the conclusion that a `switch`
statement is almost always superior to a statement that includes any
`else if`.

The exceptions that I have found in our codebase are just these two:

* The `if else` is followed by an additional statement before the next
  condition (separated by a `;`).
* The whole thing is within a `for` loop and `break` statements are
  used. In this case, using `switch` would require tagging the `for`
  loop, which probably tips the balance.

Why are `switch` statements more readable?

For one, fewer curly braces. But more importantly, the conditions all
have the same alignment, so the whole thing follows the natural flow
of going down a list of conditions. With `else if`, in contrast, all
conditions but the first are "hidden" behind `} else if `, harder to
spot and (for no good reason) presented differently from the first
condition.

I'm sure the aforemention wise coders can list even more reasons.

In any case, I like it so much that I have found myself recommending
it in code reviews. I would like to make it a habit in our code base,
without making it a hard requirement that we would test on the CI. But
for that, there has to be a role model, so this commit eliminates all
`if else` occurrences, unless it is autogenerated code or fits one of
the exceptions above.

Signed-off-by: beorn7 <beorn@grafana.com>
2023-04-19 17:22:31 +02:00
..
custom-sd build(deps): bump github.com/prometheus/prometheus from 0.37.0 to 0.42.0 in /documentation/examples/remote_storage 2023-03-11 17:15:43 +09:00
kubernetes-rabbitmq fixes yamllint errors 2021-06-12 12:47:47 +02:00
remote_storage style: Replace else if cascades with switch 2023-04-19 17:22:31 +02:00
Makefile Check syntax of example configurations (#10753) 2022-05-26 18:17:21 +10:00
prometheus-agent.yml config: Make remote-write required for Agent mode (#9618) 2021-10-30 01:41:40 +02:00
prometheus-digitalocean.yml fixes yamllint errors 2021-06-12 12:47:47 +02:00
prometheus-docker.yml fixes yamllint errors 2021-06-12 12:47:47 +02:00
prometheus-dockerswarm.yml fixes yamllint errors 2021-06-12 12:47:47 +02:00
prometheus-eureka.yml Add Eureka Service Discovery (#3369) 2020-08-26 17:36:59 +02:00
prometheus-hetzner.yml Check syntax of example configurations (#10753) 2022-05-26 18:17:21 +10:00
prometheus-ionos.yml Add service discovery for IONOS Cloud (#10514) 2022-05-20 14:57:23 +02:00
prometheus-kubernetes.yml k8s example: Remove obsolete comment 2022-10-10 18:09:39 +02:00
prometheus-linode.yml Fixed spacing causing "field credentials not found in type linode.plain” error (#10752) 2022-05-25 22:46:02 +02:00
prometheus-marathon.yml fixes yamllint errors 2021-06-12 12:47:47 +02:00
prometheus-nomad.yml feat(nomad): add nomad service discovery 2022-06-30 14:17:08 +02:00
prometheus-ovhcloud.yml Add service discovery for OvhCloud (#10802) 2022-11-03 10:20:09 +01:00
prometheus-puppetdb.yml docs: Improve PuppetDB example (#9547) 2021-10-20 21:03:17 +02:00
prometheus-scaleway.yml add support for scaleway service discovery (#8555) 2021-03-10 15:10:17 +01:00
prometheus-uyuni.yml Add Uyuni service discovery (#8190) 2021-10-19 01:00:44 +02:00
prometheus-vultr.yml Check syntax of example configurations (#10753) 2022-05-26 18:17:21 +10:00
prometheus.yml fixes yamllint errors 2021-06-12 12:47:47 +02:00
rbac-setup.yml update ServiceAccount for new kubernetes versions 2023-01-05 15:43:48 +00:00
web-config.yml Fix a broken link for the bcrypt ref. at the web-config.yml example 2021-04-20 22:43:37 +02:00