eslint-plugin-ember icon indicating copy to clipboard operation
eslint-plugin-ember copied to clipboard

Route segments naming convention

Open Windvis opened this issue 7 years ago • 6 comments

Can anyone explain why snake_case is the recommended naming convention for route segments?

The route-segments-snake-case documentation mentions Ember doesn't have to do extra serialization in order to resolve promises but I'm not sure what that means exactly.

I would prefer to just use camelCase in our apps, but I first want to understand why snake_case was recommended in the first place 😄

Windvis avatar Jan 11 '19 10:01 Windvis

@rwjblue do you happen to know the answer? I stumbled upon this question yesterday too and couldn't find an answer

Turbo87 avatar Apr 09 '20 23:04 Turbo87

Basically _id is treated specially in the default Route.prototype.model implementation:

https://github.com/emberjs/ember.js/blob/b815c77d62840c3c252b7177fa442a38e4584659/packages/@ember/-internals/routing/lib/system/route.ts#L1162-L1191

IMHO, this has aged pretty poorly and should be reconsidered, but given that this type of implicit behavior is actually kinda hard to migrate away from the exact transition path is tricky.

rwjblue avatar Apr 13 '20 16:04 rwjblue

We could probably make that regexp match either post_id or postId, but it isn't immediately clear if that should be considered breaking in and of itself. 😩

rwjblue avatar Apr 13 '20 16:04 rwjblue

FWIW, I think we could tweak the rule to make it clearer that _id is the only snake case thing suggested. Everything else could be camel. :thinking:

rwjblue avatar Apr 13 '20 16:04 rwjblue

could we make it an optional feature to use postId instead of post_id, or something like that?

Turbo87 avatar Apr 13 '20 16:04 Turbo87

I would like to find a path towards dropping snake-casing conventions entirely.

EDIT: Looks like there's an RFC: https://github.com/emberjs/rfcs/issues/556.

mmun avatar Apr 20 '21 21:04 mmun