Skip to content
Permalink
Browse files
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.
  • Loading branch information
raphinesse committed Jul 18, 2019
1 parent 5a35287 commit ea24546ea48a7d612b2467c70d6434e5652d816b
Showing 13 changed files with 57 additions and 81 deletions.
@@ -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 () {
@@ -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 () {
@@ -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 () {
@@ -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 () {
@@ -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 () {
@@ -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 () {},
@@ -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,32 +260,32 @@ 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);
expect(activityAttr['android:enabled']).toEqual('true');
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);
expect(activityAttr['android:enabled']).toEqual('true');
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);
expect(activityAttr['android:enabled']).toEqual('true');
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');
@@ -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;
@@ -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
@@ -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;

@@ -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);
});
@@ -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, '\\$&');
}
@@ -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

0 comments on commit ea24546

Please sign in to comment.