From 879f6caed14c6fba0d6b51d260f96715e8eb6b6e Mon Sep 17 00:00:00 2001 From: Ivan Goncharov Date: Sun, 19 May 2019 11:51:26 +0300 Subject: [PATCH] Replace all "var" with "const" & "let" in "resources/*.js" files (#1872) --- .eslintrc.yml | 2 -- resources/inline-invariant.js | 6 +++--- resources/watch.js | 30 +++++++++++++++--------------- 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/.eslintrc.yml b/.eslintrc.yml index edbd8d9a31..8c7f05ca78 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -363,9 +363,7 @@ overrides: no-console: off no-sync: off global-require: off - no-var: off #TODO no-shadow: off #TODO - vars-on-top: off #TODO no-unused-vars: off #TODO no-else-return: off #TODO object-shorthand: off #TODO diff --git a/resources/inline-invariant.js b/resources/inline-invariant.js index 94afc3b858..93ea54593f 100644 --- a/resources/inline-invariant.js +++ b/resources/inline-invariant.js @@ -26,14 +26,14 @@ module.exports = function inlineInvariant(context) { return { visitor: { CallExpression: function(path) { - var node = path.node; - var parent = path.parent; + const node = path.node; + const parent = path.parent; if (!isAppropriateInvariantCall(node, parent)) { return; } - var args = node.arguments.slice(0); + const args = node.arguments.slice(0); args[0] = t.numericLiteral(0); path.replaceWith( diff --git a/resources/watch.js b/resources/watch.js index b542fcf4b4..f135f3e364 100644 --- a/resources/watch.js +++ b/resources/watch.js @@ -16,12 +16,12 @@ const flowBinPath = require('flow-bin'); process.env.PATH += ':./node_modules/.bin'; -var cmd = resolvePath(__dirname); -var srcDir = resolvePath(cmd, '../src'); +const cmd = resolvePath(__dirname); +const srcDir = resolvePath(cmd, '../src'); function exec(command, options) { return new Promise((resolve, reject) => { - var child = spawn(command, options, { + const child = spawn(command, options, { cmd: cmd, env: process.env, stdio: 'inherit' @@ -36,12 +36,12 @@ function exec(command, options) { }); } -var flowServer = spawn(flowBinPath, ['server'], { +const flowServer = spawn(flowBinPath, ['server'], { cmd: cmd, env: process.env }); -var watcher = sane(srcDir, { glob: ['**/*.js', '**/*.graphql'] }) +const watcher = sane(srcDir, { glob: ['**/*.js', '**/*.graphql'] }) .on('ready', startWatch) .on('add', changeFile) .on('delete', deleteFile) @@ -54,10 +54,10 @@ process.on('SIGINT', () => { process.exit(); }); -var isChecking; -var needsCheck; -var toCheck = {}; -var timeout; +let isChecking; +let needsCheck; +let toCheck = {}; +let timeout; function startWatch() { process.stdout.write(CLEARSCREEN + green(invert('watching...'))); @@ -86,7 +86,7 @@ function guardedCheck() { return; } isChecking = true; - var filepaths = Object.keys(toCheck); + const filepaths = Object.keys(toCheck); toCheck = {}; needsCheck = false; checkFiles(filepaths).then(() => { @@ -150,7 +150,7 @@ function allTests(filepaths) { return filepaths.length > 0 && filepaths.every(isTest); } -var TEST_PATH_RX = /^(?:.*?\/)?__tests__\/.+?-test\.js$/; +const TEST_PATH_RX = /^(?:.*?\/)?__tests__\/.+?-test\.js$/; function isTest(filepath) { return TEST_PATH_RX.test(filepath); @@ -158,10 +158,10 @@ function isTest(filepath) { // Print helpers -var CLEARSCREEN = '\u001b[2J'; -var CLEARLINE = '\r\x1B[K'; -var CHECK = green('\u2713'); -var X = red('\u2718'); +const CLEARSCREEN = '\u001b[2J'; +const CLEARLINE = '\r\x1B[K'; +const CHECK = green('\u2713'); +const X = red('\u2718'); function invert(str) { return `\u001b[7m ${str} \u001b[27m`;