From 51b6886f8d71125b6b9c27262c153af8c39e1555 Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Sun, 5 Mar 2017 22:29:28 +0000 Subject: [PATCH] Lint internal scripts with eslint:recommended (#1729) * Lint internal scripts with eslint:recommended * Warnings r bad --- .eslintrc | 15 ++++++++++++++- package.json | 6 ------ packages/eslint-config-react-app/index.js | 2 ++ packages/react-dev-utils/checkRequiredFiles.js | 2 ++ packages/react-dev-utils/clearConsole.js | 2 ++ packages/react-dev-utils/formatWebpackMessages.js | 2 ++ packages/react-dev-utils/getProcessForPort.js | 11 +++++++++++ packages/react-dev-utils/openBrowser.js | 2 ++ packages/react-dev-utils/prompt.js | 4 +++- packages/react-dev-utils/webpackHotDevClient.js | 4 +++- packages/react-scripts/bin/react-scripts.js | 4 ++-- .../react-scripts/config/webpack.config.prod.js | 1 - .../fixtures/kitchensink/integration/initDOM.js | 2 +- tasks/e2e-simple.sh | 2 +- 14 files changed, 45 insertions(+), 14 deletions(-) diff --git a/.eslintrc b/.eslintrc index 5e603ecd193..d4e6d47749e 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,3 +1,16 @@ { - "extends": "react-app" + "extends": "eslint:recommended", + "env": { + "browser": true, + "commonjs": true, + "node": true, + "es6": true + }, + "parserOptions": { + "ecmaVersion": 6 + }, + "rules": { + "no-console": "off", + "strict": ["error", "global"] + } } diff --git a/package.json b/package.json index 1398c949cf9..46bc55b0245 100644 --- a/package.json +++ b/package.json @@ -11,13 +11,7 @@ "test": "node packages/react-scripts/scripts/test.js --env=jsdom" }, "devDependencies": { - "babel-eslint": "7.1.0", "eslint": "3.16.1", - "eslint-config-react-app": "0.5.1", - "eslint-plugin-flowtype": "2.21.0", - "eslint-plugin-import": "2.0.1", - "eslint-plugin-jsx-a11y": "4.0.0", - "eslint-plugin-react": "6.4.1", "lerna": "2.0.0-beta.38", "lerna-changelog": "^0.2.3" } diff --git a/packages/eslint-config-react-app/index.js b/packages/eslint-config-react-app/index.js index dc111c991ed..b56b41680da 100644 --- a/packages/eslint-config-react-app/index.js +++ b/packages/eslint-config-react-app/index.js @@ -7,6 +7,8 @@ * of patent rights can be found in the PATENTS file in the same directory. */ +'use strict'; + // Inspired by https://github.com/airbnb/javascript but less opinionated. // We use eslint-loader so even warnings are very visible. diff --git a/packages/react-dev-utils/checkRequiredFiles.js b/packages/react-dev-utils/checkRequiredFiles.js index 69233db4837..55139b0b870 100644 --- a/packages/react-dev-utils/checkRequiredFiles.js +++ b/packages/react-dev-utils/checkRequiredFiles.js @@ -7,6 +7,8 @@ * of patent rights can be found in the PATENTS file in the same directory. */ +'use strict'; + var fs = require('fs'); var path = require('path'); var chalk = require('chalk'); diff --git a/packages/react-dev-utils/clearConsole.js b/packages/react-dev-utils/clearConsole.js index cfd10155167..74336284723 100644 --- a/packages/react-dev-utils/clearConsole.js +++ b/packages/react-dev-utils/clearConsole.js @@ -7,6 +7,8 @@ * of patent rights can be found in the PATENTS file in the same directory. */ +'use strict'; + function clearConsole() { process.stdout.write(process.platform === 'win32' ? '\x1Bc' : '\x1B[2J\x1B[3J\x1B[H'); } diff --git a/packages/react-dev-utils/formatWebpackMessages.js b/packages/react-dev-utils/formatWebpackMessages.js index 88834a9fc62..bfee3ec5b65 100644 --- a/packages/react-dev-utils/formatWebpackMessages.js +++ b/packages/react-dev-utils/formatWebpackMessages.js @@ -7,6 +7,8 @@ * of patent rights can be found in the PATENTS file in the same directory. */ +'use strict'; + // WARNING: this code is untranspiled and is used in browser too. // Please make sure any changes are in ES5 or contribute a Babel compile step. diff --git a/packages/react-dev-utils/getProcessForPort.js b/packages/react-dev-utils/getProcessForPort.js index d412b0c7a72..24b89823eb6 100644 --- a/packages/react-dev-utils/getProcessForPort.js +++ b/packages/react-dev-utils/getProcessForPort.js @@ -1,3 +1,14 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +'use strict'; + var chalk = require('chalk'); var execSync = require('child_process').execSync; var path = require('path'); diff --git a/packages/react-dev-utils/openBrowser.js b/packages/react-dev-utils/openBrowser.js index 2e66716439b..912c1819bcd 100644 --- a/packages/react-dev-utils/openBrowser.js +++ b/packages/react-dev-utils/openBrowser.js @@ -7,6 +7,8 @@ * of patent rights can be found in the PATENTS file in the same directory. */ +'use strict'; + var execSync = require('child_process').execSync; var opn = require('opn'); diff --git a/packages/react-dev-utils/prompt.js b/packages/react-dev-utils/prompt.js index 4b1faf9bac8..e6e19cf39eb 100644 --- a/packages/react-dev-utils/prompt.js +++ b/packages/react-dev-utils/prompt.js @@ -7,6 +7,8 @@ * of patent rights can be found in the PATENTS file in the same directory. */ +'use strict'; + var rl = require('readline'); // Convention: "no" should be the conservative choice. @@ -37,6 +39,6 @@ function prompt(question, isYesDefault) { return resolve(isYes); }); }); -}; +} module.exports = prompt; diff --git a/packages/react-dev-utils/webpackHotDevClient.js b/packages/react-dev-utils/webpackHotDevClient.js index 7b1768d8fa0..b5ed34669b5 100644 --- a/packages/react-dev-utils/webpackHotDevClient.js +++ b/packages/react-dev-utils/webpackHotDevClient.js @@ -7,6 +7,8 @@ * of patent rights can be found in the PATENTS file in the same directory. */ +'use strict'; + // This alternative WebpackDevServer combines the functionality of: // https://github.com/webpack/webpack-dev-server/blob/webpack-1/client/index.js // https://github.com/webpack/webpack/blob/webpack-1/hot/dev-server.js @@ -319,4 +321,4 @@ function tryApplyUpdates(onHotUpdateSuccess) { } ); } -}; +} diff --git a/packages/react-scripts/bin/react-scripts.js b/packages/react-scripts/bin/react-scripts.js index 5ed9b244ca6..e614d9b598e 100755 --- a/packages/react-scripts/bin/react-scripts.js +++ b/packages/react-scripts/bin/react-scripts.js @@ -14,13 +14,13 @@ case 'test': {stdio: 'inherit'} ); if (result.signal) { - if (result.signal == 'SIGKILL') { + if (result.signal === 'SIGKILL') { console.log( 'The build failed because the process exited too early. ' + 'This probably means the system ran out of memory or someone called ' + '`kill -9` on the process.' ); - } else if (result.signal == 'SIGTERM') { + } else if (result.signal === 'SIGTERM') { console.log( 'The build failed because the process exited too early. ' + 'Someone might have called `kill` or `killall`, or the system could ' + diff --git a/packages/react-scripts/config/webpack.config.prod.js b/packages/react-scripts/config/webpack.config.prod.js index 548f3793456..61aaf5fedac 100644 --- a/packages/react-scripts/config/webpack.config.prod.js +++ b/packages/react-scripts/config/webpack.config.prod.js @@ -15,7 +15,6 @@ var HtmlWebpackPlugin = require('html-webpack-plugin'); var ExtractTextPlugin = require('extract-text-webpack-plugin'); var ManifestPlugin = require('webpack-manifest-plugin'); var InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin'); -var url = require('url'); var paths = require('./paths'); var getClientEnvironment = require('./env'); diff --git a/packages/react-scripts/fixtures/kitchensink/integration/initDOM.js b/packages/react-scripts/fixtures/kitchensink/integration/initDOM.js index 7cf8134b79f..9b6049104f9 100644 --- a/packages/react-scripts/fixtures/kitchensink/integration/initDOM.js +++ b/packages/react-scripts/fixtures/kitchensink/integration/initDOM.js @@ -15,7 +15,7 @@ if (process.env.E2E_FILE) { const markup = fs.readFileSync(file, 'utf8') getMarkup = () => markup - const pathPrefix = process.env.PUBLIC_URL.replace(/^https?:\/\/[^\/]+\/?/, '') + const pathPrefix = process.env.PUBLIC_URL.replace(/^https?:\/\/[^/]+\/?/, '') resourceLoader = (resource, callback) => callback( null, diff --git a/tasks/e2e-simple.sh b/tasks/e2e-simple.sh index 594f4604085..650d6783898 100755 --- a/tasks/e2e-simple.sh +++ b/tasks/e2e-simple.sh @@ -97,7 +97,7 @@ then fi # Lint own code -./node_modules/.bin/eslint --ignore-path .gitignore ./ +./node_modules/.bin/eslint --max-warnings 0 --ignore-path .gitignore ./ # ****************************************************************************** # First, test the create-react-app development environment.