From 46ca092023f9faa7d331c833741aad8f993d511d Mon Sep 17 00:00:00 2001 From: Ade Viankakrisna Fadlil Date: Mon, 30 Oct 2017 14:23:10 +0700 Subject: [PATCH 1/3] add support for linting json files --- packages/eslint-config-react-app/index.js | 2 +- packages/eslint-config-react-app/package.json | 1 + packages/react-error-overlay/package.json | 1 + packages/react-scripts/config/webpack.config.dev.js | 2 +- packages/react-scripts/config/webpack.config.prod.js | 2 +- packages/react-scripts/package.json | 1 + 6 files changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/eslint-config-react-app/index.js b/packages/eslint-config-react-app/index.js index f029f9626bf..a7c96590c9a 100644 --- a/packages/eslint-config-react-app/index.js +++ b/packages/eslint-config-react-app/index.js @@ -28,7 +28,7 @@ module.exports = { parser: 'babel-eslint', - plugins: ['import', 'flowtype', 'jsx-a11y', 'react'], + plugins: ['import', 'flowtype', 'jsx-a11y', 'react', 'json'], env: { browser: true, diff --git a/packages/eslint-config-react-app/package.json b/packages/eslint-config-react-app/package.json index 6f2b244a1e5..051e6475d4b 100644 --- a/packages/eslint-config-react-app/package.json +++ b/packages/eslint-config-react-app/package.json @@ -15,6 +15,7 @@ "eslint": "^4.1.1", "eslint-plugin-flowtype": "^2.34.1", "eslint-plugin-import": "^2.6.0", + "eslint-plugin-json": "^1.2.0", "eslint-plugin-jsx-a11y": "^6.0.2", "eslint-plugin-react": "^7.1.0" }, diff --git a/packages/react-error-overlay/package.json b/packages/react-error-overlay/package.json index 33e6f651bc3..404a3f5ddfc 100644 --- a/packages/react-error-overlay/package.json +++ b/packages/react-error-overlay/package.json @@ -46,6 +46,7 @@ "eslint-config-react-app": "^2.1.0", "eslint-plugin-flowtype": "2.41.0", "eslint-plugin-import": "2.8.0", + "eslint-plugin-json": "1.2.0", "eslint-plugin-jsx-a11y": "6.0.3", "eslint-plugin-react": "7.5.1", "flow-bin": "^0.63.1", diff --git a/packages/react-scripts/config/webpack.config.dev.js b/packages/react-scripts/config/webpack.config.dev.js index c975a58c790..9898bcf6a9f 100644 --- a/packages/react-scripts/config/webpack.config.dev.js +++ b/packages/react-scripts/config/webpack.config.dev.js @@ -123,7 +123,7 @@ module.exports = { // First, run the linter. // It's important to do this before Babel processes the JS. { - test: /\.(js|jsx|mjs)$/, + test: /\.(js|jsx|mjs|json)$/, enforce: 'pre', use: [ { diff --git a/packages/react-scripts/config/webpack.config.prod.js b/packages/react-scripts/config/webpack.config.prod.js index 769016ed1b6..305d2790f10 100644 --- a/packages/react-scripts/config/webpack.config.prod.js +++ b/packages/react-scripts/config/webpack.config.prod.js @@ -130,7 +130,7 @@ module.exports = { // First, run the linter. // It's important to do this before Babel processes the JS. { - test: /\.(js|jsx|mjs)$/, + test: /\.(js|jsx|mjs|json)$/, enforce: 'pre', use: [ { diff --git a/packages/react-scripts/package.json b/packages/react-scripts/package.json index 84d0faf615e..db425e1f94a 100644 --- a/packages/react-scripts/package.json +++ b/packages/react-scripts/package.json @@ -39,6 +39,7 @@ "eslint-loader": "1.9.0", "eslint-plugin-flowtype": "2.41.0", "eslint-plugin-import": "2.8.0", + "eslint-plugin-json": "1.2.0", "eslint-plugin-jsx-a11y": "6.0.3", "eslint-plugin-react": "7.5.1", "extract-text-webpack-plugin": "3.0.2", From f7100dfeae377b0c19e02d09acd7fdcc56f633bf Mon Sep 17 00:00:00 2001 From: Ade Viankakrisna Fadlil Date: Mon, 30 Oct 2017 15:39:37 +0700 Subject: [PATCH 2/3] add json-loader because the build script fails without it --- packages/react-scripts/config/webpack.config.dev.js | 6 ++++++ packages/react-scripts/config/webpack.config.prod.js | 6 ++++++ packages/react-scripts/package.json | 1 + 3 files changed, 13 insertions(+) diff --git a/packages/react-scripts/config/webpack.config.dev.js b/packages/react-scripts/config/webpack.config.dev.js index 9898bcf6a9f..c6867427965 100644 --- a/packages/react-scripts/config/webpack.config.dev.js +++ b/packages/react-scripts/config/webpack.config.dev.js @@ -148,6 +148,12 @@ module.exports = { // match the requirements. When no loader matches it will fall // back to the "file" loader at the end of the loader list. oneOf: [ + // This is included by default, but when we add .json to eslint-loader + // test regex the compiler fails to recognize json files. + { + test: /\.json$/, + loader: require.resolve('json-loader'), + }, // "url" loader works like "file" loader except that it embeds assets // smaller than specified limit in bytes as data URLs to avoid requests. // A missing `test` is equivalent to a match. diff --git a/packages/react-scripts/config/webpack.config.prod.js b/packages/react-scripts/config/webpack.config.prod.js index 305d2790f10..e8250cf7268 100644 --- a/packages/react-scripts/config/webpack.config.prod.js +++ b/packages/react-scripts/config/webpack.config.prod.js @@ -157,6 +157,12 @@ module.exports = { // match the requirements. When no loader matches it will fall // back to the "file" loader at the end of the loader list. oneOf: [ + // This is included by default, but when we add .json to eslint-loader + // test regex the compiler fails to recognize json files. + { + test: /\.json$/, + loader: require.resolve('json-loader'), + }, // "url" loader works just like "file" loader but it also embeds // assets smaller than specified size as data URLs to avoid requests. { diff --git a/packages/react-scripts/package.json b/packages/react-scripts/package.json index db425e1f94a..e414deed5ef 100644 --- a/packages/react-scripts/package.json +++ b/packages/react-scripts/package.json @@ -47,6 +47,7 @@ "fs-extra": "5.0.0", "html-webpack-plugin": "2.30.1", "jest": "22.0.6", + "json-loader": "0.5.7", "object-assign": "4.1.1", "postcss-flexbugs-fixes": "3.2.0", "postcss-loader": "2.0.10", From 74d32027143287dd5901a0c3af91a6b665f6fc62 Mon Sep 17 00:00:00 2001 From: Ade Viankakrisna Fadlil Date: Wed, 10 Jan 2018 05:27:00 +0700 Subject: [PATCH 3/3] update comment about json-loader to explain why it is needed --- packages/react-scripts/config/webpack.config.dev.js | 4 ++-- packages/react-scripts/config/webpack.config.prod.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/react-scripts/config/webpack.config.dev.js b/packages/react-scripts/config/webpack.config.dev.js index c6867427965..d0595c9a814 100644 --- a/packages/react-scripts/config/webpack.config.dev.js +++ b/packages/react-scripts/config/webpack.config.dev.js @@ -148,8 +148,8 @@ module.exports = { // match the requirements. When no loader matches it will fall // back to the "file" loader at the end of the loader list. oneOf: [ - // This is included by default, but when we add .json to eslint-loader - // test regex the compiler fails to recognize json files. + // Necessary because we add .json test in eslint-loader + // https://webpack.js.org/guides/migrating/#json-loader-is-not-required-anymore { test: /\.json$/, loader: require.resolve('json-loader'), diff --git a/packages/react-scripts/config/webpack.config.prod.js b/packages/react-scripts/config/webpack.config.prod.js index e8250cf7268..13c7cc9fae3 100644 --- a/packages/react-scripts/config/webpack.config.prod.js +++ b/packages/react-scripts/config/webpack.config.prod.js @@ -157,8 +157,8 @@ module.exports = { // match the requirements. When no loader matches it will fall // back to the "file" loader at the end of the loader list. oneOf: [ - // This is included by default, but when we add .json to eslint-loader - // test regex the compiler fails to recognize json files. + // Necessary because we add .json test in eslint-loader + // https://webpack.js.org/guides/migrating/#json-loader-is-not-required-anymore { test: /\.json$/, loader: require.resolve('json-loader'),