From 11351925462bdc97686ff4faa80b2d9d4e32312e Mon Sep 17 00:00:00 2001 From: Mariusz Nowak Date: Wed, 29 May 2019 13:22:38 +0200 Subject: [PATCH 1/6] Ensure ESLint treats modules as CJS not ESM --- .eslintrc.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.eslintrc.js b/.eslintrc.js index 9eecfdb9f..5c9183b4c 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -12,6 +12,9 @@ module.exports = { "react/require-extension": "off", "import/no-extraneous-dependencies": "off" }, + "parserOptions": { + "sourceType": "script", // Override ESM implied by airbnb + }, "env": { "mocha": true, "jest": true From d8288d057c12d0fd595b074a1b16ccc0ccc2f60d Mon Sep 17 00:00:00 2001 From: Mariusz Nowak Date: Wed, 29 May 2019 13:34:27 +0200 Subject: [PATCH 2/6] Fix eslint configuration of 'strict' option --- .eslintrc.js | 2 +- lib/plugins/aws/lib/getServiceState.js | 2 ++ lib/utils/fs/readFileIfExists.js | 2 ++ lib/utils/renameService.js | 2 ++ lib/utils/sentry.js | 2 ++ tests/setupTests.js | 2 ++ 6 files changed, 11 insertions(+), 1 deletion(-) diff --git a/.eslintrc.js b/.eslintrc.js index 5c9183b4c..7bdf7dda3 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -5,9 +5,9 @@ module.exports = { "rules": { "func-names": "off", "global-require": "off", // Interfers with optional and eventual circular references + "strict": ["error", "safe"], // doesn't work in node v4 :( - "strict": "off", "prefer-rest-params": "off", "react/require-extension": "off", "import/no-extraneous-dependencies": "off" diff --git a/lib/plugins/aws/lib/getServiceState.js b/lib/plugins/aws/lib/getServiceState.js index 0feefd37a..fe5b95b01 100644 --- a/lib/plugins/aws/lib/getServiceState.js +++ b/lib/plugins/aws/lib/getServiceState.js @@ -1,3 +1,5 @@ +'use strict'; + const path = require('path'); module.exports = { diff --git a/lib/utils/fs/readFileIfExists.js b/lib/utils/fs/readFileIfExists.js index 4876033db..9c7fdd70e 100644 --- a/lib/utils/fs/readFileIfExists.js +++ b/lib/utils/fs/readFileIfExists.js @@ -1,3 +1,5 @@ +'use strict'; + const fileExists = require('./fileExists'); const readFile = require('./readFile'); const BbPromise = require('bluebird'); diff --git a/lib/utils/renameService.js b/lib/utils/renameService.js index ecb853c07..69dbd4fcf 100644 --- a/lib/utils/renameService.js +++ b/lib/utils/renameService.js @@ -1,3 +1,5 @@ +'use strict'; + const path = require('path'); const fse = require('fs-extra'); diff --git a/lib/utils/sentry.js b/lib/utils/sentry.js index 651a9302f..1a01325dc 100644 --- a/lib/utils/sentry.js +++ b/lib/utils/sentry.js @@ -1,3 +1,5 @@ +'use strict'; + const raven = require('raven'); const ci = require('ci-info'); const configUtils = require('./config'); diff --git a/tests/setupTests.js b/tests/setupTests.js index 4da8b0798..01313fd46 100644 --- a/tests/setupTests.js +++ b/tests/setupTests.js @@ -1,3 +1,5 @@ +'use strict'; + // timeout is set to 5 minutes // eslint-disable-next-line no-undef jasmine.DEFAULT_TIMEOUT_INTERVAL = 300000; From 1608de249103fb4b7089752e067f99c050bebdd6 Mon Sep 17 00:00:00 2001 From: Mariusz Nowak Date: Wed, 29 May 2019 13:39:54 +0200 Subject: [PATCH 3/6] Turn on prefer-rest-params eslint rule --- .eslintrc.js | 3 +-- lib/utils/log/consoleLog.js | 4 ++-- lib/utils/log/fileLog.js | 5 ++--- lib/utils/log/log.js | 4 ++-- lib/utils/userStats.js | 4 ++-- 5 files changed, 9 insertions(+), 11 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 7bdf7dda3..da195d61f 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -5,10 +5,9 @@ module.exports = { "rules": { "func-names": "off", "global-require": "off", // Interfers with optional and eventual circular references - "strict": ["error", "safe"], + "strict": ["error", "safe"], // airbnb implies we're transpiling with babel, we're not // doesn't work in node v4 :( - "prefer-rest-params": "off", "react/require-extension": "off", "import/no-extraneous-dependencies": "off" }, diff --git a/lib/utils/log/consoleLog.js b/lib/utils/log/consoleLog.js index 2ba6c7017..4bbe99661 100644 --- a/lib/utils/log/consoleLog.js +++ b/lib/utils/log/consoleLog.js @@ -1,7 +1,7 @@ 'use strict'; -const consoleLog = function () { - console.log(arguments); // eslint-disable-line no-console +const consoleLog = function (...args) { + console.log(args); // eslint-disable-line no-console }; module.exports = consoleLog; diff --git a/lib/utils/log/fileLog.js b/lib/utils/log/fileLog.js index b8dd3549f..4b2c1f070 100644 --- a/lib/utils/log/fileLog.js +++ b/lib/utils/log/fileLog.js @@ -4,11 +4,10 @@ const _ = require('lodash'); const fs = require('fs'); const path = require('path'); -const fileLog = function () { +const fileLog = function (...args) { // TODO BRN: This does not guarentee order, is not multi process safe, // TODO BRN: and is not guarenteed to complete before exit. - fs.appendFileSync(path.join(process.cwd(), 'sls.log'), - _.join(Array.prototype.slice.call(arguments)) + '\n'); // eslint-disable-line prefer-template + fs.appendFileSync(path.join(process.cwd(), 'sls.log'), `${_.join(args)}\n`); }; module.exports = fileLog; diff --git a/lib/utils/log/log.js b/lib/utils/log/log.js index aa59e55ce..c9561f026 100644 --- a/lib/utils/log/log.js +++ b/lib/utils/log/log.js @@ -9,8 +9,8 @@ const loggers = [ fileLog, ]; -const log = function () { - _.each(loggers, (logger) => logger.apply(null, arguments)); // eslint-disable-line prefer-spread +const log = function (...args) { + _.each(loggers, (logger) => logger(...args)); }; module.exports = log; diff --git a/lib/utils/userStats.js b/lib/utils/userStats.js index 435d6a7f9..7700a9b75 100644 --- a/lib/utils/userStats.js +++ b/lib/utils/userStats.js @@ -13,8 +13,8 @@ const TRACK_URL = 'https://serverless.com/api/framework/track'; const IDENTIFY_URL = 'https://serverless.com/api/framework/identify'; const DEBUG = false; -function debug() { - if (DEBUG) console.log(arguments); +function debug(...args) { + if (DEBUG) console.log(args); } /* note tracking swallows errors */ From e4f1b5707ef6e8715c5cf42c9f07e02bd4aa48d9 Mon Sep 17 00:00:00 2001 From: Mariusz Nowak Date: Wed, 29 May 2019 13:52:22 +0200 Subject: [PATCH 4/6] Improve explanation --- .eslintrc.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.eslintrc.js b/.eslintrc.js index da195d61f..2eb9d17db 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -12,7 +12,7 @@ module.exports = { "import/no-extraneous-dependencies": "off" }, "parserOptions": { - "sourceType": "script", // Override ESM implied by airbnb + "sourceType": "script", // airbnb assumes ESM, while we're CJS }, "env": { "mocha": true, From 7d96e1e0caaa9e7048bbb821b51478222fd1700a Mon Sep 17 00:00:00 2001 From: Mariusz Nowak Date: Wed, 29 May 2019 13:53:16 +0200 Subject: [PATCH 5/6] Document disabling of rule --- .eslintrc.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.eslintrc.js b/.eslintrc.js index 2eb9d17db..ed670cf65 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -5,10 +5,10 @@ module.exports = { "rules": { "func-names": "off", "global-require": "off", // Interfers with optional and eventual circular references + "react/require-extension": "off", // Forced by airbnb, not applicable (also deprecated) "strict": ["error", "safe"], // airbnb implies we're transpiling with babel, we're not // doesn't work in node v4 :( - "react/require-extension": "off", "import/no-extraneous-dependencies": "off" }, "parserOptions": { From 8182e9e0c848f8c06013f9c4cae0f2121dd53da0 Mon Sep 17 00:00:00 2001 From: Mariusz Nowak Date: Wed, 29 May 2019 13:58:24 +0200 Subject: [PATCH 6/6] Configure "import/no-extraneous-dependencies" rule --- .eslintrc.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index ed670cf65..60abf1402 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -5,11 +5,9 @@ module.exports = { "rules": { "func-names": "off", "global-require": "off", // Interfers with optional and eventual circular references + "import/no-extraneous-dependencies": ["error", {"devDependencies": ["**/*.test.js", "**/scripts/**", "**/tests/**"]}], "react/require-extension": "off", // Forced by airbnb, not applicable (also deprecated) "strict": ["error", "safe"], // airbnb implies we're transpiling with babel, we're not - - // doesn't work in node v4 :( - "import/no-extraneous-dependencies": "off" }, "parserOptions": { "sourceType": "script", // airbnb assumes ESM, while we're CJS