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

snake_case vs camelCase URL query params #10804

Open
chris48s opened this issue Jan 10, 2025 · 3 comments
Open

snake_case vs camelCase URL query params #10804

chris48s opened this issue Jan 10, 2025 · 3 comments
Labels
developer-experience Dev tooling, test framework, and CI

Comments

@chris48s
Copy link
Member

Over the last 10+ years we have accumulated a lot of code written by a lot of different people.
In general, I think we've done a reasonable job of enforcing relatively consistent code styles and naming conventions, via documentation and/or lint rules, but there are obviously some exceptions.

One significant "blind spot" where we have a lot of variance is whether we use snake_case or camelCase URL query params.

There's a bunch of places where we are using camelCase. For example:

const queryParamSchema = Joi.object({
metadataUrl: optionalUrl.required(),
versionPrefix: Joi.string().optional(),
versionSuffix: Joi.string().optional(),
}).required()

export const queryParamSchema = Joi.object({
pypiBaseUrl: optionalUrl,
}).required()

const queryParamSchema = Joi.object({
server: optionalUrl.required(),
queryOpt: Joi.string()
.regex(/(:[\w.]+=[^:]*)+/i)
.optional(),
nexusVersion: Joi.equal('2', '3'),
}).required()

and a bunch of places where we are using snake_case. For example:

const queryParamSchema = Joi.object({
repository_url: optionalUrl.required(),
include_prereleases: Joi.equal(''),
}).required()

const queryParamSchema = Joi.object({
path: relativeUri,
display_timestamp: Joi.string()
.valid(...displayEnum)
.default('author'),
gitea_url: optionalUrl,
}).required()

const queryParamSchema = Joi.object({
up_message: Joi.string(),
down_message: Joi.string(),
up_color: Joi.alternatives(Joi.string(), Joi.number()),
down_color: Joi.alternatives(Joi.string(), Joi.number()),
}).required()

I think the other day we acquired the first case where we have one of each next to each other on the same service 🤦

const queryParamSchema = Joi.object({
server_fqdn: Joi.string().hostname(),
fetchMode: Joi.string()
.valid(...fetchModeEnum)
.default('guest'),
}).required()

I have not counted exactly, but roughly speaking we have about half and half.

The standard params that apply to all badges are all camelCase: labelColor, logoColor, logoSize

I think we've at least managed to avoid having any params that use snake-case 🤞 but maybe somewhere in the codebase there is an example 😬

There are a couple of ways we can change the names of query params without making a breaking change. One way we can do it is with redirects. Another would be to write the queryParamSchemas to accept both formats but only document one for the services where we want to fix this. Having got to the stage where we have hundreds of service integrations, this is going to be quite difficult to unpick, and I wouldn't want to do it all at once. It would be nice to gradually work towards fixing this though.

I suggest we:

  1. Pick one or the other
  2. Document it
  3. Make some kind of a lint/danger rule to catch this
  4. At least get to a stage where everything we add from now onwards matches this convention
  5. Gradually bring services into line with the convention

Given:

  1. We use camelCase for variable names (which makes translating URL query params straight to correctly named variables easier)
  2. The standard params that apply to all badges are all camelCase: labelColor, logoColor, logoSize

I'm gong to suggest we standardise on camelCase, but I also feel like there is a reason why we used snake_case in a lot of cases, and I can't remember what it is.

@chris48s chris48s added the developer-experience Dev tooling, test framework, and CI label Jan 10, 2025
@jNullj
Copy link
Member

jNullj commented Jan 10, 2025

I think camelCase is used more around js/node devs, so thats a pro for that.
I think that snake_case is more readable but that's personal and we can't really use this as a good point, unless the whole team thinks so, in that case it would make sense.
My last point is that as it mainly visuals we might want to stick with whatever is most common in our codebase already to avoid extra work converting to one or the other

@jNullj
Copy link
Member

jNullj commented Jan 10, 2025

I'm gong to suggest we standardise on camelCase, but I also feel like there is a reason why we used snake_case in a lot of cases, and I can't remember what it is.

Maybe it makes sense when upstream api uses snake_case?

@chris48s
Copy link
Member Author

With a badge, the underlying API is something the user doesn't necessarily interact with so I don't think there's any benefit to vertical consistency with the upstream API here. I'd say horizontal consistency across badges gives more of a benefit for users in this case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
developer-experience Dev tooling, test framework, and CI
Projects
None yet
Development

No branches or pull requests

2 participants