jhermsmeier / node-envelope

Quite liberal Email parser
MIT License
40 stars 12 forks source link

Es6 #27

Closed brettz9 closed 4 years ago

brettz9 commented 4 years ago

Builds on #24, #25, and #26 .

refactor: use more es6 features (and enforce these and other practices with a few added rules)

jhermsmeier commented 4 years ago

Similar to #26, there's no benefit to using ES6 syntax sugar everywhere – sporadically where it makes sense, or is needed, sure – but not as a forcing rule, sorry.

brettz9 commented 4 years ago

If it helps to hear rationales for the particular ES6 features I added, these are why I like to use them:

1 prefer-destructuring and object-shorthand : I find these rules especially helpful in reducing the noise in one's code. While these are indeed just sugar (though native, performant sugar), I find they can help me see more quickly what else is going on in my code. With a clear view on the code, I find myself less prone to mistaken logic as well. 2 no-var - This is a little more than a sugar issue, I think, as let allows one to redefine variables in an inner scope without conflict and var, moreover, has a counter-intuitive hosting behavior (the latter can admittedly be avoided by a separate rule like vars-on-top, but if the environment supports it, I figure it is helpful to go with let or const for the other reason anyways). 3 prefer-const - I love this rule, as I find that I almost never need to use let, and when I do need a let now, the presence of that keyword causes me to pay more attention, as I know there is some state tracking going on. I think it communicates some sense of intent, and I find it helpful for that.

This PR also did have a couple stylistic rules (semi and quotes). My reason for adding them was because they are for pretty ubiquitously used syntax and to enforce your existing apparent preferences (for avoiding semi-colons and using single quotes). I find it can otherwise get a little disorderly looking, or even complicate searching when there are different styles at once (e.g., if I know inline functions have no space after the function keyword, I could use this fact to search for inline only).

But none of these are critical, so no worries if it is not your cup of tea!