From 64097ef5b248d9185710394692696ccf9c4956a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Raphael=20von=20der=20Gr=C3=BCn?= Date: Tue, 18 Jun 2019 02:37:59 +0200 Subject: [PATCH 1/2] Fix ESLint violations where applicable --- 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 | 52 +++++++++++------------- 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, 55 insertions(+), 79 deletions(-) diff --git a/spec/ActionStack.spec.js b/spec/ActionStack.spec.js index 496d73b9..d651dc98 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 e76eab8b..21baa57a 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 a2f13b8d..e3058ed9 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 cac5a68b..8e2a9e77 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 98c617a6..aa2a7c87 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 255b2386..27898da8 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 b629c964..40afa40e 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('HELLO'); var usesNetworkOne = et.XML(''); -var usesNetworkTwo = et.XML(''); -var usesReceive = et.XML(''); +var usesNetworkTwo = et.XML(''); +var usesReceive = et.XML(''); var helloTagOne = et.XML('

HELLO

'); var goodbyeTag = et.XML('

GOODBYE

'); var helloTagTwo = et.XML('

HELLO

'); @@ -54,8 +50,6 @@ var TEST_XML = '\n' + ' \n' + '\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 be8f78e7..88c1e777 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('[ \t\r\n]+?', 'g'); + var regExp = /[ \t\r\n]+?<\/string>/g; fs.writeFileSync(self.filepath, modules.plist.build(self.data, { indent: '\t', offset: -1 }).replace(regExp, '')); } self.is_changed = false; diff --git a/src/CordovaError/CordovaError.js b/src/CordovaError/CordovaError.js index 24de6af1..428980b8 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 4060d680..b7a8c771 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 c8f971a0..4e9973b8 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 0b4fdc1e..9e50dbf8 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 df515833..7221e7ae 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 From 0fb249f81ffa2a3dad57724b3c8ddbbc4898e501 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Raphael=20von=20der=20Gr=C3=BCn?= Date: Thu, 18 Jul 2019 11:56:31 +0200 Subject: [PATCH 2/2] Use multi-line template strings --- spec/util/xml-helpers.spec.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/spec/util/xml-helpers.spec.js b/spec/util/xml-helpers.spec.js index 40afa40e..6699ae3e 100644 --- a/spec/util/xml-helpers.spec.js +++ b/spec/util/xml-helpers.spec.js @@ -22,12 +22,12 @@ var xml_helpers = require('../../src/util/xml-helpers'); var et = require('elementtree'); var title = et.XML('HELLO'); -var usesNetworkOne = et.XML(''); -var usesNetworkTwo = et.XML(''); -var usesReceive = et.XML(''); +var usesNetworkOne = et.XML(``); +var usesNetworkTwo = et.XML(``); +var usesReceive = et.XML(``); var helloTagOne = et.XML('

HELLO

'); var goodbyeTag = et.XML('

GOODBYE

'); var helloTagTwo = et.XML('

HELLO

');