Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ESLint violations where applicable #83

Merged
merged 2 commits into from
Jul 18, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions spec/ActionStack.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
2 changes: 1 addition & 1 deletion spec/ConfigChanges/ConfigChanges.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
3 changes: 1 addition & 2 deletions spec/ConfigParser/ConfigParser.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
2 changes: 1 addition & 1 deletion spec/PlatformJson.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
42 changes: 15 additions & 27 deletions spec/PluginInfo/PluginInfo.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
5 changes: 2 additions & 3 deletions spec/superspawn.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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 () {},
Expand Down
52 changes: 23 additions & 29 deletions spec/util/xml-helpers.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 usesNetworkTwo = et.XML('<uses-permission ' +
raphinesse marked this conversation as resolved.
Show resolved Hide resolved
'android:name="PACKAGE_NAME.permission.C2D_MESSAGE" />');
var usesReceive = et.XML('<uses-permission ' +
raphinesse marked this conversation as resolved.
Show resolved Hide resolved
'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>');
Expand All @@ -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 () {
Expand Down Expand Up @@ -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');
});
Expand Down Expand Up @@ -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');
Expand All @@ -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');
Expand Down
4 changes: 1 addition & 3 deletions src/ConfigChanges/ConfigFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
*
*/

/* eslint no-control-regex: 0 */

var fs = require('fs-extra');
var path = require('path');

Expand Down Expand Up @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions src/CordovaError/CordovaError.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
under the License.
*/

/* eslint no-proto: 0 */

var EOL = require('os').EOL;

/**
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/PlatformJson.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions src/PluginManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
3 changes: 1 addition & 2 deletions src/util/plist-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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, '\\$&');
}
6 changes: 2 additions & 4 deletions src/util/xml-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down