You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ra...@apache.org on 2019/10/21 16:14:09 UTC

[cordova-browser] branch master updated: Ensure to lint as many files as possible (#84)

This is an automated email from the ASF dual-hosted git repository.

raphinesse pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cordova-browser.git


The following commit(s) were added to refs/heads/master by this push:
     new bc0fdeb  Ensure to lint as many files as possible (#84)
bc0fdeb is described below

commit bc0fdebfaf0b5e493f8e6008dbbecc8a2563d51b
Author: Raphael von der GrĂ¼n <ra...@gmail.com>
AuthorDate: Mon Oct 21 18:14:03 2019 +0200

    Ensure to lint as many files as possible (#84)
    
    * Lint everything, including bins w/out extension
    
    * Apply eslint --fix to all linted files
    
    * Manually fix all remaining lint rule violations
    
    * Remove ESLint inline config
---
 bin/create                     | 19 +++++++------------
 bin/template/cordova/Api.js    |  4 ++--
 bin/template/cordova/build     | 10 ++++------
 bin/template/cordova/clean     | 15 ++++++---------
 bin/template/cordova/log       |  2 +-
 bin/template/cordova/run       | 35 +++++++++++++++--------------------
 bin/template/cordova/version   |  2 +-
 cordova-js-src/.eslintrc.yml   |  4 ++++
 cordova-js-src/confighelper.js | 42 ++++++++++++++++++++----------------------
 cordova-js-src/exec.js         | 40 ++++++++++++++++++----------------------
 cordova-js-src/platform.js     |  9 ++++-----
 package.json                   |  2 +-
 12 files changed, 83 insertions(+), 101 deletions(-)

diff --git a/bin/create b/bin/create
index 6d73745..3961c70 100755
--- a/bin/create
+++ b/bin/create
@@ -48,14 +48,12 @@ var path = require('path');
 var ConfigParser = require('cordova-common').ConfigParser;
 var Api = require('./template/cordova/Api');
 
-
 var argv = require('nopt')({
-    'help' : Boolean,
-    'cli' : Boolean,
-    'shared' : Boolean, // alias for --link
-    'link' : Boolean
-}, { 'd' : '--verbose' });
-
+    'help': Boolean,
+    'cli': Boolean,
+    'shared': Boolean, // alias for --link
+    'link': Boolean
+}, { 'd': '--verbose' });
 
 var projectPath = argv.argv.remain[0];
 
@@ -68,8 +66,7 @@ if (argv.help || !projectPath) {
     console.log('   <project_name>: Project name');
     console.log('   <project_template_dir>: Path to project template (override).');
     process.exit(0);
-}
-else {
+} else {
     var configPath = path.resolve(__dirname, 'template/config.xml');
     var config = new ConfigParser(configPath);
 
@@ -84,10 +81,8 @@ else {
     var options = {
         cli: argv.cli,
         link: argv.link || argv.shared,
-        customTemplate: argv.argv.remain[3],
+        customTemplate: argv.argv.remain[3]
     };
 
     Api.createPlatform(projectPath, config, options);
 }
-
-
diff --git a/bin/template/cordova/Api.js b/bin/template/cordova/Api.js
index da0ec8a..e8b9bf8 100644
--- a/bin/template/cordova/Api.js
+++ b/bin/template/cordova/Api.js
@@ -428,9 +428,9 @@ Api.prototype._addModulesInfo = function (plugin, targetDir) {
         .filter(function (moduleToInstall) {
             return installedPaths.indexOf(moduleToInstall.file) === -1;
         }).map(function (moduleToInstall) {
-            var moduleName = plugin.id + '.' + (moduleToInstall.name || moduleToInstall.src.match(/([^\/]+)\.js/)[1]);
+            var moduleName = plugin.id + '.' + (moduleToInstall.name || moduleToInstall.src.match(/([^/]+)\.js/)[1]);
             var obj = {
-                file: ['plugins', plugin.id, moduleToInstall.src].join('/'), /* eslint no-useless-escape : 0 */
+                file: ['plugins', plugin.id, moduleToInstall.src].join('/'),
                 id: moduleName,
                 pluginId: plugin.id
             };
diff --git a/bin/template/cordova/build b/bin/template/cordova/build
index e867ab1..7794438 100755
--- a/bin/template/cordova/build
+++ b/bin/template/cordova/build
@@ -19,16 +19,14 @@
        under the License.
 */
 
-
-var build = require('./lib/build'),
-    args  = process.argv;
+var build = require('./lib/build');
+var args = process.argv;
 
 // provide help
-if ( args[2] == '--help' || args[2] == '/?' || args[2] == '-h' || args[2] == '/h' ||
-                    args[2] == 'help' || args[2] == '-help' || args[2] == '/help') {
+const helpOptions = '--help /? -h /h help -help /help'.split(' ');
+if (helpOptions.includes(args[2])) {
     build.help();
     process.exit(0);
 } else {
-
     build.run();
 }
diff --git a/bin/template/cordova/clean b/bin/template/cordova/clean
index 1852d66..0f0673f 100644
--- a/bin/template/cordova/clean
+++ b/bin/template/cordova/clean
@@ -19,18 +19,15 @@
        under the License.
 */
 
-
-var path = require('path'),
-    clean = require('./lib/clean'),
-    args  = process.argv;
+var path = require('path');
+var clean = require('./lib/clean');
+var args = process.argv;
 
 // Support basic help commands
-if ( args.length > 2
-   || args[2] == '--help' || args[2] == '/?' || args[2] == '-h' ||
-                    args[2] == 'help' || args[2] == '-help' || args[2] == '/help') {
-    console.log('Usage: ' + path.relative(process.cwd(), path.join(__dirname, 'clean')) );
+const helpOptions = '--help /? -h /h help -help /help'.split(' ');
+if (args.length > 2 || helpOptions.includes(args[2])) {
+    console.log('Usage: ' + path.relative(process.cwd(), path.join(__dirname, 'clean')));
     process.exit(0);
 } else {
     clean.run();
 }
-
diff --git a/bin/template/cordova/log b/bin/template/cordova/log
index bb6fb8c..34d68e7 100755
--- a/bin/template/cordova/log
+++ b/bin/template/cordova/log
@@ -17,4 +17,4 @@
        under the License.
 */
 
-console.log("cordova/log");
\ No newline at end of file
+console.log('cordova/log');
diff --git a/bin/template/cordova/run b/bin/template/cordova/run
index b41e299..30661b8 100755
--- a/bin/template/cordova/run
+++ b/bin/template/cordova/run
@@ -19,35 +19,30 @@
        under the License.
 */
 
-var fs = require('fs'),
-    path = require('path'),
-    nopt  = require('nopt'),
-    url = require('url'),
-    runForrest = require('./lib/run'),
-    cordovaServe = require('cordova-serve');
+var nopt = require('nopt');
+var runForrest = require('./lib/run');
 
 var args = process.argv;
 
 start(args);
 
-function start(argv) {
-    var args  = nopt({'help': Boolean, 'target': String, 'port': Number}, {'help': ['/?', '-h', 'help', '-help', '/help']}, argv);
-    if(args.help) {
+function start (argv) {
+    var args = nopt({ 'help': Boolean, 'target': String, 'port': Number }, { 'help': ['/?', '-h', 'help', '-help', '/help'] }, argv);
+    if (args.help) {
         help();
-    }
-    else {
+    } else {
         return runForrest.run(args);
     }
 }
 
-function help() {
-    console.log("\nUsage: run [ --target=<browser> ] [ --port=<number> ]");
-    console.log("    --target=<browser> : Launches the specified browser. Chrome is default.");
-    console.log("    --port=<number>    : Http server uses specified port number.");
-    console.log("Examples:");
-    console.log("    run");
-    console.log("    run -- --target=ie");
-    console.log("    run -- --target=chrome --port=8000");
-    console.log("");
+function help () {
+    console.log('\nUsage: run [ --target=<browser> ] [ --port=<number> ]');
+    console.log('    --target=<browser> : Launches the specified browser. Chrome is default.');
+    console.log('    --port=<number>    : Http server uses specified port number.');
+    console.log('Examples:');
+    console.log('    run');
+    console.log('    run -- --target=ie');
+    console.log('    run -- --target=chrome --port=8000');
+    console.log('');
     process.exit(0);
 }
diff --git a/bin/template/cordova/version b/bin/template/cordova/version
index 8e51200..7020390 100755
--- a/bin/template/cordova/version
+++ b/bin/template/cordova/version
@@ -20,6 +20,6 @@
 */
 
 // Coho updates this line:
-var VERSION = "6.1.0-dev";
+var VERSION = '6.1.0-dev';
 
 console.log(VERSION);
diff --git a/cordova-js-src/.eslintrc.yml b/cordova-js-src/.eslintrc.yml
new file mode 100644
index 0000000..e3d49d8
--- /dev/null
+++ b/cordova-js-src/.eslintrc.yml
@@ -0,0 +1,4 @@
+env:
+    node: false
+    commonjs: true
+    browser: true
diff --git a/cordova-js-src/confighelper.js b/cordova-js-src/confighelper.js
index 34d8b19..88f3210 100644
--- a/cordova-js-src/confighelper.js
+++ b/cordova-js-src/confighelper.js
@@ -21,54 +21,52 @@
 
 var config;
 
-function Config(xhr) {
-    function loadPreferences(xhr) {
-       var parser = new DOMParser();
-       var doc = parser.parseFromString(xhr.responseText, "application/xml");
+function Config (xhr) {
+    function loadPreferences (xhr) {
+        var parser = new DOMParser();
+        var doc = parser.parseFromString(xhr.responseText, 'application/xml');
 
-       var preferences = doc.getElementsByTagName("preference");
-       return Array.prototype.slice.call(preferences);
+        var preferences = doc.getElementsByTagName('preference');
+        return Array.prototype.slice.call(preferences);
     }
 
     this.xhr = xhr;
     this.preferences = loadPreferences(this.xhr);
 }
 
-function readConfig(success, error) {
+function readConfig (success, error) {
     var xhr;
 
-    if(typeof config != 'undefined') {
+    if (typeof config !== 'undefined') {
         success(config);
     }
 
-    function fail(msg) {
+    function fail (msg) {
         console.error(msg);
 
-        if(error) {
+        if (error) {
             error(msg);
         }
     }
 
-    var xhrStatusChangeHandler = function() {
-        if (xhr.readyState == 4) {
-            if (xhr.status == 200 || xhr.status == 304 || xhr.status === 0 /* file:// */) {
+    var xhrStatusChangeHandler = function () {
+        if (xhr.readyState === 4) {
+            if (xhr.status === 200 || xhr.status === 304 || xhr.status === 0 /* file:// */) {
                 config = new Config(xhr);
                 success(config);
-            }
-            else {
+            } else {
                 fail('[Browser][cordova.js][xhrStatusChangeHandler] Could not XHR config.xml: ' + xhr.statusText);
             }
         }
     };
 
     xhr = new XMLHttpRequest();
-    xhr.addEventListener("load", xhrStatusChangeHandler);
-
+    xhr.addEventListener('load', xhrStatusChangeHandler);
 
     try {
-        xhr.open("get", "config.xml", true);
+        xhr.open('get', 'config.xml', true);
         xhr.send();
-    } catch(e) {
+    } catch (e) {
         fail('[Browser][cordova.js][readConfig] Could not XHR config.xml: ' + JSON.stringify(e));
     }
 }
@@ -77,12 +75,12 @@ function readConfig(success, error) {
  * Reads a preference value from config.xml.
  * Returns preference value or undefined if it does not exist.
  * @param {String} preferenceName Preference name to read */
-Config.prototype.getPreferenceValue = function getPreferenceValue(preferenceName) {
-    var preferenceItem = this.preferences && this.preferences.filter(function(item) {
+Config.prototype.getPreferenceValue = function getPreferenceValue (preferenceName) {
+    var preferenceItem = this.preferences && this.preferences.filter(function (item) {
         return item.attributes.name && item.attributes.name.value === preferenceName;
     });
 
-    if(preferenceItem && preferenceItem[0] && preferenceItem[0].attributes && preferenceItem[0].attributes.value) {
+    if (preferenceItem && preferenceItem[0] && preferenceItem[0].attributes && preferenceItem[0].attributes.value) {
         return preferenceItem[0].attributes.value.value;
     }
 };
diff --git a/cordova-js-src/exec.js b/cordova-js-src/exec.js
index 97f736a..f5f62f1 100644
--- a/cordova-js-src/exec.js
+++ b/cordova-js-src/exec.js
@@ -19,8 +19,8 @@
  *
 */
 
-/*jslint sloppy:true, plusplus:true*/
-/*global require, module, console */
+/* jslint sloppy:true, plusplus:true */
+/* global require, module, console */
 
 var cordova = require('cordova');
 var execProxy = require('cordova/exec/proxy');
@@ -46,16 +46,14 @@ module.exports = function (success, fail, service, action, args) {
     args = args || [];
 
     if (proxy) {
-        
+
         var callbackId = service + cordova.callbackId++;
-        
-        if (typeof success === "function" || typeof fail === "function") {
-            cordova.callbacks[callbackId] = {success: success, fail: fail};
+
+        if (typeof success === 'function' || typeof fail === 'function') {
+            cordova.callbacks[callbackId] = { success: success, fail: fail };
         }
         try {
 
-            
-
             // callbackOptions param represents additional optional parameters command could pass back, like keepCallback or
             // custom callbackId, for example {callbackId: id, keepCallback: true, status: cordova.callbackStatus.JSON_EXCEPTION }
             var onSuccess = function (result, callbackOptions) {
@@ -67,8 +65,7 @@ module.exports = function (success, fail, service, action, args) {
                 // see CB-8996 Mobilespec app hang on windows
                 if (callbackOptions.status !== undefined && callbackOptions.status !== null) {
                     callbackStatus = callbackOptions.status;
-                }
-                else {
+                } else {
                     callbackStatus = cordova.callbackStatus.OK;
                 }
                 cordova.callbackSuccess(callbackOptions.callbackId || callbackId,
@@ -87,28 +84,27 @@ module.exports = function (success, fail, service, action, args) {
                 // note: status can be 0
                 if (callbackOptions.status !== undefined && callbackOptions.status !== null) {
                     callbackStatus = callbackOptions.status;
-                }
-                else {
+                } else {
                     callbackStatus = cordova.callbackStatus.OK;
                 }
                 cordova.callbackError(callbackOptions.callbackId || callbackId,
-                {
-                    status: callbackStatus,
-                    message: err,
-                    keepCallback: callbackOptions.keepCallback || false
-                });
+                    {
+                        status: callbackStatus,
+                        message: err,
+                        keepCallback: callbackOptions.keepCallback || false
+                    });
             };
             proxy(onSuccess, onError, args);
 
         } catch (e) {
-            console.log("Exception calling native with command :: " + service + " :: " + action  + " ::exception=" + e);
+            console.log('Exception calling native with command :: ' + service + ' :: ' + action + ' ::exception=' + e);
         }
     } else {
 
-        console.log("Error: exec proxy not found for :: " + service + " :: " + action);
-        
-        if(typeof fail === "function" ) {
-            fail("Missing Command Error");
+        console.log('Error: exec proxy not found for :: ' + service + ' :: ' + action);
+
+        if (typeof fail === 'function') {
+            fail('Missing Command Error');
         }
     }
 };
diff --git a/cordova-js-src/platform.js b/cordova-js-src/platform.js
index 96eb943..18e43a6 100644
--- a/cordova-js-src/platform.js
+++ b/cordova-js-src/platform.js
@@ -23,7 +23,7 @@ module.exports = {
     id: 'browser',
     cordovaVersion: '4.2.0', // cordova-js
 
-    bootstrap: function() {
+    bootstrap: function () {
 
         var modulemapper = require('cordova/modulemapper');
         var channel = require('cordova/channel');
@@ -32,11 +32,10 @@ module.exports = {
 
         channel.onNativeReady.fire();
 
-        document.addEventListener("visibilitychange", function(){
-            if(document.hidden) {
+        document.addEventListener('visibilitychange', function () {
+            if (document.hidden) {
                 channel.onPause.fire();
-            }
-            else {
+            } else {
                 channel.onResume.fire();
             }
         });
diff --git a/package.json b/package.json
index 61d20d2..bf59e2c 100644
--- a/package.json
+++ b/package.json
@@ -18,7 +18,7 @@
   ],
   "scripts": {
     "cover": "nyc jasmine",
-    "eslint": "eslint bin spec",
+    "eslint": "eslint . \"bin/**/!(*.*)\"",
     "jasmine": "jasmine",
     "test": "npm run eslint && npm run cover"
   },


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