-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
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
[Core] Improve eslint a bit more #2903
Comments
Are these all that's left? |
I was also thinking about:
But I'm not 100% convinced we need them. |
|
I think these are all mostly good. I could definitely argue for some of them and I can't really argue against any of them. I'm open to what you both think is best. At some point I would be curious to do a comparison of our eslint feature set to React's or AirBnb's. For example, is our's looser or stricter? And if we happen to be really close to one, maybe we could adopt it. If we're not close but feel strongly about ours, then we can leave it be. |
We should finish discussing our stance on |
I think we should add Should be pretty simple: src/auto-complete.jsx
408:13 error JSX props should not use arrow functions react/jsx-no-bind
414:13 error JSX props should not use arrow functions react/jsx-no-bind
418:13 error JSX props should not use arrow functions react/jsx-no-bind
422:13 error JSX props should not use arrow functions react/jsx-no-bind
src/DropDownMenu/DropDownMenu.jsx
388:11 error JSX props should not use .bind() react/jsx-no-bind
src/time-picker/clock.jsx
180:11 error JSX props should not use .bind() react/jsx-no-bind
181:11 error JSX props should not use .bind() react/jsx-no-bind
src/time-picker/time-display.jsx
151:11 error JSX props should not use arrow functions react/jsx-no-bind
158:11 error JSX props should not use arrow functions react/jsx-no-bind |
@newoga out of interest, what would you use instead of:
|
@mbrookes This is less of a style preference and more for performance! I didn't realize it until just recently when I read a blog post. I'm not quite the best approach of how to handle this all the time, but this would be better I think: handleOnTouchTap(value) {
this.props.onSelectAffix(value);
}
<Component prop={this.handleOntouchTap('pm')} /> |
Note, our performance issues related in the |
The jsx-no-bind doc says this:
|
@newoga I think that your proposal doesn't solve anything 😁. handleOnTouchTap(value) {
this.props.onSelectAffix(value);
}
<Component prop={this.handleOntouchTap} type="pm" /> |
Haha, I knew something didn't look right when I typed it 😁! I guess the component that is calling the |
@oliviertassinari Maybe for |
@oliviertassinari No, this should be better. 😏 : handleOnTouchTap() {
this.props.onSelectAffix();
}
<Component prop={this.handleOntouchTap} type=“pm" /> @newoga thanks for the explanation, I wasn't aware of the performance implication - I'll keep it in mind for my own code. |
@oliviertassinari That will still create a new element object. I don't think I think this low level of optimization should be avoided as it complicates the code. If we properly implement pure-render (Recompose |
@mbrookes @oliviertassinari Nope: <Component prop={this.props.onSelectAffix} type=“pm"/> |
@alitaheri Good point. We save one function allocation but we then have the memory allocation required for a component. Not that great 😁. I'm wondering if we can solve the binding without introducing a new component in some cases. |
@alitaheri - ah, you win! 😆 |
@oliviertassinari Functions are immutable. you can't change what they have in their closures. in some cases it's simply impossible. I'd say we really shouldn't worry about this. I mean if we memoize style objects all our problems will be solved. and these functions will go unnoticed for as long as javascript lives 😆 There are much bigger fish to fry than this. let's cook'em first and then if profilers brag about these function allocations we'll come back to this issue 😁 |
I don't think that's correct, because we're looping through menu items: const menuItemElements = menuItems
? menuItems.map((item, idx) => (
<MenuItem
key={idx}
primaryText={item[displayMember || 'text']}
value={item[valueMember]}
onTouchTap={this._onMenuItemTouchTap.bind(this, idx, item)}
/>
))
: React.Children.map(children, child => {
const clone = React.cloneElement(child, {
onTouchTap: this._onMenuItemTouchTap.bind(this, index, child.props.value),
}, child.props.children);
index += 1;
return clone;
}); According to the docs, this would be a new function allocation per component that is rendered rather than just one for all? |
@newoga There is nothing we can do about it in this case since it's placing |
@alitaheri Okay fair enough! 😄 |
I just updated my eslint-airbnb configuration in my personal project today and they started enforcing this: http://eslint.org/docs/rules/no-unneeded-ternary That might be a good one for us to add to the list. @alitaheri This one is for you. 😆 |
@newoga I'm loving it! |
No more monsters within monsters 😆 |
There's nothing inherently wrong with nested ternaries, as long as they're formatted correctly. This: let thing = foo ? bar
: (baz === qux) ? quxx
: foobar; is more readable than both of the following, and more compact than the latter: let thing = foo ? bar : baz === qux ? quxx : foobar; let thing;
if (foo) {
thing = bar;
} else if (baz === qux) {
thing = quxx;
} else {
thing = foobar;
} |
If you format your last example like this:
|
There is indeed nothing wrong with well formatted nested ternary. I use it myself, to get away with singular expression: const foo = cond1
? value1
: cond2
? value2
: value3; The real issue is when value is expression itself... const foo = criteria1 === stuff < 0
? [(stuff + bar), ...restOfTheStuff]
: cond2
? [someOtherIrrelevantStuff]
: {object: "?!!!"}; that begins to lose it's readability really fast. I have nothing against ternary, I even sometimes nest them 3 levels deep and it still remains readable. But they should be used to make code easier to read, as should everything else! not make it harder. this applies to everything. even if/else chains. if it makes code readable use it, if it feels "clever", then it's wrong. |
IMHO, using space to align the code is a bad idea for maintainability. |
I think we all agree then - use appropriately, format properly, and |
Would you consider adding this to the list? http://eslint.org/docs/rules/operator-linebreak I noticed in Stepper that @namKolo put the + for string continuation linebreaks on the following line, which may be preferable, as extending a string onto a new line then only requires one line change, not two. |
That's a good point. I think that the best to do is to use |
Either works for me, but good to have the consistency. |
I think we should add |
I saw |
Lets hold these until we get the bulk of the bugfix / enhancement PRs merged. |
I agree, let's do a freeze on eslinting for now until we're ready to do a lot of the big remaining pieces. When that's done we'll give @oliviertassinari a few days to perfect the rest of these 😁 |
Alright, let's wait. |
please please please |
Having a look at the source code, I think that we can stil improve it before starting doing heavy changes.
I was thinking about enforcing those rules:
brace-style: 2
: that prevent merge conflict between / coding style [eslint] Enforce brace-style #2920react/jsx-pascal-case: 2
https://github.com/airbnb/javascript/tree/master/react#naming [eslint] Enforce new react rules #2953react/jsx-closing-bracket-location: 2
[eslint] Enforce new react rules #2953react/jsx-max-props-per-line: [2, {maximum: 3}]
[eslint] Enforce new react rules #2953jsx-equals-spacing: 2
[eslint] enforce react/jsx-equals-spacing #3035arrow-parens: 2
[eslint] Enforce arrow-parens #3207prefer-template: 2
[eslint] Enforce prefer-template #3242no-unneeded-ternary: 2
[eslint] Enforce one more rule no-unneeded-ternary #3320prefer-const: 2
: that reduce the overhead when trying to understand what the property is for. [eslint] Refactor some component to use const instead of let #3300 [eslint] Enforce prefer-const #3315jsx-space-before-closing: 2
[eslint] Enforce jsx-space-before-closing #3397id-blacklist: [2, e]
[eslint] Move from e to event #3398react/no-is-mounted: 2
[Core] Remove isMounted() #3437padded-blocks: [2, never]
[eslint] enforce padded-blocks never #3493no-multiple-empty-lines: 2
[eslint] Enforce operator-linebreak and no-multiple-empty-lines #3516operator-linebreak: [2, "after"]
[eslint] Enforce operator-linebreak and no-multiple-empty-lines #3516react/jsx-handler-names: 2
[eslint] Enforce jsx-handler-names #3408react/prefer-es6-class: 2
prefer-arrow-callback: 2
: well, because it's cool?react/no-multi-comp: 2
: that's simpler to look for a specific componentno-shadow: 2
The text was updated successfully, but these errors were encountered: