From 5c3dd99976c1a6f8f693f54619b1ff6a883fd01a Mon Sep 17 00:00:00 2001 From: Gleb Bahmutov Date: Tue, 21 Nov 2017 16:36:40 -0500 Subject: [PATCH 1/5] using prettier-eslint --- index.js | 30 +++++++++++++++++++----------- package.json | 3 ++- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/index.js b/index.js index 2a73b9b..08a79e5 100644 --- a/index.js +++ b/index.js @@ -17,10 +17,7 @@ const defaultOptions = { browserifyOptions: { extensions: ['.js', '.jsx', '.coffee', '.cjsx'], transform: [ - [ - require.resolve('./cjsxify'), - {}, - ], + [require.resolve('./cjsxify'), {}], [ require.resolve('babelify'), { @@ -30,7 +27,9 @@ const defaultOptions = { plugins: ['babel-plugin-add-module-exports'].map(require.resolve), // babel-preset-env supports any JS that's stage-4, meaning it's // completely finalized in the ECMA standard - presets: ['babel-preset-env', 'babel-preset-react'].map(require.resolve), + presets: ['babel-preset-env', 'babel-preset-react'].map( + require.resolve + ), }, ], ], @@ -61,8 +60,16 @@ const preprocessor = (options = {}) => { log('received user options', options) // allow user to override default options - const browserifyOptions = Object.assign({}, defaultOptions.browserifyOptions, options.browserifyOptions) - const watchifyOptions = Object.assign({}, defaultOptions.watchifyOptions, options.watchifyOptions) + const browserifyOptions = Object.assign( + {}, + defaultOptions.browserifyOptions, + options.browserifyOptions + ) + const watchifyOptions = Object.assign( + {}, + defaultOptions.watchifyOptions, + options.watchifyOptions + ) // we return function that accepts the arguments provided by // the event 'file:preprocessor' @@ -152,18 +159,19 @@ const preprocessor = (options = {}) => { log(`update ${filePath}`) // we overwrite the cached bundle promise, so on subsequent invocations // it gets the latest bundle - const bundlePromise = bundles[filePath] = bundle() - .finally(() => { + const bundlePromise = (bundles[filePath] = bundle().finally(() => { log(`- update finished for ${filePath}`) file.emit('rerun') - }) + })) // we suppress unhandled rejections so they don't bubble up to the // unhandledRejection handler and crash the app. Cypress will eventually // take care of the rejection when the file is requested bundlePromise.suppressUnhandledRejections() }) - const bundlePromise = fs.ensureDirAsync(path.dirname(outputPath)).then(bundle) + const bundlePromise = fs + .ensureDirAsync(path.dirname(outputPath)) + .then(bundle) // cache the bundle promise, so it can be returned if this function // is invoked again with the same filePath diff --git a/package.json b/package.json index 08721c3..4852b42 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "ban": "ban", "deps": "deps-ok && dependency-check --no-dev .", "license": "license-checker --production --onlyunknown --csv", - "lint": "eslint --fix *.js", + "lint": "prettier-eslint --trailing-comma es5 --no-semi --single-quote --write '*.js'", "secure": "nsp check", "size": "t=\"$(npm pack .)\"; wc -c \"${t}\"; tar tvf \"${t}\"; rm \"${t}\";", "test": "mocha", @@ -50,6 +50,7 @@ "mocha": "3.5.0", "mockery": "2.1.0", "nsp": "2.7.0", + "prettier-eslint-cli": "4.4.0", "semantic-release": "8.2.0", "simple-commit-message": "3.3.1", "sinon": "3.2.1", From cbe8481390932f1aa38d2385dfec4b1b1faf44fd Mon Sep 17 00:00:00 2001 From: Gleb Bahmutov Date: Tue, 21 Nov 2017 16:42:04 -0500 Subject: [PATCH 2/5] remove duplicate options --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4852b42..e1a5905 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "ban": "ban", "deps": "deps-ok && dependency-check --no-dev .", "license": "license-checker --production --onlyunknown --csv", - "lint": "prettier-eslint --trailing-comma es5 --no-semi --single-quote --write '*.js'", + "lint": "prettier-eslint --no-semi --write '*.js'", "secure": "nsp check", "size": "t=\"$(npm pack .)\"; wc -c \"${t}\"; tar tvf \"${t}\"; rm \"${t}\";", "test": "mocha", From 340c11473cacc5f3fb1a8b1afb0a95e82f918fed Mon Sep 17 00:00:00 2001 From: Gleb Bahmutov Date: Wed, 22 Nov 2017 10:28:30 -0500 Subject: [PATCH 3/5] latest eslint settings --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index e1a5905..9b3506a 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "ban": "ban", "deps": "deps-ok && dependency-check --no-dev .", "license": "license-checker --production --onlyunknown --csv", - "lint": "prettier-eslint --no-semi --write '*.js'", + "lint": "prettier-eslint --write '*.js'", "secure": "nsp check", "size": "t=\"$(npm pack .)\"; wc -c \"${t}\"; tar tvf \"${t}\"; rm \"${t}\";", "test": "mocha", @@ -43,7 +43,7 @@ "deps-ok": "1.2.1", "dont-crack": "1.2.1", "eslint": "4.6.1", - "eslint-plugin-cypress-dev": "1.0.0", + "eslint-plugin-cypress-dev": "1.0.2", "eslint-plugin-mocha": "4.11.0", "github-post-release": "1.13.1", "license-checker": "13.0.3", From 77e798a4a88bd054a0d91a0c86b07402aca51cf1 Mon Sep 17 00:00:00 2001 From: Gleb Bahmutov Date: Wed, 22 Nov 2017 10:31:22 -0500 Subject: [PATCH 4/5] make code simpler to avoid wrapping in parens --- index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 08a79e5..66fbc58 100644 --- a/index.js +++ b/index.js @@ -159,10 +159,11 @@ const preprocessor = (options = {}) => { log(`update ${filePath}`) // we overwrite the cached bundle promise, so on subsequent invocations // it gets the latest bundle - const bundlePromise = (bundles[filePath] = bundle().finally(() => { + const bundlePromise = bundle().finally(() => { log(`- update finished for ${filePath}`) file.emit('rerun') - })) + }) + bundles[filePath] = bundlePromise // we suppress unhandled rejections so they don't bubble up to the // unhandledRejection handler and crash the app. Cypress will eventually // take care of the rejection when the file is requested From a91aba0c4da489cd4559d29c0a56fdae61df75fb Mon Sep 17 00:00:00 2001 From: Gleb Bahmutov Date: Wed, 22 Nov 2017 10:32:22 -0500 Subject: [PATCH 5/5] run lint before test --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 9b3506a..d6c8c5e 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "lint": "prettier-eslint --write '*.js'", "secure": "nsp check", "size": "t=\"$(npm pack .)\"; wc -c \"${t}\"; tar tvf \"${t}\"; rm \"${t}\";", + "pretest": "npm run lint", "test": "mocha", "test-debug": "node --inspect --debug-brk ./node_modules/.bin/_mocha", "test-watch": "chokidar '*.js' 'test/*.js' -c 'npm test'",