-
Notifications
You must be signed in to change notification settings - Fork 50.5k
Enable linting for __tests__ #3985
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,8 @@ | ||
| var warning = require('./lib/warning'); | ||
| warning( | ||
| false, | ||
| 'require("react/addons") is deprecated. ' + | ||
| 'Access using require("react/addons/{addon}") instead.' | ||
| "require('react/addons') is deprecated. " + | ||
| "Access using require('react/addons/{addon}') instead." | ||
| ); | ||
|
|
||
| module.exports = require('./lib/ReactWithAddons'); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -50,20 +50,20 @@ describe('ReactComponentWithPureRenderMixin', function() { | |
| getInitialState: function() { | ||
| return { | ||
| cut: false, | ||
| slices: 1, | ||
| slices: 1 | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd rather just turn off the no trailing commas rule.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree, and think we should actually enforce trailing commas, but I think that should be another commit, and could be done with a codemod.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this commit can we turn off the rule and not remove all the trailing commas (just to add them again a little later)? Also happy for us to add them everywhere before landing this PR if you'd rather do that.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll open another PR reversing this rule, and rebase this PR on top of it after it merges. That seems like the least amount of overall effort.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay. I've changed my mind here. I'll fix the dangling commas after this PR lands. I hacked together a fancy codemod tool that hooks into eslint's node API to fix the code. (which is awesome because we get zero false positives, and it obeys eslintignore/eslintrc files) |
||
| }; | ||
| }, | ||
|
|
||
| cut: function() { | ||
| this.setState({ | ||
| cut: true, | ||
| slices: 10, | ||
| slices: 10 | ||
| }); | ||
| }, | ||
|
|
||
| eatSlice: function() { | ||
| this.setState({ | ||
| slices: this.state.slices - 1, | ||
| slices: this.state.slices - 1 | ||
| }); | ||
| }, | ||
|
|
||
|
|
@@ -101,7 +101,7 @@ describe('ReactComponentWithPureRenderMixin', function() { | |
| function getInitialState() { | ||
| return { | ||
| foo: [1, 2, 3], | ||
| bar: {a: 4, b: 5, c: 6}, | ||
| bar: {a: 4, b: 5, c: 6} | ||
| }; | ||
| } | ||
|
|
||
|
|
@@ -127,7 +127,7 @@ describe('ReactComponentWithPureRenderMixin', function() { | |
| // Do not re-render if state is equal | ||
| var settings = { | ||
| foo: initialSettings.foo, | ||
| bar: initialSettings.bar, | ||
| bar: initialSettings.bar | ||
| }; | ||
| instance.setState(settings); | ||
| expect(renderCalls).toBe(1); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,7 +27,7 @@ describe('ReactFragment', function() { | |
| x: <span />, | ||
| y: <span /> | ||
| }; | ||
| <div>{children}</div>; | ||
| void <div>{children}</div>; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Eh, not sure how I feel about this. I don't have a good alternative though
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The alternative, IMHO is to disable no-unused-expression in |
||
| expect(console.error.calls.length).toBe(1); | ||
| expect(console.error.calls[0].args[0]).toContain( | ||
| 'Any use of a keyed object' | ||
|
|
@@ -37,7 +37,7 @@ describe('ReactFragment', function() { | |
| x: <span />, | ||
| y: <span /> | ||
| }; | ||
| <div>{sameChildren}</div>; | ||
| void <div>{sameChildren}</div>; | ||
| expect(console.error.calls.length).toBe(1); | ||
| }); | ||
|
|
||
|
|
@@ -65,7 +65,7 @@ describe('ReactFragment', function() { | |
| y: <span /> | ||
| }; | ||
| var frag = ReactFragment.create(children); | ||
| frag.x; | ||
| void frag.x; | ||
| frag.y = 10; | ||
| expect(console.error.calls.length).toBe(1); | ||
| expect(console.error.calls[0].args[0]).toContain( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,7 +13,6 @@ | |
|
|
||
| var React; | ||
| var ReactTransitionGroup; | ||
| var mocks; | ||
|
|
||
| // Most of the real functionality is covered in other unit tests, this just | ||
| // makes sure we're wired up correctly. | ||
|
|
@@ -23,7 +22,6 @@ describe('ReactTransitionGroup', function() { | |
| beforeEach(function() { | ||
| React = require('React'); | ||
| ReactTransitionGroup = require('ReactTransitionGroup'); | ||
| mocks = require('mocks'); | ||
|
|
||
| container = document.createElement('div'); | ||
| }); | ||
|
|
@@ -94,15 +92,15 @@ describe('ReactTransitionGroup', function() { | |
|
|
||
| it('should handle enter/leave/enter/leave correctly', function() { | ||
| var log = []; | ||
| var cb; | ||
| var willEnterCb; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (Why this change?)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
|
|
||
| var Child = React.createClass({ | ||
| componentDidMount: function() { | ||
| log.push('didMount'); | ||
| }, | ||
| componentWillEnter: function(_cb) { | ||
| componentWillEnter: function(cb) { | ||
| log.push('willEnter'); | ||
| cb = _cb; | ||
| willEnterCb = cb; | ||
| }, | ||
| componentDidEnter: function() { | ||
| log.push('didEnter'); | ||
|
|
@@ -139,12 +137,13 @@ describe('ReactTransitionGroup', function() { | |
| expect(log).toEqual(['didMount']); | ||
| instance.setState({count: 2}); | ||
| expect(log).toEqual(['didMount', 'didMount', 'willEnter']); | ||
| for (var i = 0; i < 5; i++) { | ||
| for (var k = 0; k < 5; k++) { | ||
| instance.setState({count: 2}); | ||
| expect(log).toEqual(['didMount', 'didMount', 'willEnter']); | ||
| instance.setState({count: 1}); | ||
| } | ||
| cb(); | ||
| // other animations are blocked until willEnterCb is called | ||
| willEnterCb(); | ||
| expect(log).toEqual([ | ||
| 'didMount', 'didMount', 'willEnter', | ||
| 'didEnter', 'willLeave', 'didLeave', 'willUnmount' | ||
|
|
@@ -153,15 +152,15 @@ describe('ReactTransitionGroup', function() { | |
|
|
||
| it('should handle enter/leave/enter correctly', function() { | ||
| var log = []; | ||
| var cb; | ||
| var willEnterCb; | ||
|
|
||
| var Child = React.createClass({ | ||
| componentDidMount: function() { | ||
| log.push('didMount'); | ||
| }, | ||
| componentWillEnter: function(_cb) { | ||
| componentWillEnter: function(cb) { | ||
| log.push('willEnter'); | ||
| cb = _cb; | ||
| willEnterCb = cb; | ||
| }, | ||
| componentDidEnter: function() { | ||
| log.push('didEnter'); | ||
|
|
@@ -198,20 +197,19 @@ describe('ReactTransitionGroup', function() { | |
| expect(log).toEqual(['didMount']); | ||
| instance.setState({count: 2}); | ||
| expect(log).toEqual(['didMount', 'didMount', 'willEnter']); | ||
| for (var i = 0; i < 5; i++) { | ||
| for (var k = 0; k < 5; k++) { | ||
| instance.setState({count: 1}); | ||
| expect(log).toEqual(['didMount', 'didMount', 'willEnter']); | ||
| instance.setState({count: 2}); | ||
| } | ||
| cb(); | ||
| willEnterCb(); | ||
| expect(log).toEqual([ | ||
| 'didMount', 'didMount', 'willEnter', 'didEnter' | ||
| ]); | ||
| }); | ||
|
|
||
| it('should handle entering/leaving several elements at once', function() { | ||
| var log = []; | ||
| var cb; | ||
|
|
||
| var Child = React.createClass({ | ||
| componentDidMount: function() { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,10 +22,6 @@ describe('ReactChildren', function() { | |
| ReactFragment = require('ReactFragment'); | ||
| }); | ||
|
|
||
| function frag(obj) { | ||
| return ReactFragment.create(obj); | ||
| } | ||
|
|
||
| function nthChild(mappedChildren, n) { | ||
| var result = null; | ||
| ReactChildren.forEach(mappedChildren, function(child, index) { | ||
|
|
@@ -227,7 +223,7 @@ describe('ReactChildren', function() { | |
|
|
||
| var instance = ( | ||
| <div>{ | ||
| [frag({ | ||
| [ReactFragment.create({ | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (Why?)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Later in the code, there's the test: it('should warn if a fragment is accessed', function() {
spyOn(console, 'error');
var child = React.createElement('span');
var frag = ReactChildren.map([child, child], function(c) {
return c;
});
...Which means there's shadowing. Since frag was just a stub method used in only two places, I figured it'd be better to just get rid of it rather than renaming things to avoid a conflict.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure. |
||
| firstHalfKey: [zero, one, two], | ||
| secondHalfKey: [three, four], | ||
| keyFive: five | ||
|
|
@@ -345,7 +341,9 @@ describe('ReactChildren', function() { | |
| var zero = <div key="something"/>; | ||
| var one = <span key="something" />; | ||
|
|
||
| var mapFn = function(component) { return component; }; | ||
| var mapFn = function(component) { | ||
| return component; | ||
| }; | ||
| var instance = ( | ||
| <div>{zero}{one}</div> | ||
| ); | ||
|
|
@@ -410,7 +408,7 @@ describe('ReactChildren', function() { | |
|
|
||
| var instance = ( | ||
| <div>{ | ||
| [frag({ | ||
| [ReactFragment.create({ | ||
| firstHalfKey: [zero, one, two], | ||
| secondHalfKey: [three, four], | ||
| keyFive: five | ||
|
|
@@ -438,7 +436,7 @@ describe('ReactChildren', function() { | |
| return c; | ||
| }); | ||
| for (var key in frag) { | ||
| frag[key]; | ||
| void frag[key]; | ||
| break; | ||
| } | ||
| expect(console.error.calls.length).toBe(1); | ||
|
|
@@ -447,8 +445,8 @@ describe('ReactChildren', function() { | |
| var frag2 = ReactChildren.map([child, child], function(c) { | ||
| return c; | ||
| }); | ||
| for (var key in frag2) { | ||
| frag2[key] = 123; | ||
| for (var key2 in frag2) { | ||
| frag2[key2] = 123; | ||
| break; | ||
| } | ||
| expect(console.error.calls.length).toBe(2); | ||
|
|
||
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.
Any difference between true and false here? If not let's be consistent (I don't care what the value is if it works)
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.
http://eslint.org/docs/user-guide/configuring.html
EDIT: I can comment something to that effect in the eslintrc if you want.
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.
Ah no, I just didn't realize there was a difference. I might have known back when I first did this (I think there's a test that toggles
__DEV__)