From 626c9e6535a0ea5aa4b732d795824ea1515dc563 Mon Sep 17 00:00:00 2001 From: Ben Martinez-Bateman Date: Mon, 18 Dec 2017 10:37:32 -0800 Subject: [PATCH 1/4] Build process now allows console.log, except when the `production` flag is set on `yarn build`, in which case it will throw an error. --- .eslintrcProd | 8 ++++++++ package.json | 1 + resources/assets/build/config.js | 1 + resources/assets/build/webpack.config.js | 5 ++++- 4 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 .eslintrcProd diff --git a/.eslintrcProd b/.eslintrcProd new file mode 100644 index 0000000..bcadb59 --- /dev/null +++ b/.eslintrcProd @@ -0,0 +1,8 @@ +{ + "extends": [ + "./package.json" + ], + "rules": { + "no-console": ["error"], + } +} diff --git a/package.json b/package.json index 65b3251..8eb555b 100644 --- a/package.json +++ b/package.json @@ -56,6 +56,7 @@ ] }, "rules": { + "no-console": ["off"], "comma-dangle": [ "error", { diff --git a/resources/assets/build/config.js b/resources/assets/build/config.js index 60b8098..26a3812 100644 --- a/resources/assets/build/config.js +++ b/resources/assets/build/config.js @@ -20,6 +20,7 @@ const config = merge({ root: rootPath, assets: path.join(rootPath, 'resources/assets'), dist: path.join(rootPath, 'dist'), + eslintProd: path.join(rootPath, '.eslintrcProd'), }, enabled: { sourceMaps: !isProduction, diff --git a/resources/assets/build/webpack.config.js b/resources/assets/build/webpack.config.js index d6450bb..fc71a38 100644 --- a/resources/assets/build/webpack.config.js +++ b/resources/assets/build/webpack.config.js @@ -41,7 +41,10 @@ let webpackConfig = { enforce: 'pre', test: /\.js$/, include: config.paths.assets, - use: 'eslint', + loader: 'eslint-loader', + options: { + configFile: config.env.production ? config.paths.eslintProd : null, + }, }, { enforce: 'pre', From ea2d4070aae7dfa0f2a684f61c5614abe567fa64 Mon Sep 17 00:00:00 2001 From: Ben Martinez-Bateman Date: Mon, 18 Dec 2017 10:50:49 -0800 Subject: [PATCH 2/4] Rename production eslint file from `.eslintrcProd` to `.eslint.production.json` as per suggestion from @swalkinshaw: https://github.com/roots/sage/pull/2008#issuecomment-352520506 --- .eslintrcProd => .eslintrc.production.json | 2 +- resources/assets/build/config.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename .eslintrcProd => .eslintrc.production.json (66%) diff --git a/.eslintrcProd b/.eslintrc.production.json similarity index 66% rename from .eslintrcProd rename to .eslintrc.production.json index bcadb59..f534afe 100644 --- a/.eslintrcProd +++ b/.eslintrc.production.json @@ -3,6 +3,6 @@ "./package.json" ], "rules": { - "no-console": ["error"], + "no-console": ["error"] } } diff --git a/resources/assets/build/config.js b/resources/assets/build/config.js index 26a3812..94d645b 100644 --- a/resources/assets/build/config.js +++ b/resources/assets/build/config.js @@ -20,7 +20,7 @@ const config = merge({ root: rootPath, assets: path.join(rootPath, 'resources/assets'), dist: path.join(rootPath, 'dist'), - eslintProd: path.join(rootPath, '.eslintrcProd'), + eslintProd: path.join(rootPath, '.eslintrc.production.json'), }, enabled: { sourceMaps: !isProduction, From 789eec1a57c6f56de7bfca77bcb0ad55f33a6622 Mon Sep 17 00:00:00 2001 From: Ben Martinez-Bateman Date: Mon, 18 Dec 2017 11:51:12 -0800 Subject: [PATCH 3/4] This moves our eslint config in .eslint.js, which allows us to use conditionals in the config file itself, significantly simpliying rule creation. For small-scale differences, this seems to be the simplest solution. --- .eslintrc.js | 47 ++++++++++++++++++++++++ .eslintrc.production.json | 8 ---- package.json | 47 ------------------------ resources/assets/build/webpack.config.js | 5 +-- 4 files changed, 48 insertions(+), 59 deletions(-) create mode 100644 .eslintrc.js delete mode 100644 .eslintrc.production.json diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 0000000..62168f8 --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,47 @@ +module.exports = { + "root": true, + "extends": "eslint:recommended", + "globals": { + "wp": true + }, + "env": { + "node": true, + "es6": true, + "amd": true, + "browser": true, + "jquery": true + }, + "parserOptions": { + "ecmaFeatures": { + "globalReturn": true, + "generators": false, + "objectLiteralDuplicateProperties": false, + "experimentalObjectRestSpread": true + }, + "ecmaVersion": 2017, + "sourceType": "module" + }, + "plugins": [ + "import" + ], + "settings": { + "import/core-modules": [], + "import/ignore": [ + "node_modules", + "\\.(coffee|scss|css|less|hbs|svg|json)$" + ] + }, + "rules": { + "no-console": process.env.NODE_ENV === 'production' ? 2 : 0, + "comma-dangle": [ + "error", + { + "arrays": "always-multiline", + "objects": "always-multiline", + "imports": "always-multiline", + "exports": "always-multiline", + "functions": "ignore" + } + ] + } +} diff --git a/.eslintrc.production.json b/.eslintrc.production.json deleted file mode 100644 index f534afe..0000000 --- a/.eslintrc.production.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "extends": [ - "./package.json" - ], - "rules": { - "no-console": ["error"] - } -} diff --git a/package.json b/package.json index 8eb555b..37eb388 100644 --- a/package.json +++ b/package.json @@ -22,53 +22,6 @@ "android 4", "opera 12" ], - "eslintConfig": { - "root": true, - "extends": "eslint:recommended", - "globals": { - "wp": true - }, - "env": { - "node": true, - "es6": true, - "amd": true, - "browser": true, - "jquery": true - }, - "parserOptions": { - "ecmaFeatures": { - "globalReturn": true, - "generators": false, - "objectLiteralDuplicateProperties": false, - "experimentalObjectRestSpread": true - }, - "ecmaVersion": 2017, - "sourceType": "module" - }, - "plugins": [ - "import" - ], - "settings": { - "import/core-modules": [], - "import/ignore": [ - "node_modules", - "\\.(coffee|scss|css|less|hbs|svg|json)$" - ] - }, - "rules": { - "no-console": ["off"], - "comma-dangle": [ - "error", - { - "arrays": "always-multiline", - "objects": "always-multiline", - "imports": "always-multiline", - "exports": "always-multiline", - "functions": "ignore" - } - ] - } - }, "stylelint": { "extends": "stylelint-config-standard", "rules": { diff --git a/resources/assets/build/webpack.config.js b/resources/assets/build/webpack.config.js index fc71a38..d6450bb 100644 --- a/resources/assets/build/webpack.config.js +++ b/resources/assets/build/webpack.config.js @@ -41,10 +41,7 @@ let webpackConfig = { enforce: 'pre', test: /\.js$/, include: config.paths.assets, - loader: 'eslint-loader', - options: { - configFile: config.env.production ? config.paths.eslintProd : null, - }, + use: 'eslint', }, { enforce: 'pre', From ca76f5731658ee627aef4000f530ca42df3ab710 Mon Sep 17 00:00:00 2001 From: Ben Martinez-Bateman Date: Mon, 18 Dec 2017 11:55:42 -0800 Subject: [PATCH 4/4] Don't need this any more! :( --- resources/assets/build/config.js | 1 - 1 file changed, 1 deletion(-) diff --git a/resources/assets/build/config.js b/resources/assets/build/config.js index 94d645b..60b8098 100644 --- a/resources/assets/build/config.js +++ b/resources/assets/build/config.js @@ -20,7 +20,6 @@ const config = merge({ root: rootPath, assets: path.join(rootPath, 'resources/assets'), dist: path.join(rootPath, 'dist'), - eslintProd: path.join(rootPath, '.eslintrc.production.json'), }, enabled: { sourceMaps: !isProduction,