Skip to content

Commit

Permalink
Change prettier/eslint
Browse files Browse the repository at this point in the history
- add prettier
- update eslint
  • Loading branch information
dozoisch committed Aug 16, 2018
1 parent 2ffe5e6 commit d7e6d71
Show file tree
Hide file tree
Showing 8 changed files with 175 additions and 127 deletions.
37 changes: 0 additions & 37 deletions .eslintrc

This file was deleted.

19 changes: 19 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"use strict";
module.exports = {
extends: ["eslint:recommended", "prettier", "prettier/react"],
parserOptions: {
sourceType: "module",
ecmaVersion: "2018",
ecmaFeatures: {
jsx: true,
},
},
env: {
es6: true,
browser: true,
},
plugins: ["prettier"],
rules: {
"prettier/prettier": "error",
},
};
28 changes: 11 additions & 17 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,32 @@
/* eslint no-var: 0, strict: [2, "global"] */
/* eslint-env node */
"use strict";
require("babel-register");

var webpackConfig = require("./webpack.config.test.js");
var isCI = process.env.CONTINUOUS_INTEGRATION === "true";
const webpackConfig = require("./webpack.config.test.js");
const isCI = process.env.CONTINUOUS_INTEGRATION === "true";

module.exports = function (config) {
module.exports = function(config) {
config.set({

basePath: "",

frameworks: [
"mocha",
"chai",
],
frameworks: ["mocha", "chai"],

files: [
"test/index.js",
],
files: ["test/index.js"],

preprocessors: {
"test/index.js": ["webpack", "sourcemap"],
"test/index.js": ["webpack", "sourcemap"]
},

webpack: webpackConfig,

webpackMiddleware: {
noInfo: isCI,
noInfo: isCI
},

reporters: ["mocha"],

mochaReporter: {
output: "autowatch",
output: "autowatch"
},

port: 9876,
Expand All @@ -43,11 +37,11 @@ module.exports = function (config) {

autoWatch: true,

browsers: [ isCI ? "PhantomJS" : "Chrome" ],
browsers: [isCI ? "PhantomJS" : "Chrome"],

captureTimeout: 60000,
browserNoActivityTimeout: 30000,

singleRun: isCI,
singleRun: isCI
});
};
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
"scripts": {
"build": "rm -rf lib && babel src --out-dir lib",
"lint": "eslint ./",
"pretty": "prettier --write src/*.js ./*.js test/*.js",
"test": "karma start --single-run",
"test-watch": "karma start",
"prepublish": "npm run build"
"prepare": "npm run build"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -39,9 +40,9 @@
"chai": "^3.5.0",
"es5-shim": "~4.1.3",
"es6-shim": "^0.35.3",
"eslint": "~1.6.0",
"eslint-config-defaults": "~7.0.1",
"eslint-plugin-react": "~3.5.1",
"eslint": "^5.3.0",
"eslint-config-prettier": "^3.0.1",
"eslint-plugin-prettier": "^2.6.2",
"karma": "~0.13.9",
"karma-chai": "~0.1.0",
"karma-chrome-launcher": "~0.2.0",
Expand All @@ -53,6 +54,7 @@
"karma-webpack": "~1.7.0",
"mocha": "~2.3.3",
"phantomjs": "^2.0.0",
"prettier": "^1.14.2",
"react": "^16.4.2",
"react-dom": "^16.4.2",
"react-is": "^16.4.2",
Expand Down
22 changes: 13 additions & 9 deletions src/async-script-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default function makeAsyncScript(getScriptURL, options) {

class AsyncScriptLoader extends Component {
constructor(props, context) {
super(props, context)
super(props, context);
this.state = {};
this.__scriptURL = "";
}
Expand All @@ -35,8 +35,11 @@ export default function makeAsyncScript(getScriptURL, options) {

asyncScriptLoaderHandleLoad(state) {
// use reacts setState callback to fire props.asyncScriptOnLoad with new state/entry
this.setState(state,
() => this.props.asyncScriptOnLoad && this.props.asyncScriptOnLoad(this.state)
this.setState(
state,
() =>
this.props.asyncScriptOnLoad &&
this.props.asyncScriptOnLoad(this.state)
);
}

Expand Down Expand Up @@ -70,7 +73,8 @@ export default function makeAsyncScript(getScriptURL, options) {
return;
}
// if still loading then callback to observer queue
entry.observers[key] = entry => this.asyncScriptLoaderHandleLoad(entry);
entry.observers[key] = entry =>
this.asyncScriptLoaderHandleLoad(entry);
return;
}

Expand All @@ -83,7 +87,7 @@ export default function makeAsyncScript(getScriptURL, options) {
observers[key] = entry => this.asyncScriptLoaderHandleLoad(entry);
SCRIPT_MAP[scriptURL] = {
loaded: false,
observers,
observers
};

let script = document.createElement("script");
Expand Down Expand Up @@ -122,7 +126,7 @@ export default function makeAsyncScript(getScriptURL, options) {
});
}
};
script.onerror = event => {
script.onerror = () => {
let mapEntry = SCRIPT_MAP[scriptURL];
if (mapEntry) {
mapEntry.errored = true;
Expand Down Expand Up @@ -178,13 +182,13 @@ export default function makeAsyncScript(getScriptURL, options) {
// We can pass it along to AsyncScriptLoader as a regular prop, e.g. "forwardedRef"
// And it can then be attached to the Component.
const ForwardedComponent = forwardRef((props, ref) => {
return createElement(AsyncScriptLoader, {...props, forwardedRef: ref });
return createElement(AsyncScriptLoader, { ...props, forwardedRef: ref });
});
ForwardedComponent.displayName = `AsyncScriptLoader(${wrappedComponentName})`;
ForwardedComponent.propTypes = {
asyncScriptOnLoad: PropTypes.func,
asyncScriptOnLoad: PropTypes.func
};

return hoistStatics(ForwardedComponent, WrappedComponent);
}
};
}
8 changes: 2 additions & 6 deletions test/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
{
"env": {
"mocha": true
"mocha": true,
"node": true
},
"globals": {
"assert": true
},
"rules": {
"no-script-url": 1,
"no-unused-expressions": 0,
"react/no-multi-comp": 0
}
}
Loading

0 comments on commit d7e6d71

Please sign in to comment.