You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by au...@apache.org on 2017/07/18 16:54:28 UTC

cordova-serve git commit: CB-12895 : setup eslint and removed jshint

Repository: cordova-serve
Updated Branches:
  refs/heads/master 0c2fbd904 -> 1119b5eb9


CB-12895 : setup eslint and removed jshint


Project: http://git-wip-us.apache.org/repos/asf/cordova-serve/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-serve/commit/1119b5eb
Tree: http://git-wip-us.apache.org/repos/asf/cordova-serve/tree/1119b5eb
Diff: http://git-wip-us.apache.org/repos/asf/cordova-serve/diff/1119b5eb

Branch: refs/heads/master
Commit: 1119b5eb9d2f44379aa7763a35c199327f5ad99f
Parents: 0c2fbd9
Author: Audrey So <au...@apache.org>
Authored: Fri Jun 9 13:07:21 2017 -0700
Committer: Audrey So <au...@apache.org>
Committed: Fri Jul 14 15:16:59 2017 -0700

----------------------------------------------------------------------
 .eslintrc.yml   | 10 +++++++
 package.json    | 12 ++++++--
 src/browser.js  | 78 +++++++++++++++++++++++++++-------------------------
 src/exec.js     |  8 ++----
 src/platform.js |  8 +++---
 src/server.js   |  6 ++--
 src/util.js     | 16 +++++------
 7 files changed, 77 insertions(+), 61 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-serve/blob/1119b5eb/.eslintrc.yml
----------------------------------------------------------------------
diff --git a/.eslintrc.yml b/.eslintrc.yml
new file mode 100644
index 0000000..f6aae32
--- /dev/null
+++ b/.eslintrc.yml
@@ -0,0 +1,10 @@
+root: true
+extends: semistandard
+rules:
+  indent:
+    - error
+    - 4
+  camelcase: off
+  padded-blocks: off
+  operator-linebreak: off
+  no-throw-literal: off

http://git-wip-us.apache.org/repos/asf/cordova-serve/blob/1119b5eb/package.json
----------------------------------------------------------------------
diff --git a/package.json b/package.json
index 26671d1..aea3625 100644
--- a/package.json
+++ b/package.json
@@ -26,11 +26,17 @@
     "shelljs": "^0.5.3"
   },
   "devDependencies": {
-    "jshint": "^2.8.0"
+    "eslint": "^4.0.0",
+    "eslint-config-semistandard": "^11.0.0",
+    "eslint-config-standard": "^10.2.1",
+    "eslint-plugin-import": "^2.3.0",
+    "eslint-plugin-node": "^5.0.0",
+    "eslint-plugin-promise": "^3.5.0",
+    "eslint-plugin-standard": "^3.0.1"
   },
   "scripts": {
-    "jshint": "node node_modules/jshint/bin/jshint src",
-    "test": "npm run jshint"
+    "eslint": "node node_modules/eslint/bin/eslint src ",
+    "test": "npm run eslint"
   },
   "engines": {
     "node": ">=4.0.0",

http://git-wip-us.apache.org/repos/asf/cordova-serve/blob/1119b5eb/src/browser.js
----------------------------------------------------------------------
diff --git a/src/browser.js b/src/browser.js
index 2b08afb..05690cc 100644
--- a/src/browser.js
+++ b/src/browser.js
@@ -17,10 +17,10 @@
  under the License.
  */
 
-var child_process = require('child_process'),
-    exec = require('./exec'),
-    fs = require('fs'),
-    Q = require('q');
+var child_process = require('child_process');
+var exec = require('./exec');
+var fs = require('fs');
+var Q = require('q');
 
 var NOT_INSTALLED = 'The browser target is not installed: %target%';
 var NOT_SUPPORTED = 'The browser target is not supported: %target%';
@@ -44,34 +44,34 @@ module.exports = function (opts) {
 
         var urlAdded = false;
         switch (process.platform) {
-            case 'darwin':
-                args = ['open'];
-                if (target == 'chrome') {
-                    // Chrome needs to be launched in a new window. Other browsers, particularly, opera does not work with this.        
-                    args.push('-n');
-                }
-                args.push('-a', browser);
-                break;
-            case 'win32':
-                // On Windows, we really want to use the "start" command. But, the rules regarding arguments with spaces, and 
-                // escaping them with quotes, can get really arcane. So the easiest way to deal with this is to pass off the 
-                // responsibility to "cmd /c", which has that logic built in. 
-                // 
-                // Furthermore, if "cmd /c" double-quoted the first parameter, then "start" will interpret it as a window title, 
-                // so we need to add a dummy empty-string window title: http://stackoverflow.com/a/154090/3191
-
-                if (target === 'edge') {
-                    browser += ':' + url;
-                    urlAdded = true;
-                }
-
-                args = ['cmd /c start ""', browser];
-                break;
-            case 'linux':
+        case 'darwin':
+            args = ['open'];
+            if (target === 'chrome') {
+                // Chrome needs to be launched in a new window. Other browsers, particularly, opera does not work with this.
+                args.push('-n');
+            }
+            args.push('-a', browser);
+            break;
+        case 'win32':
+            // On Windows, we really want to use the "start" command. But, the rules regarding arguments with spaces, and
+            // escaping them with quotes, can get really arcane. So the easiest way to deal with this is to pass off the
+            // responsibility to "cmd /c", which has that logic built in.
+            //
+            // Furthermore, if "cmd /c" double-quoted the first parameter, then "start" will interpret it as a window title,
+            // so we need to add a dummy empty-string window title: http://stackoverflow.com/a/154090/3191
+
+            if (target === 'edge') {
+                browser += ':' + url;
+                urlAdded = true;
+            }
+
+            args = ['cmd /c start ""', browser];
+            break;
+        case 'linux':
                 // if a browser is specified, launch it with the url as argument
                 // otherwise, use xdg-open.
-                args = [browser];
-                break;
+            args = [browser];
+            break;
         }
 
         if (!urlAdded) {
@@ -80,12 +80,14 @@ module.exports = function (opts) {
         var command = args.join(' ');
         return exec(command).catch(function (error) {
             // Assume any error means that the browser is not installed and display that as a more friendly error.
-            throw new Error(NOT_INSTALLED.replace('%target%', target));
+            if (error) {
+                throw new Error(NOT_INSTALLED.replace('%target%', target));
+            }
         });
     });
 };
 
-function getBrowser(target, dataDir) {
+function getBrowser (target, dataDir) {
     dataDir = dataDir || 'temp_chrome_user_data_dir_for_cordova';
 
     var chromeArgs = ' --user-data-dir=/tmp/' + dataDir;
@@ -125,14 +127,14 @@ function getBrowser(target, dataDir) {
     return Q.reject(NOT_SUPPORTED.replace('%target%', target));
 }
 
-function checkBrowserExistsWindows(browser, target) {
+function checkBrowserExistsWindows (browser, target) {
     var promise = target === 'edge' ? edgeSupported() : browserInstalled(browser);
     return promise.catch(function (error) {
-        return Q.reject((error && error.toString() || NOT_INSTALLED).replace('%target%', target));
+        return Q.reject(((error && error.toString()) || ((NOT_INSTALLED).replace('%target%', target))));
     });
 }
 
-function edgeSupported() {
+function edgeSupported () {
     var d = Q.defer();
 
     child_process.exec('ver', function (err, stdout, stderr) {
@@ -151,7 +153,7 @@ function edgeSupported() {
 }
 
 var regItemPattern = /\s*\(Default\)\s+(REG_SZ)\s+([^\s].*)\s*/;
-function browserInstalled(browser) {
+function browserInstalled (browser) {
     // On Windows, the 'start' command searches the path then 'App Paths' in the registry. We do the same here. Note
     // that the start command uses the PATHEXT environment variable for the list of extensions to use if no extension is
     // provided. We simplify that to just '.EXE' since that is what all the supported browsers use.
@@ -175,7 +177,7 @@ function browserInstalled(browser) {
                 // fail the fs.exists() test below to give us the expected result).
                 d.reject();
             } else {
-                fs.exists(trimRegPath(result[2]), function (exists) {
+                fs.stat(trimRegPath(result[2]), function (exists) {
                     if (exists) {
                         d.resolve();
                     } else {
@@ -190,7 +192,7 @@ function browserInstalled(browser) {
     return d.promise;
 }
 
-function trimRegPath(path) {
+function trimRegPath (path) {
     // Trim quotes and whitespace
     return path.replace(/^[\s"]+|[\s"]+$/g, '');
 }

http://git-wip-us.apache.org/repos/asf/cordova-serve/blob/1119b5eb/src/exec.js
----------------------------------------------------------------------
diff --git a/src/exec.js b/src/exec.js
index d1c02a4..35e0dec 100644
--- a/src/exec.js
+++ b/src/exec.js
@@ -17,8 +17,8 @@
  under the License.
  */
 
-var child_process = require('child_process'),
-    Q             = require('q');
+var child_process = require('child_process');
+var Q = require('q');
 
 /**
  * Executes the command specified.
@@ -32,8 +32,7 @@ module.exports = function (cmd, opt_cwd) {
         child_process.exec(cmd, {cwd: opt_cwd, maxBuffer: 1024000}, function (err, stdout, stderr) {
             if (err) {
                 d.reject(new Error('Error executing "' + cmd + '": ' + stderr));
-            }
-            else {
+            } else {
                 d.resolve(stdout);
             }
         });
@@ -43,4 +42,3 @@ module.exports = function (cmd, opt_cwd) {
     }
     return d.promise;
 };
-

http://git-wip-us.apache.org/repos/asf/cordova-serve/blob/1119b5eb/src/platform.js
----------------------------------------------------------------------
diff --git a/src/platform.js b/src/platform.js
index 7abbb81..ca8e139 100644
--- a/src/platform.js
+++ b/src/platform.js
@@ -17,9 +17,9 @@
  under the License.
  */
 
-var fs     = require('fs'),
-    Q      = require('q'),
-    util   = require('./util');
+var fs = require('fs');
+var Q = require('q');
+var util = require('./util');
 
 /**
  * Launches a server where the root points to the specified platform in a Cordova project.
@@ -49,7 +49,7 @@ module.exports = function (platform, opts) {
     });
 };
 
-function findProjectRoot(path) {
+function findProjectRoot (path) {
     var projectRoot = util.cordovaProjectRoot(path);
     if (!projectRoot) {
         if (!path) {

http://git-wip-us.apache.org/repos/asf/cordova-serve/blob/1119b5eb/src/server.js
----------------------------------------------------------------------
diff --git a/src/server.js b/src/server.js
index 9040d2b..f629f69 100644
--- a/src/server.js
+++ b/src/server.js
@@ -17,9 +17,9 @@
  under the License.
  */
 
-var chalk   = require('chalk'),
-    express = require('express'),
-    Q       = require('q');
+var chalk = require('chalk');
+var express = require('express');
+var Q = require('q');
 
 /**
  * @desc Launches a server with the specified options and optional custom handlers.

http://git-wip-us.apache.org/repos/asf/cordova-serve/blob/1119b5eb/src/util.js
----------------------------------------------------------------------
diff --git a/src/util.js b/src/util.js
index 8fb076b..242e96f 100644
--- a/src/util.js
+++ b/src/util.js
@@ -17,8 +17,8 @@
  under the License.
  */
 
-var fs   = require('fs'),
-    path = require('path');
+var fs = require('fs');
+var path = require('path');
 
 // Some helpful utility stuff copied from cordova-lib. This is a bit nicer than taking a dependency on cordova-lib just
 // to get this minimal stuff. Hopefully we won't need the platform stuff (finding platform www_dir) once it is moved
@@ -41,12 +41,12 @@ var platforms = {
  * @param {string=} dir - the directory to start from (we check this directory then work up), or CWD if none specified.
  * @returns {string} - the Cordova project's root directory, or null if not found.
  */
-function cordovaProjectRoot(dir) {
+function cordovaProjectRoot (dir) {
     if (!dir) {
         // Prefer PWD over cwd so that symlinked dirs within your PWD work correctly.
         var pwd = process.env.PWD;
         var cwd = process.cwd();
-        if (pwd && pwd != cwd && pwd != 'undefined') {
+        if (pwd && pwd !== cwd && pwd !== 'undefined') {
             return cordovaProjectRoot(pwd) || cordovaProjectRoot(cwd);
         }
         return cordovaProjectRoot(cwd);
@@ -63,7 +63,7 @@ function cordovaProjectRoot(dir) {
         }
         var parentDir = path.normalize(path.join(dir, '..'));
         // Detect fs root.
-        if (parentDir == dir) {
+        if (parentDir === dir) {
             return bestReturnValueSoFar;
         }
         dir = parentDir;
@@ -71,15 +71,15 @@ function cordovaProjectRoot(dir) {
     return null;
 }
 
-function getPlatformWwwRoot(cordovaProjectRoot, platformName) {
+function getPlatformWwwRoot (cordovaProjectRoot, platformName) {
     var platform = platforms[platformName];
     if (!platform) {
-        throw new Error ('Unrecognized platform: ' + platformName);
+        throw new Error('Unrecognized platform: ' + platformName);
     }
     return path.join(cordovaProjectRoot, 'platforms', platformName, platform.www_dir);
 }
 
-function isRootDir(dir) {
+function isRootDir (dir) {
     if (fs.existsSync(path.join(dir, 'www'))) {
         if (fs.existsSync(path.join(dir, 'config.xml'))) {
             // For sure is.


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org