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

ESLint cleanup #204

Merged
merged 6 commits into from
Oct 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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 test/build.js → build-tools/test-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const fs = require('fs-extra');
const path = require('path');
const { build, collectModules } = require('../build-tools');
const { build, collectModules } = require('.');

// Istanbul is provided by karma-coverage
const { Instrumenter } = require('istanbul');
Expand Down Expand Up @@ -51,6 +51,6 @@ function collectTestBuildModules () {
});

// Finally, add modules provided by test platform
const testModulesPath = path.join(__dirname, 'test-platform-modules');
const testModulesPath = path.join(__dirname, '../test/test-platform-modules');
return Object.assign(...platformModules, collectModules(testModulesPath));
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"pretest": "npm run build:test",
"test": "npm run eslint && karma start",
"build": "grunt compile",
"build:test": "node test/build.js pkg/cordova.test.js"
"build:test": "node build-tools/test-build pkg/cordova.test.js"
},
"license": "Apache-2.0",
"contributors": [
Expand Down Expand Up @@ -69,6 +69,7 @@
}
],
"dependencies": {
"eslint-plugin-es5": "^1.4.1",
"execa": "^1.0.0",
"fs-extra": "^8.0.1",
"globby": "^9.2.0"
Expand Down
12 changes: 12 additions & 0 deletions src/.eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
extends:
- plugin:es5/no-es2015
- plugin:es5/no-es2016

env:
node: false
commonjs: true
browser: true

globals:
define: false
PLATFORM_VERSION_BUILD_LABEL: false
2 changes: 1 addition & 1 deletion src/common/base64.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ base64.fromArrayBuffer = function (arrayBuffer) {
};

base64.toArrayBuffer = function (str) {
var decodedStr = typeof atob !== 'undefined' ? atob(str) : Buffer.from(str, 'base64').toString('binary'); // eslint-disable-line no-undef
var decodedStr = atob(str);
var arrayBuffer = new ArrayBuffer(decodedStr.length);
var array = new Uint8Array(arrayBuffer);
for (var i = 0, len = decodedStr.length; i < len; i++) {
Expand Down
9 changes: 4 additions & 5 deletions src/common/channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,14 @@ var channel = {
}
if (!len) h();
},
/* eslint-disable no-return-assign */

create: function (type) {
return channel[type] = new Channel(type, false);
return (channel[type] = new Channel(type, false));
},
createSticky: function (type) {
return channel[type] = new Channel(type, true);
return (channel[type] = new Channel(type, true));
},
/* eslint-enable no-return-assign */

/**
* cordova Channels that must fire before "deviceready" is fired.
*/
Expand Down Expand Up @@ -221,7 +221,6 @@ Channel.prototype.unsubscribe = function (eventListenerOrFunction) {
* Calls all functions subscribed to this channel.
*/
Channel.prototype.fire = function (e) {
var fail = false; // eslint-disable-line no-unused-vars
var fireArgs = Array.prototype.slice.call(arguments);
// Apply stickiness.
if (this.state === 1) {
Expand Down
11 changes: 4 additions & 7 deletions src/common/modulemapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/

var builder = require('cordova/builder');
var moduleMap = define.moduleMap; // eslint-disable-line no-undef
var moduleMap = define.moduleMap;
var symbolList;
var deprecationMap;

Expand Down Expand Up @@ -59,12 +59,9 @@ function prepareNamespace (symbolPath, context) {
if (!symbolPath) {
return context;
}
var parts = symbolPath.split('.');
var cur = context;
for (var i = 0, part; part = parts[i]; ++i) { // eslint-disable-line no-cond-assign
cur = cur[part] = cur[part] || {};
}
return cur;
return symbolPath.split('.').reduce(function (cur, part) {
return (cur[part] = cur[part] || {});
}, context);
}

exports.mapModules = function (context) {
Expand Down
6 changes: 3 additions & 3 deletions src/common/pluginloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ exports.injectScript = function (url, onload, onerror) {

function injectIfNecessary (id, url, onload, onerror) {
onerror = onerror || onload;
if (id in define.moduleMap) { // eslint-disable-line no-undef
if (id in define.moduleMap) {
onload();
} else {
exports.injectScript(url, function () {
if (id in define.moduleMap) { // eslint-disable-line no-undef
if (id in define.moduleMap) {
onload();
} else {
onerror();
Expand All @@ -50,7 +50,7 @@ function injectIfNecessary (id, url, onload, onerror) {

function onScriptLoadingComplete (moduleList, finishPluginLoading) {
// Loop through all the plugins and then through their clobbers and merges.
for (var i = 0, module; module = moduleList[i]; i++) { // eslint-disable-line no-cond-assign
for (var i = 0, module; (module = moduleList[i]); i++) {
if (module.clobbers && module.clobbers.length) {
for (var j = 0; j < module.clobbers.length; j++) {
modulemapper.clobbers(module.id, module.clobbers[j]);
Expand Down
9 changes: 5 additions & 4 deletions src/common/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,11 @@ utils.clone = function (obj) {

retVal = {};
for (i in obj) {
// https://issues.apache.org/jira/browse/CB-11522 'unknown' type may be returned in
// custom protocol activation case on Windows Phone 8.1 causing "No such interface supported" exception
// on cloning.
if ((!(i in retVal) || retVal[i] !== obj[i]) && typeof obj[i] !== 'undefined' && typeof obj[i] !== 'unknown') { // eslint-disable-line valid-typeof
// 'unknown' type may be returned in custom protocol activation case on
// Windows Phone 8.1 causing "No such interface supported" exception on
// cloning (https://issues.apache.org/jira/browse/CB-11522)
// eslint-disable-next-line valid-typeof
if ((!(i in retVal) || retVal[i] !== obj[i]) && typeof obj[i] !== 'undefined' && typeof obj[i] !== 'unknown') {
retVal[i] = utils.clone(obj[i]);
}
}
Expand Down
5 changes: 1 addition & 4 deletions src/cordova.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

// Workaround for Windows 10 in hosted environment case
// http://www.w3.org/html/wg/drafts/html/master/browsers.html#named-access-on-the-window-object
if (window.cordova && !(window.cordova instanceof HTMLElement)) { // eslint-disable-line no-undef
if (window.cordova && !(window.cordova instanceof HTMLElement)) {
throw new Error('cordova already defined');
}

Expand Down Expand Up @@ -94,16 +94,13 @@ function createEvent (type, data) {
return event;
}

/* eslint-disable no-undef */
var cordova = {
define: define,
require: require,
version: PLATFORM_VERSION_BUILD_LABEL,
platformVersion: PLATFORM_VERSION_BUILD_LABEL,
platformId: platform.id,

/* eslint-enable no-undef */

/**
* Methods to add/remove your own addEventListener hijacking on document + window.
*/
Expand Down
2 changes: 2 additions & 0 deletions test/.eslintrc.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
env:
node: false
browser: true
jasmine: true

globals:
Expand Down
9 changes: 4 additions & 5 deletions test/android/test.exec.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,11 @@ describe('android exec.processMessages', function () {
// Avoid a log message warning about the lack of _nativeApi.
exec.setJsToNativeBridgeMode(exec.jsToNativeModes.PROMPT);
nativeApiProvider.set(nativeApi);
/* eslint-disable no-undef */
var origPrompt = typeof prompt === 'undefined' ? undefined : prompt;
prompt = function () { return 1234; };

var origPrompt = window.prompt;
window.prompt = function () { return 1234; };
exec.init();
prompt = origPrompt;
/* eslint-enable no-undef */
window.prompt = origPrompt;
});

afterEach(function () {
Expand Down
13 changes: 0 additions & 13 deletions test/ios/test.exec.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,6 @@ describe('iOS exec', function () {
});
});

function simulateNativeBehaviour (codes) { // eslint-disable-line no-unused-vars
var execPayload = JSON.parse(exec.nativeFetchMessages());
while (execPayload.length && codes.length) {
var curPayload = execPayload.shift();
var callbackId = curPayload[0];
var moreResults = exec.nativeCallback(callbackId, codes.shift(), 'payload', false);
if (moreResults) {
execPayload.push.apply(execPayload, JSON.parse(moreResults));
}
}
expect(codes.length).toBe(0, 'Wrong number of results.');
}

describe('exec', function () {
it('Test#001 : should return "" from nativeFetchMessages work when nothing is pending.', function () {
var execPayload = exec.nativeFetchMessages();
Expand Down
4 changes: 4 additions & 0 deletions test/test-platform-modules/.eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
env:
node: false
commonjs: true
browser: true
3 changes: 2 additions & 1 deletion test/test-platform-modules/exec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@
*
*/

module.exports = jasmine.createSpy(); // eslint-disable-line no-undef
/* eslint-env jasmine */
module.exports = jasmine.createSpy();
18 changes: 11 additions & 7 deletions test/test.base64.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,23 @@ describe('base64', function () {
it('Test#002 : can base64 encode a binary string in an ArrayBuffer', function () {
var arrayBuffer = new ArrayBuffer(256);
var view = new Uint8Array(arrayBuffer);
/* eslint-disable no-undef */
base64string = 'AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6PkJGSk5SVlpeYmZqbnJ2en6ChoqOkpaanqKmqq6ytrq+wsbKztLW2t7i5uru8vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5OXm5+jp6uvs7e7v8PHy8/T19vf4+fr7/P3+/w==';

for (var i = 0; i < view.length; i++) {
view[i] = i;
}

expect(base64.fromArrayBuffer(arrayBuffer)).toBe(base64string);
expect(base64.fromArrayBuffer(arrayBuffer)).toBe(
'AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4v' +
'MDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5f' +
'YGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6P' +
'kJGSk5SVlpeYmZqbnJ2en6ChoqOkpaanqKmqq6ytrq+wsbKztLW2t7i5uru8vb6/' +
'wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5OXm5+jp6uvs7e7v' +
'8PHy8/T19vf4+fr7/P3+/w=='
);
});

it('Test#003 : can base64 encode an text string in an ArrayBuffer', function () {
var orig = 'Some Awesome Test This Is!';
var base64string = typeof btoa !== 'undefined' ? btoa(orig) : Buffer.from('Some Awesome Test This Is!', 'binary').toString('base64');
var base64string = btoa(orig);
var arrayBuffer = new ArrayBuffer(orig.length);
var view = new Uint8Array(arrayBuffer);

Expand All @@ -64,8 +68,8 @@ describe('base64', function () {

it('Test#004 : can decode a base64-encoded text string into an ArrayBuffer', function () {
var orig = 'Some Awesome Test This Is!';
var base64string = typeof btoa !== 'undefined' ? btoa(orig) : Buffer.from(orig, 'binary').toString('base64');
/* eslint-enable no-undef */
var base64string = btoa(orig);

var arrayBuffer = base64.toArrayBuffer(base64string);

var testString = '';
Expand Down
6 changes: 3 additions & 3 deletions test/test.pluginloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ describe('pluginloader', function () {
injectScript.and.callFake(function (url, onload, onerror) {
// jsdom deficiencies:
if (typeof location !== 'undefined') {
expect(url).toBe(window.location.href.replace(/\/[^\/]*?$/, '/foo/cordova_plugins.js')); // eslint-disable-line no-useless-escape
expect(url).toBe(window.location.href.replace(/\/[^/]*?$/, '/foo/cordova_plugins.js'));
} else {
expect(url).toBe('foo/cordova_plugins.js');
}
/* eslint-disable no-undef */

define('cordova/plugin_list', function (require, exports, module) {
module.exports = [];
});
Expand Down Expand Up @@ -79,7 +79,7 @@ describe('pluginloader', function () {
injectScript.and.callFake(function (url, onload, onerror) {
// jsdom deficiencies:
if (typeof location !== 'undefined') {
expect(url).toBe(window.location.href.replace(/\/[^\/]*?$/, '/foo/some/path.js')); // eslint-disable-line no-useless-escape
expect(url).toBe(window.location.href.replace(/\/[^/]*?$/, '/foo/some/path.js'));
} else {
expect(url).toBe('foo/some/path.js');
}
Expand Down
2 changes: 1 addition & 1 deletion test/test.urlutil.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('urlutil', function () {
});

it('Test#003 : can handle relative URLs', function () {
var rootUrl = window.location.href.replace(/[?#].*/, '').replace(/[^\/]*$/, ''); // eslint-disable-line no-useless-escape
var rootUrl = window.location.href.replace(/[?#].*/, '').replace(/[^/]*$/, '');
expect(urlutil.makeAbsolute('foo?a#b')).toBe(rootUrl + 'foo?a#b');
expect(urlutil.makeAbsolute('foo/b%20ar')).toBe(rootUrl + 'foo/b%20ar');
});
Expand Down
3 changes: 2 additions & 1 deletion test/test.utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ describe('utils', function () {
expect(isArray).toBe(true);
});
it('Test#009 : should return true for new Array().', function () {
var isArray = utils.isArray(new Array()); // eslint-disable-line no-array-constructor
// eslint-disable-next-line no-array-constructor
var isArray = utils.isArray(new Array());
expect(isArray).toBe(true);
});
it('Test#010 : should return false for {}.', function () {
Expand Down