Conversation
| ``` | ||
| ## External libraries | ||
|
|
||
| ### Prefer native js vs lodash |
There was a problem hiding this comment.
a good section, i like it. my common feedback - please add few words regarding to polyfills. Otherwise it looks unsafely to swapping to native methods.
There was a problem hiding this comment.
one more - is adding a few words when lodash is preferred, say reduce an Object, or find via object, is a shorthand's we prefer.
_.reduce({foo: 'FOO', bar: 'BAR'}, callback, {});
_.find( [{baz: 10}, {baz: 30}, {baz: 50}], {foo: 30});
There was a problem hiding this comment.
Maybe we will leave only bad cases to not divide all lodash functionality to good or bad? I described popular and often used methods. In cases above, we can use Object.(keys|values|entries) and after use array methods.
There was a problem hiding this comment.
I guess we have to provide a list of all bad technics we have to replace to native alternatives. Regarding to using two methods vs one: using two methods vs one is not a good choice. We have to make our code simple and do not introduce extra boilerplate code. Lodash is created for this.
There was a problem hiding this comment.
It's a rare case where you need reduce to object and I think it's nice to directly show where is a plain array or where is an object which you need to use as an array. You use one short method with particular cases and your code remains strict, native and without external modules except using external functionality which eats any type
DmitryKorlas
left a comment
There was a problem hiding this comment.
A good section, i like it. my common feedback - please add few words regarding to polyfills and examples when lodash is preferred.
|
Need more examples for Object, for instance: // BAD
_.isEmpty(value)
// GOOD
!Object.keys(value).length |
eslint-config-ringcentral/index.js
Outdated
| mocha: true | ||
| }, | ||
| extends: 'eslint:recommended', | ||
| extends: ['plugin:you-dont-need-lodash-underscore/all', 'eslint:recommended'], |
There was a problem hiding this comment.
Disagree. This one is too strict and not cross browser. I don't think we have totally forbid lodash. A lot of cases when lodash functionality is better choice vs native build-ins. I guess we have to prefer native methods when possible, but do not dictate using only native methods by introducing this rule into guide.
There was a problem hiding this comment.
It's not all at all. It is just which are easy to replace by native implementation https://github.com/you-dont-need/You-Dont-Need-Lodash-Underscore/blob/master/lib/rules/rules.json
| // BAD | ||
| _.uniq([1, 2, 3, 3, 2]); | ||
| // GOOD | ||
| [...new Set([1, 2, 3, 3, 2])]; |
There was a problem hiding this comment.
This one does not looks better vs lodash variant. _.uniq is more clear and shortener. Also, Set has cross browser limitations.
There was a problem hiding this comment.
Native and one line, easy to understand or to google purpose if not. I suggest it's a nice choice, IE should die, thinking about it is an atavism in 2k19. It will be attention about polyfills
| // BAD | ||
| _.includes([1, 2, 3], 1); | ||
| // GOOD | ||
| [1, 2, 3].includes(1); |
There was a problem hiding this comment.
Array.prototype.includes is not a cross browser and still not supported in IE11. Native variant is only preferred when polyfill is included. Otherwise it dangerous and we should not recommend it.
There was a problem hiding this comment.
I will add a attention about polyfills
|
|
||
| > Reason: lodash is a great library which contains a lot of useful functions but the modern js has the short identical part of this functionality so some lodash functions are excess alternative. | ||
|
|
||
| > Don't forget to check necessary browsers compatibility and turn on polyfills if it's needed. |
There was a problem hiding this comment.
A good note, I like it. I guess it would be better to clarify which variants is dangerous and add a link to MDN for every such method. We have to notify a users of this document.
There was a problem hiding this comment.
I suggest to not create a compatibility map, all developers understand about using different functionality and should think about each method itself depending which browser support is needed for an application
DmitryKorlas
left a comment
There was a problem hiding this comment.
see the feedback in a comments
3b13d34 to
9a092f1
Compare
5aeddaa to
a07208c
Compare
af1b08f to
e0da56d
Compare
9192a7d to
24cc0dc
Compare
11833aa to
433cd59
Compare
9a9f751 to
bb4b754
Compare
bb4b754 to
590365c
Compare
945b052 to
e966dfe
Compare
No description provided.