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
jsx-no-bind: Report usage of local functions as violations #3048
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems great.
Arguably this is a breaking change since it will cause more warnings to appear, but equally arguably, it's a bug fix that function declarations were ever ignored (it just never came up because the airbnb styleguide forbids function declarations entirely).
08132d4
to
49b7182
Compare
Codecov Report
@@ Coverage Diff @@
## master #3048 +/- ##
=======================================
Coverage 97.40% 97.41%
=======================================
Files 111 111
Lines 7445 7452 +7
Branches 2723 2726 +3
=======================================
+ Hits 7252 7259 +7
Misses 193 193
Continue to review full report at Codecov.
|
Cheers! |
This incorrectly marks a valid code as incorrect in BDD-style tests. describe('<Outer/>', () => {
const Inner = () => <div/>;
it('wraps', () => {
render(
<Outer inner={Inner} />
);
});
}); |
@andy128k In your case you can extract Inner outside of describe, cos it has no closure |
@andy128k i don't think there's as much value for this rule to apply to tests at all, since it's a rule about runtime performance. |
@JustFly1984 describe('<Outer/>', () => {
describe('<div/>, () => {
const Inner = () => <div/>;
it('wraps', () => {
render(
<Outer inner={Inner} />
);
});
});
describe('<span/>', () => {
const Inner = () => <span/>;
it('wraps', () => {
render(
<Outer inner={Inner} />
);
});
});
}); Extraction just breaks code style. @ljharb This is what I did -- ignored this rule for affected tests. But having a separated configuration of eslint for tests just feels wrong. |
It’s totally normal and expected and it’s weird to have the same exact eslint config for tests and prod code - that said, if there’s a way to handle this case that doesn’t special-case BDD globals, I’m down. |
You can rewrite/disable rules in eslintrc for /*.{test|spec}.{j|t}sx?/ files |
Fixes #3047
I implemented this in a pretty straightforward way, so there are some trade-offs:
To fix 1 would require some fancy analysis, and is probably not worth the effort, though 2 would be easy to fix and I can do so if needed.