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/07/18 10:22:38 UTC

[cordova-common] branch master updated: Fix ESLint violations where applicable (#83)

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-common.git


The following commit(s) were added to refs/heads/master by this push:
     new ea24546  Fix ESLint violations where applicable (#83)
ea24546 is described below

commit ea24546ea48a7d612b2467c70d6434e5652d816b
Author: Raphael von der GrĂ¼n <ra...@gmail.com>
AuthorDate: Thu Jul 18 12:22:34 2019 +0200

    Fix ESLint violations where applicable (#83)
    
    Fixes most ESLint violations that were masked by ESLint comments. Two instances still remain. One is an acceptable usage of `eval` and is in `CordovaError` that should be fixed by its own commit.
---
 spec/ActionStack.spec.js                 |  4 +--
 spec/ConfigChanges/ConfigChanges.spec.js |  2 +-
 spec/ConfigParser/ConfigParser.spec.js   |  3 +-
 spec/PlatformJson.spec.js                |  2 +-
 spec/PluginInfo/PluginInfo.spec.js       | 42 +++++++++---------------
 spec/superspawn.spec.js                  |  5 ++-
 spec/util/xml-helpers.spec.js            | 56 ++++++++++++++------------------
 src/ConfigChanges/ConfigFile.js          |  4 +--
 src/CordovaError/CordovaError.js         |  5 +--
 src/PlatformJson.js                      |  2 +-
 src/PluginManager.js                     |  4 +--
 src/util/plist-helpers.js                |  3 +-
 src/util/xml-helpers.js                  |  6 ++--
 13 files changed, 57 insertions(+), 81 deletions(-)

diff --git a/spec/ActionStack.spec.js b/spec/ActionStack.spec.js
index 496d73b..d651dc9 100644
--- a/spec/ActionStack.spec.js
+++ b/spec/ActionStack.spec.js
@@ -17,13 +17,13 @@
     under the License.
 */
 var path = require('path');
-var action_stack = require('../src/ActionStack');
+var ActionStack = require('../src/ActionStack');
 var android_one_project = path.join(__dirname, '..', 'projects', 'android_one');
 
 describe('action-stack', function () {
     var stack;
     beforeEach(function () {
-        stack = new action_stack(); /* eslint new-cap : 0 */
+        stack = new ActionStack();
     });
     describe('processing of actions', function () {
         it('Test 001 : should process actions one at a time until all are done', function () {
diff --git a/spec/ConfigChanges/ConfigChanges.spec.js b/spec/ConfigChanges/ConfigChanges.spec.js
index e76eab8..21baa57 100644
--- a/spec/ConfigChanges/ConfigChanges.spec.js
+++ b/spec/ConfigChanges/ConfigChanges.spec.js
@@ -56,7 +56,7 @@ var cfg = new ConfigParser(xml);
 var pluginInfoProvider = new PluginInfoProvider();
 
 function innerXML (xmltext) {
-    return xmltext.replace(/^<[\w\s\-=\/"\.]+>/, '').replace(/<\/[\w\s\-=\/"\.]+>$/, ''); /* eslint no-useless-escape : 0 */
+    return xmltext.replace(/^<[\w\s\-=/".]+>/, '').replace(/<\/[\w\s\-=/".]+>$/, '');
 }
 
 function get_munge_change () {
diff --git a/spec/ConfigParser/ConfigParser.spec.js b/spec/ConfigParser/ConfigParser.spec.js
index a2f13b8..e3058ed 100644
--- a/spec/ConfigParser/ConfigParser.spec.js
+++ b/spec/ConfigParser/ConfigParser.spec.js
@@ -24,9 +24,8 @@ var xml = path.join(__dirname, '../fixtures/test-config.xml');
 var xml_contents = fs.readFileSync(xml, 'utf-8');
 
 describe('config.xml parser', function () {
-    var readFile; /* eslint no-unused-vars : 0 */
     beforeEach(function () {
-        readFile = spyOn(fs, 'readFileSync').and.returnValue(xml_contents);
+        spyOn(fs, 'readFileSync').and.returnValue(xml_contents);
     });
 
     it('Test 001 : should create an instance based on an xml file', function () {
diff --git a/spec/PlatformJson.spec.js b/spec/PlatformJson.spec.js
index cac5a68..8e2a9e7 100644
--- a/spec/PlatformJson.spec.js
+++ b/spec/PlatformJson.spec.js
@@ -161,7 +161,7 @@ describe('ModuleMetadata class', function () {
 
     it('Test 011 : should throw if either pluginId or jsModule argument isn\'t specified', function () {
         expect(ModuleMetadata).toThrow();
-        expect(function () { new ModuleMetadata('fakePlugin', {}); }).toThrow(); /* eslint no-new : 0 */
+        expect(() => new ModuleMetadata('fakePlugin', {})).toThrow();
     });
 
     it('Test 012 : should guess module id either from name property of from module src', function () {
diff --git a/spec/PluginInfo/PluginInfo.spec.js b/spec/PluginInfo/PluginInfo.spec.js
index 98c617a..aa2a7c8 100644
--- a/spec/PluginInfo/PluginInfo.spec.js
+++ b/spec/PluginInfo/PluginInfo.spec.js
@@ -23,40 +23,28 @@ var pluginsDir = path.join(__dirname, '../fixtures/plugins');
 
 describe('PluginInfo', function () {
     it('Test 001 : should read a plugin.xml file', function () {
-        /* eslint-disable no-unused-vars */
-        var p;
-        var prefs;
-        var assets;
-        var deps;
-        var configFiles;
-        var infos;
-        var srcFiles;
-        var headerFiles;
-        var libFiles;
-        var resourceFiles;
-        var getFrameworks;
+        let p;
         expect(function () {
             p = new PluginInfo(path.join(pluginsDir, 'ChildBrowser'));
-            prefs = p.getPreferences('android');
-            assets = p.getAssets('android');
-            deps = p.getDependencies('android');
-            configFiles = p.getConfigFiles('android');
-            infos = p.getInfo('android');
-            srcFiles = p.getSourceFiles('android');
-            headerFiles = p.getHeaderFiles('android');
-            libFiles = p.getLibFiles('android');
-            getFrameworks = p.getFrameworks('android');
-            resourceFiles = p.getResourceFiles('android');
         }).not.toThrow();
+
         expect(p).toBeDefined();
         expect(p.name).toEqual('Child Browser');
-        // TODO: Add some expectations for results of getSomething.
-        /* eslint-enable no-unused-vars */
+
+        expect(p.getInfo('android').length).toBe(2);
+        expect(p.getAssets('android').length).toBe(2);
+        expect(p.getConfigFiles('android').length).toBe(4);
+        expect(p.getSourceFiles('android').length).toBe(1);
+        expect(p.getPreferences('android')).toEqual({});
+        expect(p.getDependencies('android')).toEqual([]);
+        expect(p.getHeaderFiles('android')).toEqual([]);
+        expect(p.getLibFiles('android')).toEqual([]);
+        expect(p.getFrameworks('android')).toEqual([]);
+        expect(p.getResourceFiles('android')).toEqual([]);
     });
+
     it('Test 002 : should throw when there is no plugin.xml file', function () {
-        expect(function () {
-            new PluginInfo('/non/existent/dir'); /* eslint no-new : 0 */
-        }).toThrow();
+        expect(() => new PluginInfo('/non/existent/dir')).toThrow();
     });
 
     it('Test 003: replace framework src', function () {
diff --git a/spec/superspawn.spec.js b/spec/superspawn.spec.js
index 255b238..27898da 100644
--- a/spec/superspawn.spec.js
+++ b/spec/superspawn.spec.js
@@ -23,11 +23,10 @@ var superspawn = require('../src/superspawn');
 var LS = process.platform === 'win32' ? 'dir' : 'ls';
 
 describe('spawn method', function () {
-    var progressSpy, failSpy;
+    var progressSpy;
 
     beforeEach(function () {
         progressSpy = jasmine.createSpy('progress');
-        failSpy = jasmine.createSpy('fail'); /* eslint no-unused-vars : 0 */
     });
 
     it('should resolve on success', () => {
@@ -58,7 +57,7 @@ describe('spawn method', function () {
 
     it('Test 004 : reject handler should pass in Error object with stdout and stderr properties', () => {
         var cp = require('child_process');
-        spyOn(cp, 'spawn').and.callFake(function (cmd, args, opts) {
+        spyOn(cp, 'spawn').and.callFake(() => {
             return {
                 stdout: {
                     setEncoding: function () {},
diff --git a/spec/util/xml-helpers.spec.js b/spec/util/xml-helpers.spec.js
index b629c96..6699ae3 100644
--- a/spec/util/xml-helpers.spec.js
+++ b/spec/util/xml-helpers.spec.js
@@ -17,21 +17,17 @@
     under the License.
 */
 
-/* eslint no-useless-escape : 0 */
-
 var path = require('path');
 var xml_helpers = require('../../src/util/xml-helpers');
 var et = require('elementtree');
 
-/* eslint-disable no-multi-str */
-
 var title = et.XML('<title>HELLO</title>');
-var usesNetworkOne = et.XML('<uses-permission ' +
-            'android:name="PACKAGE_NAME.permission.C2D_MESSAGE"/>');
-var usesNetworkTwo = et.XML('<uses-permission android:name=\
-            "PACKAGE_NAME.permission.C2D_MESSAGE" />');
-var usesReceive = et.XML('<uses-permission android:name=\
-            "com.google.android.c2dm.permission.RECEIVE"/>');
+var usesNetworkOne = et.XML(`<uses-permission
+    android:name="PACKAGE_NAME.permission.C2D_MESSAGE"/>`);
+var usesNetworkTwo = et.XML(`<uses-permission
+    android:name="PACKAGE_NAME.permission.C2D_MESSAGE" />`);
+var usesReceive = et.XML(`<uses-permission
+    android:name="com.google.android.c2dm.permission.RECEIVE"/>`);
 var helloTagOne = et.XML('<h1>HELLO</h1>');
 var goodbyeTag = et.XML('<h1>GOODBYE</h1>');
 var helloTagTwo = et.XML('<h1>  HELLO  </h1>');
@@ -54,8 +50,6 @@ var TEST_XML = '<?xml version="1.0" encoding="UTF-8"?>\n' +
     '    <preference name="webviewbounce" value="true" />\n' +
     '</widget>\n';
 
-/* eslint-enable no-multi-str */
-
 describe('xml-helpers', function () {
     describe('parseElementtreeSync', function () {
         it('Test 001 : should parse xml with a byte order mark', function () {
@@ -179,8 +173,8 @@ describe('xml-helpers', function () {
             var xml = {
                 oldAttrib: { 'android:name': 'com.phonegap.DroidGap', 'android:label': '@string/app_name', 'android:configChanges': 'orientation|keyboardHidden', 'android:enabled': 'true' }
             };
-            xml_helpers.pruneXMLRestore(android_manifest_xml, 'application/activity[@android:name=\"com.phonegap.DroidGap\"]', xml);
-            var activityAttr = android_manifest_xml.find('application/activity[@android:name=\"com.phonegap.DroidGap\"]').attrib;
+            xml_helpers.pruneXMLRestore(android_manifest_xml, 'application/activity[@android:name="com.phonegap.DroidGap"]', xml);
+            var activityAttr = android_manifest_xml.find('application/activity[@android:name="com.phonegap.DroidGap"]').attrib;
             expect(Object.keys(activityAttr).length).toEqual(4);
             expect(activityAttr['android:enabled']).toEqual('true');
         });
@@ -225,33 +219,33 @@ describe('xml-helpers', function () {
             android_manifest_xml = xml_helpers.parseElementtreeSync(path.join(__dirname, '../fixtures/projects/android/AndroidManifest.xml'));
         });
         it('Test 021 : should merge attributes at specified selector', function () {
-            var children = plugin_xml.find('platform/edit-config[@mode=\"merge\"]').getchildren();
-            xml_helpers.graftXMLMerge(android_manifest_xml, children, 'application/activity[@android:name=\"com.phonegap.DroidGap\"]', {});
-            var activityAttr = android_manifest_xml.find('application/activity[@android:name=\"com.phonegap.DroidGap\"]').attrib;
+            var children = plugin_xml.find('platform/edit-config[@mode="merge"]').getchildren();
+            xml_helpers.graftXMLMerge(android_manifest_xml, children, 'application/activity[@android:name="com.phonegap.DroidGap"]', {});
+            var activityAttr = android_manifest_xml.find('application/activity[@android:name="com.phonegap.DroidGap"]').attrib;
             expect(Object.keys(activityAttr).length).toEqual(4);
             expect(activityAttr['android:enabled']).toEqual('true');
             expect(activityAttr['android:configChanges']).toEqual('keyboardHidden');
         });
         it('Test 022 : should be able to handle absolute selectors', function () {
-            var children = plugin_xml.find('platform/edit-config[@mode=\"merge\"]').getchildren();
-            xml_helpers.graftXMLMerge(android_manifest_xml, children, '/manifest/application/activity[@android:name=\"com.phonegap.DroidGap\"]', {});
-            var activityAttr = android_manifest_xml.find('application/activity[@android:name=\"com.phonegap.DroidGap\"]').attrib;
+            var children = plugin_xml.find('platform/edit-config[@mode="merge"]').getchildren();
+            xml_helpers.graftXMLMerge(android_manifest_xml, children, '/manifest/application/activity[@android:name="com.phonegap.DroidGap"]', {});
+            var activityAttr = android_manifest_xml.find('application/activity[@android:name="com.phonegap.DroidGap"]').attrib;
             expect(Object.keys(activityAttr).length).toEqual(4);
             expect(activityAttr['android:enabled']).toEqual('true');
             expect(activityAttr['android:configChanges']).toEqual('keyboardHidden');
         });
         it('Test 023 : should be able to handle absolute selectors with wildcards', function () {
-            var children = plugin_xml.find('platform/edit-config[@mode=\"merge\"]').getchildren();
-            xml_helpers.graftXMLMerge(android_manifest_xml, children, '/*/*/activity[@android:name=\"com.phonegap.DroidGap\"]', {});
-            var activityAttr = android_manifest_xml.find('application/activity[@android:name=\"com.phonegap.DroidGap\"]').attrib;
+            var children = plugin_xml.find('platform/edit-config[@mode="merge"]').getchildren();
+            xml_helpers.graftXMLMerge(android_manifest_xml, children, '/*/*/activity[@android:name="com.phonegap.DroidGap"]', {});
+            var activityAttr = android_manifest_xml.find('application/activity[@android:name="com.phonegap.DroidGap"]').attrib;
             expect(Object.keys(activityAttr).length).toEqual(4);
             expect(activityAttr['android:enabled']).toEqual('true');
             expect(activityAttr['android:configChanges']).toEqual('keyboardHidden');
         });
         it('Test 024 : should be able to handle xpath selectors', function () {
-            var children = plugin_xml.find('platform/edit-config[@mode=\"merge\"]').getchildren();
-            xml_helpers.graftXMLMerge(android_manifest_xml, children, 'application/activity[@android:name=\"com.phonegap.DroidGap\"]', {});
-            var activityAttr = android_manifest_xml.find('application/activity[@android:name=\"com.phonegap.DroidGap\"]').attrib;
+            var children = plugin_xml.find('platform/edit-config[@mode="merge"]').getchildren();
+            xml_helpers.graftXMLMerge(android_manifest_xml, children, 'application/activity[@android:name="com.phonegap.DroidGap"]', {});
+            var activityAttr = android_manifest_xml.find('application/activity[@android:name="com.phonegap.DroidGap"]').attrib;
             expect(Object.keys(activityAttr).length).toEqual(4);
             expect(activityAttr['android:enabled']).toEqual('true');
             expect(activityAttr['android:configChanges']).toEqual('keyboardHidden');
@@ -266,7 +260,7 @@ describe('xml-helpers', function () {
             android_manifest_xml = xml_helpers.parseElementtreeSync(path.join(__dirname, '../fixtures/projects/android/AndroidManifest.xml'));
         });
         it('Test 025 : should overwrite attributes at specified selector', function () {
-            var children = plugin_xml.find('platform/edit-config[@mode=\"overwrite\"]').getchildren();
+            var children = plugin_xml.find('platform/edit-config[@mode="overwrite"]').getchildren();
             xml_helpers.graftXMLOverwrite(android_manifest_xml, children, 'application/activity', {});
             var activityAttr = android_manifest_xml.find('application/activity').attrib;
             expect(Object.keys(activityAttr).length).toEqual(3);
@@ -274,7 +268,7 @@ describe('xml-helpers', function () {
             expect(activityAttr['android:configChanges']).not.toBeDefined();
         });
         it('Test 026 : should be able to handle absolute selectors', function () {
-            var children = plugin_xml.find('platform/edit-config[@mode=\"overwrite\"]').getchildren();
+            var children = plugin_xml.find('platform/edit-config[@mode="overwrite"]').getchildren();
             xml_helpers.graftXMLOverwrite(android_manifest_xml, children, '/manifest/application/activity', {});
             var activityAttr = android_manifest_xml.find('application/activity').attrib;
             expect(Object.keys(activityAttr).length).toEqual(3);
@@ -282,7 +276,7 @@ describe('xml-helpers', function () {
             expect(activityAttr['android:configChanges']).not.toBeDefined();
         });
         it('Test 027 : should be able to handle absolute selectors with wildcards', function () {
-            var children = plugin_xml.find('platform/edit-config[@mode=\"overwrite\"]').getchildren();
+            var children = plugin_xml.find('platform/edit-config[@mode="overwrite"]').getchildren();
             xml_helpers.graftXMLOverwrite(android_manifest_xml, children, '/*/*/activity', {});
             var activityAttr = android_manifest_xml.find('application/activity').attrib;
             expect(Object.keys(activityAttr).length).toEqual(3);
@@ -290,8 +284,8 @@ describe('xml-helpers', function () {
             expect(activityAttr['android:configChanges']).not.toBeDefined();
         });
         it('Test 028 : should be able to handle xpath selectors', function () {
-            var children = plugin_xml.find('platform/edit-config[@mode=\"overwrite\"]').getchildren();
-            xml_helpers.graftXMLOverwrite(android_manifest_xml, children, 'application/activity[@android:name=\"ChildApp\"]', {});
+            var children = plugin_xml.find('platform/edit-config[@mode="overwrite"]').getchildren();
+            xml_helpers.graftXMLOverwrite(android_manifest_xml, children, 'application/activity[@android:name="ChildApp"]', {});
             var activityAttr = android_manifest_xml.find('application/activity').attrib;
             expect(Object.keys(activityAttr).length).toEqual(3);
             expect(activityAttr['android:enabled']).toEqual('true');
diff --git a/src/ConfigChanges/ConfigFile.js b/src/ConfigChanges/ConfigFile.js
index be8f78e..88c1e77 100644
--- a/src/ConfigChanges/ConfigFile.js
+++ b/src/ConfigChanges/ConfigFile.js
@@ -14,8 +14,6 @@
  *
 */
 
-/* eslint no-control-regex: 0 */
-
 var fs = require('fs-extra');
 var path = require('path');
 
@@ -93,7 +91,7 @@ ConfigFile.prototype.save = function ConfigFile_save () {
         fs.writeFileSync(self.filepath, self.data.write({ indent: 4 }), 'utf-8');
     } else {
         // plist
-        var regExp = new RegExp('<string>[ \t\r\n]+?</string>', 'g');
+        var regExp = /<string>[ \t\r\n]+?<\/string>/g;
         fs.writeFileSync(self.filepath, modules.plist.build(self.data, { indent: '\t', offset: -1 }).replace(regExp, '<string></string>'));
     }
     self.is_changed = false;
diff --git a/src/CordovaError/CordovaError.js b/src/CordovaError/CordovaError.js
index 24de6af..428980b 100644
--- a/src/CordovaError/CordovaError.js
+++ b/src/CordovaError/CordovaError.js
@@ -17,8 +17,6 @@
     under the License.
 */
 
-/* eslint no-proto: 0 */
-
 var EOL = require('os').EOL;
 
 /**
@@ -37,6 +35,9 @@ function CordovaError (message, code, context) {
     this.code = code || CordovaError.UNKNOWN_ERROR;
     this.context = context;
 }
+
+// FIXME __proto__ property has been deprecated as of ECMAScript 3.1
+// eslint-disable-next-line no-proto
 CordovaError.prototype.__proto__ = Error.prototype;
 
 // TODO: Extend error codes according the projects specifics
diff --git a/src/PlatformJson.js b/src/PlatformJson.js
index 4060d68..b7a8c77 100644
--- a/src/PlatformJson.js
+++ b/src/PlatformJson.js
@@ -246,7 +246,7 @@ function ModuleMetadata (pluginId, jsModule) {
     if (!pluginId) throw new TypeError('pluginId argument must be a valid plugin id');
     if (!jsModule.src && !jsModule.name) throw new TypeError('jsModule argument must contain src or/and name properties');
 
-    this.id = pluginId + '.' + (jsModule.name || jsModule.src.match(/([^\/]+)\.js/)[1]); /* eslint no-useless-escape: 0 */
+    this.id = pluginId + '.' + (jsModule.name || jsModule.src.match(/([^/]+)\.js/)[1]);
     this.file = ['plugins', pluginId, jsModule.src].join('/');
     this.pluginId = pluginId;
 
diff --git a/src/PluginManager.js b/src/PluginManager.js
index c8f971a..4e9973b 100644
--- a/src/PluginManager.js
+++ b/src/PluginManager.js
@@ -103,9 +103,9 @@ PluginManager.prototype.doOperation = function (operation, plugin, options) {
 
             var action;
             if (operation === PluginManager.INSTALL) {
-                action = actions.createAction.apply(actions, [installer, actionArgs, uninstaller, actionArgs]); /* eslint no-useless-call: 0 */
+                action = actions.createAction(installer, actionArgs, uninstaller, actionArgs);
             } else /* op === PluginManager.UNINSTALL */{
-                action = actions.createAction.apply(actions, [uninstaller, actionArgs, installer, actionArgs]); /* eslint no-useless-call: 0 */
+                action = actions.createAction(uninstaller, actionArgs, installer, actionArgs);
             }
             actions.push(action);
         });
diff --git a/src/util/plist-helpers.js b/src/util/plist-helpers.js
index 0b4fdc1..9e50dbf 100644
--- a/src/util/plist-helpers.js
+++ b/src/util/plist-helpers.js
@@ -16,7 +16,6 @@
     specific language governing permissions and limitations
     under the License.
 */
-/* eslint no-useless-escape: 0 */
 
 // contains PLIST utility functions
 var __ = require('underscore');
@@ -92,5 +91,5 @@ function nodeEqual (node1, node2) {
 
 // escape string for use in regex
 function escapeRE (str) {
-    return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&');
+    return str.replace(/[-[\]/{}()*+?.\\^$|]/g, '\\$&');
 }
diff --git a/src/util/xml-helpers.js b/src/util/xml-helpers.js
index df51583..7221e7a 100644
--- a/src/util/xml-helpers.js
+++ b/src/util/xml-helpers.js
@@ -27,10 +27,8 @@ var _ = require('underscore');
 var et = require('elementtree');
 var stripBom = require('strip-bom');
 
-/* eslint-disable no-useless-escape */
-var ROOT = /^\/([^\/]*)/;
-var ABSOLUTE = /^\/([^\/]*)\/(.*)/;
-/* eslint-enable no-useless-escape */
+var ROOT = /^\/([^/]*)/;
+var ABSOLUTE = /^\/([^/]*)\/(.*)/;
 
 module.exports = {
     // compare two et.XML nodes, see if they match


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