-
Notifications
You must be signed in to change notification settings - Fork 0
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
Disable alphabetic sorting of object keys #9
Comments
fwiw. pros:
cons:
|
Thanks i'll add those! |
I like that there's a single correct way to order both objects and members, but I don't feel strongly that we have to enforce it. The cons probably outweigh the pros here. |
@andsens in case of special rules, you'll have to add a new rule on each case you encounter, no? |
@miklschmidt, yes. That goes both for the special rules mentioned in the pros as well as the cons. |
@bondo Totally agree with the member ordering, ordering by access level and component lifecycle methods is great. I like enforcing order that makes sense. |
Is kind of a strangely worded con. Is it a con that there's another solution to a part of the problem? |
Well, I'd say pretty much the whole problem. As in, instead of creating an all-encompassing rule and the whittling it down through special cases, build up a set of rules instead that eventually cover every aspect. |
@andsens oh yea i agree with that, but is that a con? Isn't that more of a "how we can do it differently", or a "better solution".. I'll add that. |
I think there's several rules in place here - and we should split this issue in two. There's object member ordering and class member ordering. These are two quite different things - as one can affect the semantics of the program and one cannot. With that said - I can follow the argument for removing the rule around object member orderings - these rarely tend to be so large that there's an actual advantage, whereas classes do grow quite large and figuring out where the "correct" place to add a new member can be quite tedious. I think it is important to note here that, as long as there's a rule in place, to order by alphabetical names, one should not simply rename something to group it together - this is not the intent behind these rules - you're not supposed to do something to get to what you tried to do that the linter told you was not the way. The linter tells you to move a member - not rename it. The goal around trying to find a rule that "makes sense" or "just works" around ordering of stuff (that groups things together) is a noble one, but I don't see it happening. There's simply way too many special cases to handle if that is what you want to do. And what is the plan here? Creating a rule that says you have to group width and height together, not caring about anything else? @miklschmidt Can you change this issue to be solely related to object member ordering? If you feel strongly about class member orderings then also create an issue for that? (which btw, there's a ton of options of how to order class members, see the tslint docs on class member orderings, it's not a simple yes/no). As stated earlier - I'm fine with removing the rule on object member orderings. Personally I do prefer not having to think about where to put my stuff and knowing where I should find it again - as I would much rather focus my energy on actual coding - but if the rest of you feel strongly about this there's not that much difference here and that can be worked out. Do remember though - if the goal is to create a rule about logical grouping, then you need to come up with an actual plan for implementing that. Simply saying "add stuff one by one" is not enough. Do we add stuff that we have rules for in random places in the object? Top, or bottom? Creating such a rule set is a huge task - and would probably not do down well. There's also always the option of trying to solve the CSS issues in a special case basis (where we could create rules for logical grouping - assuming one would come up with a complete set of rules). That is a tedious, but doable task. |
Absolutely, will do!
You should think about where you put your stuff, that's what makes the difference between good readable code and less readable code. Also as long as we don't have an auto fix for alphabetic sorting, you have to think way harder than if you didn't have to alphabetically sort everything. We can make a style guide for this if you think adding rules for it is too much work. We could do something like this:
Which would solve that problem, i know it's practically impossible to enforce programatically, but again, i don't think we should choose a lesser solution because our tooling says no. Randomly forcing an arbitrary sorting that doesn't yield a net benefit is not really fixing anything, other than consistency. Personally i'd rather have inconsistent readable code than consistent unreadable code, if you catch my drift. I totally agree with enforcing things that make the code more readable, such as enforcing react lifecycle methods in the top of the class, access level sort order and so on, because those are specific logical groupings, we should have more of those, and less of the arbitrary stuff. |
I guess I'm just not that convinced that we will end up with a better grouping when it is not always clear that there is one. I do like the idea around possibly using comments to create such groupings - which is also an option that we could explore. To have a default that will do alphabetical sorting and then allow creating separate groups after the default (to ie. group all stuff having to do with |
Can we do that? I'd be okay with that compromise! |
It'd take some work, but I can't see why not. |
I'm thinking something like the following:
Does this sound reasonable to you? Or is there something you'd like to see changed? |
What's "Defaults"?, rest sounds good! |
Ah defaults was a bad name, (will edit) meant ungrouped. Here's some examples: Default/ungrouped: {
a: 1,
b: 2,
c: 3,
} Groups {
// My group
b: 1,
// My other group
a: 1
} Mixed groups and ungrouped/defaults {
c: 1,
// My group
b: 2,
// My other group
c: 3
} |
Ah yes! Perfect! |
Could we maybe make a "special group" called "CSS" that just disables the sorting completely until we have a working DSL or some better rules? |
Technically sure, although I'd probably call it something different. The only issue worth mentioning here is that it'd only affect the object it is defined in (ie. not nested objects.). Also, it'd not be much different from simply disabling the rule and reenabling it. |
Yea well you've got a point there! I'll just disable it for CSS for now. |
So far the only pro i've heard for this is that keys are easier to find when they're alphabetically sorted. I think this is an invalid pro because to make use of alphabetic sorting, you need to know the name of the key you're looking for. If you already know the name, ctrl/cmd+f is your friend.
Object key sorting:
pros:
cons:
padding
with apaddingBottom
because the wrong order is enforced.width
andheight
, orisModalShown
andtoggleModal
.Possible solution to achieve non-arbitrary consistency:
Feel free to add pros/cons to the list!
Vote 👍 for removal, 👎 for keeping.
The text was updated successfully, but these errors were encountered: