diff --git a/package.json b/package.json index 85129d49c..060687cb3 100644 --- a/package.json +++ b/package.json @@ -64,7 +64,7 @@ "babel-core": "^6.14.0", "babel-eslint": "^6.1.2", "babel-loader": "^6.2.5", - "babel-preset-airbnb": "^2.0.0", + "babel-preset-airbnb": "^2.1.0", "babel-register": "^6.14.0", "chai": "^3.5.0", "coveralls": "^2.11.14", @@ -73,9 +73,9 @@ "enzyme-example-karma-webpack": "^0.1.4", "enzyme-example-mocha": "^0.1.0", "enzyme-example-react-native": "^0.1.0", - "eslint": "^3.5.0", - "eslint-config-airbnb": "^10.0.1", - "eslint-plugin-import": "^1.15.0", + "eslint": "^3.6.1", + "eslint-config-airbnb": "^12.0.0", + "eslint-plugin-import": "^1.16.0", "eslint-plugin-jsx-a11y": "^2.2.2", "eslint-plugin-react": "^6.3.0", "gitbook-cli": "^1.0.1", @@ -88,7 +88,7 @@ "karma-mocha": "^1.1.1", "karma-sourcemap-loader": "^0.3.7", "karma-webpack": "^1.7.0", - "mocha": "^3.0.2", + "mocha": "^3.1.0", "rimraf": "^2.5.4", "sinon": "^1.17.6", "webpack": "^1.13.2" diff --git a/src/ComplexSelector.js b/src/ComplexSelector.js index 1a5722d63..27346b823 100644 --- a/src/ComplexSelector.js +++ b/src/ComplexSelector.js @@ -7,17 +7,15 @@ export default class ComplexSelector { this.childrenOfNode = childrenOfNode; } - getSelectors(selector) { + getSelectors(selector) { // eslint-disable-line class-methods-use-this const selectors = split(selector, / (?=(?:(?:[^"]*"){2})*[^"]*$)/); return selectors.reduce((list, sel) => { if (sel === '+' || sel === '~') { const temp = list.pop(); - list.push(sel, temp); - return list; + return list.concat(sel, temp); } - list.push(sel); - return list; + return list.concat(sel); }, []); } @@ -35,7 +33,7 @@ export default class ComplexSelector { return (child) => { if (firstPredicate(child)) { - return (sibling) => secondPredicate(sibling); + return sibling => secondPredicate(sibling); } return false; @@ -85,16 +83,7 @@ export default class ComplexSelector { } treeFilterDirect() { - return (tree, fn) => { - const results = []; - this.childrenOfNode(tree).forEach(child => { - if (fn(child)) { - results.push(child); - } - }); - - return results; - }; + return (tree, fn) => this.childrenOfNode(tree).filter(child => fn(child)); } treeFindSiblings(selectSiblings) { @@ -102,16 +91,15 @@ export default class ComplexSelector { const results = []; const list = [this.childrenOfNode(tree)]; - const traverseChildren = (children) => - children.forEach((child, i) => { - const secondPredicate = fn(child); + const traverseChildren = children => children.forEach((child, i) => { + const secondPredicate = fn(child); - list.push(this.childrenOfNode(child)); + list.push(this.childrenOfNode(child)); - if (secondPredicate) { - selectSiblings(children, secondPredicate, results, i); - } - }); + if (secondPredicate) { + selectSiblings(children, secondPredicate, results, i); + } + }); while (list.length) { traverseChildren(list.shift()); diff --git a/src/MountedTraversal.js b/src/MountedTraversal.js index 7465a1e70..d6e8685e9 100644 --- a/src/MountedTraversal.js +++ b/src/MountedTraversal.js @@ -117,7 +117,7 @@ export function childrenOfInstInternal(inst) { return false; } return true; - }).map(key => { + }).map((key) => { if (!REACT013 && typeof renderedChildren[key]._currentElement.type === 'function') { return renderedChildren[key]._instance; } diff --git a/src/ReactWrapper.jsx b/src/ReactWrapper.jsx index 6545ca14f..f6ba502b4 100644 --- a/src/ReactWrapper.jsx +++ b/src/ReactWrapper.jsx @@ -360,14 +360,7 @@ export default class ReactWrapper { * @returns {Boolean} */ containsAnyMatchingElements(nodes) { - if (!Array.isArray(nodes)) return false; - if (nodes.length <= 0) return false; - for (let i = 0; i < nodes.length; i++) { - if (this.containsMatchingElement(nodes[i])) { - return true; - } - } - return false; + return Array.isArray(nodes) && nodes.some(node => this.containsMatchingElement(node)); } /** @@ -467,7 +460,7 @@ export default class ReactWrapper { * @returns {String} */ html() { - return this.single('html', n => { + return this.single('html', (n) => { const node = findDOMNode(n); return node === null ? null : node.outerHTML.replace(/\sdata-(reactid|reactroot)+="([^"]*)+"/g, ''); @@ -495,7 +488,7 @@ export default class ReactWrapper { * @returns {ReactWrapper} */ simulate(event, mock = {}) { - this.single('simulate', n => { + this.single('simulate', (n) => { const mappedEvent = mapNativeEventNames(event); const eventFn = Simulate[mappedEvent]; if (!eventFn) { diff --git a/src/ReactWrapperComponent.jsx b/src/ReactWrapperComponent.jsx index 3cb191557..b5cc35bb2 100644 --- a/src/ReactWrapperComponent.jsx +++ b/src/ReactWrapperComponent.jsx @@ -1,6 +1,8 @@ import React, { PropTypes } from 'react'; import objectAssign from 'object.assign'; +/* eslint react/forbid-prop-types: 0 */ + /** * This is a utility component to wrap around the nodes we are * passing in to `mount()`. Theoretically, you could do everything diff --git a/src/ShallowTraversal.js b/src/ShallowTraversal.js index 9b32e209e..c561fe073 100644 --- a/src/ShallowTraversal.js +++ b/src/ShallowTraversal.js @@ -17,7 +17,7 @@ export function childrenOfNode(node) { if (!node) return []; const maybeArray = propsOfNode(node).children; const result = []; - React.Children.forEach(maybeArray, child => { + React.Children.forEach(maybeArray, (child) => { if (child !== null && child !== false && typeof child !== 'undefined') { result.push(child); } @@ -40,7 +40,7 @@ export function treeForEach(tree, fn) { export function treeFilter(tree, fn) { const results = []; - treeForEach(tree, node => { + treeForEach(tree, (node) => { if (fn(node)) { results.push(node); } @@ -56,7 +56,7 @@ export function pathToNode(node, root) { const queue = [root]; const path = []; - const hasNode = (testNode) => node === testNode; + const hasNode = testNode => node === testNode; while (queue.length) { const current = queue.pop(); diff --git a/src/ShallowWrapper.js b/src/ShallowWrapper.js index e1551b0d0..fe0284643 100644 --- a/src/ShallowWrapper.js +++ b/src/ShallowWrapper.js @@ -376,14 +376,7 @@ export default class ShallowWrapper { * @returns {Boolean} */ containsAnyMatchingElements(nodes) { - if (!Array.isArray(nodes)) return false; - if (nodes.length <= 0) return false; - for (let i = 0; i < nodes.length; i++) { - if (this.containsMatchingElement(nodes[i])) { - return true; - } - } - return false; + return Array.isArray(nodes) && nodes.some(node => this.containsMatchingElement(node)); } /** @@ -512,11 +505,7 @@ export default class ShallowWrapper { * @returns {String} */ html() { - return this.single('html', n => { - // NOTE: splitting this into two statements is required to make the linter happy. - const isNull = this.type() === null; - return isNull ? null : renderToStaticMarkup(n); - }); + return this.single('html', n => (this.type() === null ? null : renderToStaticMarkup(n))); } /** diff --git a/src/Utils.js b/src/Utils.js index 15bc375bb..b6428d34b 100644 --- a/src/Utils.js +++ b/src/Utils.js @@ -67,7 +67,7 @@ export function childrenEqual(a, b, lenComp) { if (!a && !b) return true; if (a.length !== b.length) return false; if (a.length === 0 && b.length === 0) return true; - for (let i = 0; i < a.length; i++) { + for (let i = 0; i < a.length; i += 1) { if (!nodeEqual(a[i], b[i], lenComp)) return false; } return true; @@ -80,7 +80,7 @@ export function nodeEqual(a, b, lenComp = is) { const left = propsOfNode(a); const leftKeys = Object.keys(left); const right = propsOfNode(b); - for (let i = 0; i < leftKeys.length; i++) { + for (let i = 0; i < leftKeys.length; i += 1) { const prop = leftKeys[i]; // we will check children later if (prop === 'children') { @@ -214,13 +214,8 @@ export function selectorType(selector) { } export function AND(fns) { - return x => { - let i = fns.length; - while (i--) { - if (!fns[i](x)) return false; - } - return true; - }; + const fnsReversed = fns.slice().reverse(); + return x => fnsReversed.every(fn => fn(x)); } export function coercePropValue(propName, propValue) { diff --git a/test/.eslintrc b/test/.eslintrc index 916f89a9f..890a258d6 100644 --- a/test/.eslintrc +++ b/test/.eslintrc @@ -11,5 +11,7 @@ "import/no-extraneous-dependencies": [2, { "devDependencies": true }], + "jsx-a11y/no-static-element-interactions": 0, + "jsx-a11y/anchor-has-content": 0 } } diff --git a/test/Debug-spec.jsx b/test/Debug-spec.jsx index 93fea1fc8..4f6aed922 100644 --- a/test/Debug-spec.jsx +++ b/test/Debug-spec.jsx @@ -417,7 +417,7 @@ describe('debug', () => { }); it('renders passed children properly', () => { - const Foo = (props) => ( + const Foo = props => (
From Foo {props.children} diff --git a/test/ReactWrapper-spec.jsx b/test/ReactWrapper-spec.jsx index 5ea475879..a9649a3d1 100644 --- a/test/ReactWrapper-spec.jsx +++ b/test/ReactWrapper-spec.jsx @@ -970,7 +970,7 @@ describeWithDOM('mount', () => { describeIf(!REACT013, 'stateless function components', () => { it('should set props for a component multiple times', () => { - const Foo = (props) => ( + const Foo = props => (
{props.id}
@@ -983,7 +983,7 @@ describeWithDOM('mount', () => { }); it('should merge newProps with oldProps', () => { - const Foo = (props) => ( + const Foo = props => ( ); const Bar = () => ( @@ -1544,7 +1544,7 @@ describeWithDOM('mount', () => { describeIf(!REACT013, 'stateless function components', () => { it('should handle nodes with mapped children', () => { - const Foo = (props) => ( + const Foo = props => (
{props.items.map(x => x)}
); matchesRender(); @@ -1809,7 +1809,7 @@ describeWithDOM('mount', () => { describeIf(!REACT013, 'stateless function components', () => { it('should handle mixed children with and without arrays', () => { - const Foo = (props) => ( + const Foo = props => (
{props.items.map(x => x)} diff --git a/test/ShallowWrapper-spec.jsx b/test/ShallowWrapper-spec.jsx index e1d34a195..3c6c8203e 100644 --- a/test/ShallowWrapper-spec.jsx +++ b/test/ShallowWrapper-spec.jsx @@ -825,7 +825,7 @@ describe('shallow', () => { describeIf(!REACT013, 'stateless function components', () => { it('should set props for a component multiple times', () => { - const Foo = (props) => ( + const Foo = props => (
{props.id}
@@ -838,7 +838,7 @@ describe('shallow', () => { }); it('should merge newProps with oldProps', () => { - const Foo = (props) => ( + const Foo = props => ( ); const Bar = () => ( @@ -981,7 +981,7 @@ describe('shallow', () => { describeIf(!REACT013, 'stateless function components', () => { it('should simulate events', () => { const spy = sinon.spy(); - const Foo = (props) => ( + const Foo = props => ( foo ); @@ -1076,7 +1076,7 @@ describe('shallow', () => { this.setState({ count: this.state.count + 1 }); } render() { - ++renderCount; + renderCount += 1; return ( {this.state.count} ); @@ -1363,7 +1363,7 @@ describe('shallow', () => { describeIf(!REACT013, 'stateless function components', () => { it('should handle nodes with mapped children', () => { - const Foo = (props) => ( + const Foo = props => (
{props.items.map(x => x)}
@@ -1657,7 +1657,7 @@ describe('shallow', () => { describeIf(!REACT013, 'stateless function components', () => { it('should handle mixed children with and without arrays', () => { - const Foo = (props) => ( + const Foo = props => (
{props.items.map(x => x)} diff --git a/test/Utils-spec.jsx b/test/Utils-spec.jsx index 808ad355b..c8bcd84dc 100644 --- a/test/Utils-spec.jsx +++ b/test/Utils-spec.jsx @@ -201,8 +201,8 @@ describe('Utils', () => { )).to.equal(false); expect(nodeEqual( -
, -
+
child
, +
child
, )).to.equal(false); }); @@ -213,8 +213,8 @@ describe('Utils', () => { )).to.equal(false); expect(nodeEqual( -
, -
+
child
, +
other child
, )).to.equal(false); }); @@ -225,7 +225,7 @@ describe('Utils', () => { )).to.equal(true); expect(nodeEqual( -
, +
, // eslint-disable-line react/no-children-prop
)).to.equal(true); });