diff --git a/.babelrc b/.babelrc index 53f2ae9..6b7c78d 100644 --- a/.babelrc +++ b/.babelrc @@ -1,4 +1,8 @@ { - "stage": 0, - "loose": "all" + "presets": [ + ["es2015"], + ["react"], + ["stage-0"] + ], + "plugins": ["transform-decorators-legacy"] } \ No newline at end of file diff --git a/.eslintrc b/.eslintrc index 63c23d3..ef3b3b5 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,11 +1,12 @@ { - "extends": "eslint-config-airbnb", + "extends": ["eslint-config-airbnb", "prettier"], "env": { "browser": true, "mocha": true, "node": true }, "rules": { + "prettier/prettier": ["error", { "trailingComma": "es5", "singleQuote": true }], "react/jsx-uses-react": 2, "react/jsx-uses-vars": 2, "react/react-in-jsx-scope": 2, @@ -16,6 +17,7 @@ "padded-blocks": 0 }, "plugins": [ + "prettier", "react" ] } \ No newline at end of file diff --git a/package.json b/package.json index 618f28e..750bebf 100644 --- a/package.json +++ b/package.json @@ -4,14 +4,14 @@ "description": "React component and decorator for prop providing and prop injection", "main": "./lib/index.js", "scripts": { - "build:lib": "babel src --out-dir lib", + "build:lib": "babel src --source-maps --out-dir lib", "build:umd": "webpack src/index.js dist/react-tunnel.js --config webpack.config.development.js", "build:umd:min": "webpack src/index.js dist/react-tunnel.min.js --config webpack.config.production.js", "build": "npm run build:lib && npm run build:umd && npm run build:umd:min", "clean": "rimraf lib dist coverage", - "lint": "eslint src test", + "lint": "eslint src test --fix", "prepublish": "npm run clean && npm run build", - "test": "mocha --compilers js:babel/register --recursive", + "test": "mocha --compilers js:babel-core/register --recursive", "test:watch": "npm test -- --watch", "test:cov": "babel-node ./node_modules/isparta/bin/isparta cover ./node_modules/mocha/bin/_mocha -- --recursive" }, @@ -35,21 +35,31 @@ }, "homepage": "https://github.com/gnoff/react-tunnel", "devDependencies": { - "babel": "5.x.x", - "babel-core": "5.x.x", - "babel-eslint": "4.x.x", - "babel-loader": "5.x.x", - "eslint": "1.x.x", - "eslint-config-airbnb": "0.0.7", - "eslint-plugin-react": "3.x.x", - "expect": "1.x.x", + "babel-cli": "^6.26.0", + "babel-core": "^6.26.0", + "babel-eslint": "^4.1.8", + "babel-loader": "7.1.1", + "babel-plugin-transform-decorators-legacy": "^1.3.4", + "babel-preset-es2015": "^6.24.1", + "babel-preset-react": "^6.24.1", + "babel-preset-stage-0": "^6.24.1", + "eslint": "^4.12.1", + "eslint-config-airbnb": "^16.1.0", + "eslint-config-prettier": "^2.9.0", + "eslint-plugin-import": "^2.8.0", + "eslint-plugin-jsx-a11y": "^6.0.2", + "eslint-plugin-prettier": "^2.3.1", + "eslint-plugin-react": "^7.5.1", "exenv": "1.x.x", + "expect": "1.x.x", "isparta": "3.x.x", "istanbul": "0.3.x", "jsdom": "6.x.x", "mocha": "2.x.x", "mocha-jsdom": "1.x.x", - "react": "0.14.x", + "prettier": "^1.8.2", + "react": "16.2.0", + "react-dom": "16.2.0", "rimraf": "2.x.x", "webpack": "1.x.x", "webpack-dev-server": "1.x.x" diff --git a/src/components/createAll.js b/src/components/createAll.js index 763e331..b00432c 100644 --- a/src/components/createAll.js +++ b/src/components/createAll.js @@ -6,4 +6,4 @@ export default function createAll(React) { const inject = createInject(React); return { Provider, inject }; -} \ No newline at end of file +} diff --git a/src/utils/hasEmptyIntersection.js b/src/utils/hasEmptyIntersection.js index 9f33431..ddf4dc1 100644 --- a/src/utils/hasEmptyIntersection.js +++ b/src/utils/hasEmptyIntersection.js @@ -14,7 +14,7 @@ export default function hasEmptyIntersection(objA, objB) { return false; } - const objCombined = {...objA, ...objB}; + const objCombined = { ...objA, ...objB }; const keysCombined = Object.keys(objCombined); if (keysA.length + keysB.length === keysCombined.length) { @@ -22,4 +22,4 @@ export default function hasEmptyIntersection(objA, objB) { } return false; -} \ No newline at end of file +} diff --git a/src/utils/isPlainObject.js b/src/utils/isPlainObject.js index c7323a3..383c783 100644 --- a/src/utils/isPlainObject.js +++ b/src/utils/isPlainObject.js @@ -2,7 +2,7 @@ * copied from https://github.com/gaearon/react-redux/blob/master/src/utils/isPlainObject.js authored by @gaearon */ -const fnToString = (fn) => Function.prototype.toString.call(fn); +const fnToString = fn => Function.prototype.toString.call(fn); /** * @param {any} obj The object to inspect. @@ -13,9 +13,10 @@ export default function isPlainObject(obj) { return false; } - const proto = typeof obj.constructor === 'function' ? - Object.getPrototypeOf(obj) : - Object.prototype; + const proto = + typeof obj.constructor === 'function' + ? Object.getPrototypeOf(obj) + : Object.prototype; if (proto === null) { return true; @@ -23,7 +24,9 @@ export default function isPlainObject(obj) { const constructor = proto.constructor; - return typeof constructor === 'function' - && constructor instanceof constructor - && fnToString(constructor) === fnToString(Object); -} \ No newline at end of file + return ( + typeof constructor === 'function' && + constructor instanceof constructor && + fnToString(constructor) === fnToString(Object) + ); +} diff --git a/src/utils/shallowEqual.js b/src/utils/shallowEqual.js index 8383692..1ed889a 100644 --- a/src/utils/shallowEqual.js +++ b/src/utils/shallowEqual.js @@ -17,8 +17,7 @@ export default function shallowEqual(objA, objB) { // Test for A's keys different from B. const hasOwn = Object.prototype.hasOwnProperty; for (let i = 0; i < keysA.length; i++) { - if (!hasOwn.call(objB, keysA[i]) || - objA[keysA[i]] !== objB[keysA[i]]) { + if (!hasOwn.call(objB, keysA[i]) || objA[keysA[i]] !== objB[keysA[i]]) { return false; } } diff --git a/src/utils/sharedKeys.js b/src/utils/sharedKeys.js index fdc3241..7791e29 100644 --- a/src/utils/sharedKeys.js +++ b/src/utils/sharedKeys.js @@ -1,5 +1,4 @@ export default function sharedKeys(objA, objB) { - if (!objA || !objB) { return []; } @@ -15,10 +14,10 @@ export default function sharedKeys(objA, objB) { return keysA; } - let sharedKeys = []; + const sharedKeys = []; const hasOwn = Object.prototype.hasOwnProperty; - for (let keyA of keysA) { + for (const keyA of keysA) { if (hasOwn.call(objB, keyA)) { sharedKeys.push(keyA); } diff --git a/test/components/Provider.spec.js b/test/components/Provider.spec.js index 8f10d9f..ca50d92 100644 --- a/test/components/Provider.spec.js +++ b/test/components/Provider.spec.js @@ -1,9 +1,10 @@ import expect from 'expect'; import jsdomReact from './jsdomReact'; -import React, { PropTypes, Component } from 'react/addons'; +import React, { Component } from 'react'; import { Provider } from '../../src/index'; +import PropTypes from 'prop-types'; -const { TestUtils } = React.addons; +import TestUtils from 'react-dom/test-utils'; describe('React', () => { describe('Provider', () => { diff --git a/test/components/inject.spec.js b/test/components/inject.spec.js index 0597da6..683c037 100644 --- a/test/components/inject.spec.js +++ b/test/components/inject.spec.js @@ -1,9 +1,10 @@ import expect from 'expect'; import jsdomReact from './jsdomReact'; -import React, { PropTypes, Component, Children} from 'react/addons'; +import React, { Component, Children} from 'react'; +import PropTypes from 'prop-types'; import { inject } from '../../src/index'; -const { TestUtils } = React.addons; +import TestUtils from 'react-dom/test-utils'; describe('React', () => { describe('inject', () => { diff --git a/test/components/jsdomReact.js b/test/components/jsdomReact.js index e7a475e..ccd23fc 100644 --- a/test/components/jsdomReact.js +++ b/test/components/jsdomReact.js @@ -4,4 +4,4 @@ import jsdom from 'mocha-jsdom'; export default function jsdomReact() { jsdom(); ExecutionEnvironment.canUseDOM = true; -} \ No newline at end of file +} diff --git a/test/utils/hasEmptyIntersection.spec.js b/test/utils/hasEmptyIntersection.spec.js index 6d86e13..0d02fe5 100644 --- a/test/utils/hasEmptyIntersection.spec.js +++ b/test/utils/hasEmptyIntersection.spec.js @@ -5,81 +5,47 @@ describe('Utils', () => { describe('hasEmptyIntersection', () => { it('should return true if one or the other object is empty, null, or undefined', () => { expect( - hasEmptyIntersection( - {}, - { a: 1, b: undefined, c: {}, d: 'd' } - ) + hasEmptyIntersection({}, { a: 1, b: undefined, c: {}, d: 'd' }) ).toBe(true); expect( - hasEmptyIntersection( - { a: 1, b: undefined, c: {}, d: 'd' }, - {} - ) + hasEmptyIntersection({ a: 1, b: undefined, c: {}, d: 'd' }, {}) ).toBe(true); expect( - hasEmptyIntersection( - null, - { a: 1, b: undefined, c: {}, d: 'd' } - ) + hasEmptyIntersection(null, { a: 1, b: undefined, c: {}, d: 'd' }) ).toBe(true); expect( - hasEmptyIntersection( - { a: 1, b: undefined, c: {}, d: 'd' }, - null - ) + hasEmptyIntersection({ a: 1, b: undefined, c: {}, d: 'd' }, null) ).toBe(true); expect( - hasEmptyIntersection( - undefined, - { a: 1, b: undefined, c: {}, d: 'd' } - ) + hasEmptyIntersection(undefined, { a: 1, b: undefined, c: {}, d: 'd' }) ).toBe(true); expect( - hasEmptyIntersection( - { a: 1, b: undefined, c: {}, d: 'd' }, - undefined - ) + hasEmptyIntersection({ a: 1, b: undefined, c: {}, d: 'd' }, undefined) ).toBe(true); }); it('should return false if the arguments are the same non-empty object', () => { const emptyObj = {}; const fullObj = { a: 1 }; - expect( - hasEmptyIntersection( - emptyObj, - emptyObj - ) - ).toBe(true); + expect(hasEmptyIntersection(emptyObj, emptyObj)).toBe(true); - expect( - hasEmptyIntersection( - fullObj, - fullObj - ) - ).toBe(false); + expect(hasEmptyIntersection(fullObj, fullObj)).toBe(false); }); it('should return false if objects are different but have the same keys', () => { expect( - hasEmptyIntersection( - { a: 1, b: 2, c: 3 }, - { a: 'a', b: 'b', c: 'c' } - ) + hasEmptyIntersection({ a: 1, b: 2, c: 3 }, { a: 'a', b: 'b', c: 'c' }) ).toBe(false); }); it('should return false if objects share a single key', () => { expect( - hasEmptyIntersection( - { x: 1, y: 2, z: 3 }, - { a: 1, b: 2, c: 3 } - ) + hasEmptyIntersection({ x: 1, y: 2, z: 3 }, { a: 1, b: 2, c: 3 }) ).toBe(true); expect( @@ -90,4 +56,4 @@ describe('Utils', () => { ).toBe(false); }); }); -}); \ No newline at end of file +}); diff --git a/test/utils/isPlainObject.spec.js b/test/utils/isPlainObject.spec.js index ed6ffce..f27288b 100644 --- a/test/utils/isPlainObject.spec.js +++ b/test/utils/isPlainObject.spec.js @@ -17,7 +17,7 @@ describe('Utils', () => { expect(isPlainObject([1, 2, 3])).toBe(false); expect(isPlainObject(null)).toBe(false); expect(isPlainObject()).toBe(false); - expect(isPlainObject({ 'x': 1, 'y': 2 })).toBe(true); + expect(isPlainObject({ x: 1, y: 2 })).toBe(true); }); }); -}); \ No newline at end of file +}); diff --git a/test/utils/shallowEqual.spec.js b/test/utils/shallowEqual.spec.js index 9143a37..a225af4 100644 --- a/test/utils/shallowEqual.spec.js +++ b/test/utils/shallowEqual.spec.js @@ -9,44 +9,25 @@ describe('Utils', () => { describe('shallowEqual', () => { it('should return true if arguments fields are equal', () => { expect( - shallowEqual( - { a: 1, b: 2, c: undefined }, - { a: 1, b: 2, c: undefined } - ) + shallowEqual({ a: 1, b: 2, c: undefined }, { a: 1, b: 2, c: undefined }) ).toBe(true); - expect( - shallowEqual( - { a: 1, b: 2, c: 3 }, - { a: 1, b: 2, c: 3 } - ) - ).toBe(true); + expect(shallowEqual({ a: 1, b: 2, c: 3 }, { a: 1, b: 2, c: 3 })).toBe( + true + ); const o = {}; - expect( - shallowEqual( - { a: 1, b: 2, c: o }, - { a: 1, b: 2, c: o } - ) - ).toBe(true); + expect(shallowEqual({ a: 1, b: 2, c: o }, { a: 1, b: 2, c: o })).toBe( + true + ); }); it('should return false if first argument has too many keys', () => { - expect( - shallowEqual( - { a: 1, b: 2, c: 3 }, - { a: 1, b: 2 } - ) - ).toBe(false); + expect(shallowEqual({ a: 1, b: 2, c: 3 }, { a: 1, b: 2 })).toBe(false); }); it('should return false if second argument has too many keys', () => { - expect( - shallowEqual( - { a: 1, b: 2 }, - { a: 1, b: 2, c: 3 } - ) - ).toBe(false); + expect(shallowEqual({ a: 1, b: 2 }, { a: 1, b: 2, c: 3 })).toBe(false); }); it('should return false if arguments have different keys', () => { @@ -58,4 +39,4 @@ describe('Utils', () => { ).toBe(false); }); }); -}); \ No newline at end of file +}); diff --git a/test/utils/sharedKeys.spec.js b/test/utils/sharedKeys.spec.js index effb37f..2d62403 100644 --- a/test/utils/sharedKeys.spec.js +++ b/test/utils/sharedKeys.spec.js @@ -4,107 +4,59 @@ import sharedKeys from '../../src/utils/sharedKeys'; describe('Utils', () => { describe('sharedKeys', () => { it('should return an empty Array if one or the other object is empty, null, or undefined', () => { - expect( - sharedKeys( - {}, - { a: 1, b: undefined, c: {}, d: 'd' } - ) - ).toEqual([]); + expect(sharedKeys({}, { a: 1, b: undefined, c: {}, d: 'd' })).toEqual([]); - expect( - sharedKeys( - { a: 1, b: undefined, c: {}, d: 'd' }, - {} - ) - ).toEqual([]); + expect(sharedKeys({ a: 1, b: undefined, c: {}, d: 'd' }, {})).toEqual([]); - expect( - sharedKeys( - null, - { a: 1, b: undefined, c: {}, d: 'd' } - ) - ).toEqual([]); + expect(sharedKeys(null, { a: 1, b: undefined, c: {}, d: 'd' })).toEqual( + [] + ); - expect( - sharedKeys( - { a: 1, b: undefined, c: {}, d: 'd' }, - null - ) - ).toEqual([]); + expect(sharedKeys({ a: 1, b: undefined, c: {}, d: 'd' }, null)).toEqual( + [] + ); expect( - sharedKeys( - undefined, - { a: 1, b: undefined, c: {}, d: 'd' } - ) + sharedKeys(undefined, { a: 1, b: undefined, c: {}, d: 'd' }) ).toEqual([]); expect( - sharedKeys( - { a: 1, b: undefined, c: {}, d: 'd' }, - undefined - ) + sharedKeys({ a: 1, b: undefined, c: {}, d: 'd' }, undefined) ).toEqual([]); }); it('should return equivalent of Object.keys if the arguments are the same non-empty object', () => { const emptyObj = {}; const fullObj = { a: 1 }; - expect( - sharedKeys( - emptyObj, - emptyObj - ) - ).toEqual(Object.keys(emptyObj)); + expect(sharedKeys(emptyObj, emptyObj)).toEqual(Object.keys(emptyObj)); - expect( - sharedKeys( - fullObj, - fullObj - ) - ).toEqual(Object.keys(fullObj)); + expect(sharedKeys(fullObj, fullObj)).toEqual(Object.keys(fullObj)); }); it('should return equivalent of Object.keys of either argument if objects are different but have the same keys', () => { const objA = { a: 1, b: 2, c: 3 }; const objB = { a: 'a', b: 'b', c: 'c' }; - expect( - sharedKeys( - objA, - objB - ) - ).toEqual(Object.keys(objA)); + expect(sharedKeys(objA, objB)).toEqual(Object.keys(objA)); - expect( - sharedKeys( - objA, - objB - ) - ).toEqual(Object.keys(objB)); + expect(sharedKeys(objA, objB)).toEqual(Object.keys(objB)); }); it('should return array containing all keys found in both objects', () => { - expect( - sharedKeys( - { x: 1, y: 2, z: 3 }, - { a: 1, b: 2, c: 3 } - ) - ).toEqual([]); + expect(sharedKeys({ x: 1, y: 2, z: 3 }, { a: 1, b: 2, c: 3 })).toEqual( + [] + ); expect( - sharedKeys( - { x: 1, y: 4, z: 3, b: 'blah' }, - { a: 1, b: 2, c: 3 } - ) + sharedKeys({ x: 1, y: 4, z: 3, b: 'blah' }, { a: 1, b: 2, c: 3 }) ).toEqual(['b']); expect( sharedKeys( { x: 1, y: 4, z: 3, b: 'blah' }, - { a: 1, b: 2, c: 3, y: 'z', x: 'b'} + { a: 1, b: 2, c: 3, y: 'z', x: 'b' } ).sort() ).toEqual(['b', 'x', 'y'].sort()); }); }); -}); \ No newline at end of file +});