Skip to content

Commit 7c2810e

Browse files
authored
refactor(eslint): use cordova-eslint /w fix (apache#747)
1 parent bdbb1df commit 7c2810e

File tree

7 files changed

+621
-314
lines changed

7 files changed

+621
-314
lines changed

.eslintrc.yml

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
118
root: true
2-
extends: semistandard
3-
rules:
4-
indent:
5-
- error
6-
- 4
7-
camelcase: off
8-
padded-blocks: off
9-
operator-linebreak: off
10-
no-throw-literal: off
19+
extends: '@cordova/eslint-config/browser'
20+
21+
overrides:
22+
- files: [tests/**/*.js]
23+
extends: '@cordova/eslint-config/node-tests'

package.json

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
"cordova-windows"
3535
],
3636
"scripts": {
37-
"test": "npm run eslint",
38-
"eslint": "node node_modules/eslint/bin/eslint www && node node_modules/eslint/bin/eslint src && node node_modules/eslint/bin/eslint tests"
37+
"test": "npm run lint",
38+
"lint": "eslint ."
3939
},
4040
"engines": {
4141
"cordovaDependencies": {
@@ -54,12 +54,6 @@
5454
"author": "Apache Software Foundation",
5555
"license": "Apache-2.0",
5656
"devDependencies": {
57-
"eslint": "^4.0.0",
58-
"eslint-config-semistandard": "^11.0.0",
59-
"eslint-config-standard": "^10.2.1",
60-
"eslint-plugin-import": "^2.3.0",
61-
"eslint-plugin-node": "^5.0.0",
62-
"eslint-plugin-promise": "^3.5.0",
63-
"eslint-plugin-standard": "^3.0.1"
57+
"@cordova/eslint-config": "^3.0.0"
6458
}
6559
}

src/browser/InAppBrowserProxy.js

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,43 +17,37 @@
1717
* specific language governing permissions and limitations
1818
* under the License.
1919
*
20-
*/
20+
*/
2121

2222
var modulemapper = require('cordova/modulemapper');
2323

24-
var browserWrap,
25-
popup,
26-
navigationButtonsDiv,
27-
navigationButtonsDivInner,
28-
backButton,
29-
forwardButton,
30-
closeButton;
24+
var browserWrap, popup, navigationButtonsDiv, navigationButtonsDivInner, backButton, forwardButton, closeButton;
3125

3226
function attachNavigationEvents (element, callback) {
3327
var onError = function () {
3428
try {
35-
callback({ type: 'loaderror', url: this.contentWindow.location.href }, {keepCallback: true}); // eslint-disable-line standard/no-callback-literal
29+
callback({ type: 'loaderror', url: this.contentWindow.location.href }, { keepCallback: true }); // eslint-disable-line standard/no-callback-literal
3630
} catch (err) {
3731
// blocked by CORS :\
38-
callback({ type: 'loaderror', url: null }, {keepCallback: true}); // eslint-disable-line standard/no-callback-literal
32+
callback({ type: 'loaderror', url: null }, { keepCallback: true }); // eslint-disable-line standard/no-callback-literal
3933
}
4034
};
4135

4236
element.addEventListener('pageshow', function () {
4337
try {
44-
callback({ type: 'loadstart', url: this.contentWindow.location.href }, {keepCallback: true}); // eslint-disable-line standard/no-callback-literal
38+
callback({ type: 'loadstart', url: this.contentWindow.location.href }, { keepCallback: true }); // eslint-disable-line standard/no-callback-literal
4539
} catch (err) {
4640
// blocked by CORS :\
47-
callback({ type: 'loadstart', url: null }, {keepCallback: true}); // eslint-disable-line standard/no-callback-literal
41+
callback({ type: 'loadstart', url: null }, { keepCallback: true }); // eslint-disable-line standard/no-callback-literal
4842
}
4943
});
5044

5145
element.addEventListener('load', function () {
5246
try {
53-
callback({ type: 'loadstop', url: this.contentWindow.location.href }, {keepCallback: true}); // eslint-disable-line standard/no-callback-literal
47+
callback({ type: 'loadstop', url: this.contentWindow.location.href }, { keepCallback: true }); // eslint-disable-line standard/no-callback-literal
5448
} catch (err) {
5549
// blocked by CORS :\
56-
callback({ type: 'loadstop', url: null }, {keepCallback: true}); // eslint-disable-line standard/no-callback-literal
50+
callback({ type: 'loadstop', url: null }, { keepCallback: true }); // eslint-disable-line standard/no-callback-literal
5751
}
5852
});
5953

@@ -153,7 +147,9 @@ var IAB = {
153147

154148
backButton.innerHTML = '←';
155149
backButton.addEventListener('click', function (e) {
156-
if (popup.canGoBack) { popup.goBack(); }
150+
if (popup.canGoBack) {
151+
popup.goBack();
152+
}
157153
});
158154

159155
forwardButton = document.createElement('button');
@@ -164,7 +160,9 @@ var IAB = {
164160

165161
forwardButton.innerHTML = '→';
166162
forwardButton.addEventListener('click', function (e) {
167-
if (popup.canGoForward) { popup.goForward(); }
163+
if (popup.canGoForward) {
164+
popup.goForward();
165+
}
168166
});
169167

170168
closeButton = document.createElement('button');

src/windows/InAppBrowserProxy.js

Lines changed: 48 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,10 @@
1717
* specific language governing permissions and limitations
1818
* under the License.
1919
*
20-
*/
20+
*/
2121

22-
/* jslint sloppy:true */
23-
/* global Windows:true, setImmediate */
24-
/* eslint standard/no-callback-literal : 0 */
22+
/* eslint-disable standard/no-callback-literal */
23+
/* global Windows, setImmediate */
2524

2625
var cordova = require('cordova');
2726
var urlutil = require('cordova/urlutil');
@@ -44,21 +43,32 @@ var isWebViewAvailable = cordova.platformId === 'windows';
4443
function attachNavigationEvents (element, callback) {
4544
if (isWebViewAvailable) {
4645
element.addEventListener('MSWebViewNavigationStarting', function (e) {
47-
callback({ type: 'loadstart', url: e.uri }, {keepCallback: true});
46+
callback({ type: 'loadstart', url: e.uri }, { keepCallback: true });
4847
});
4948

5049
element.addEventListener('MSWebViewNavigationCompleted', function (e) {
5150
if (e.isSuccess) {
5251
callback({ type: 'loadstop', url: e.uri }, { keepCallback: true });
5352
} else {
54-
callback({ type: 'loaderror', url: e.uri, code: e.webErrorStatus, message: 'Navigation failed with error code ' + e.webErrorStatus }, { keepCallback: true });
53+
callback(
54+
{
55+
type: 'loaderror',
56+
url: e.uri,
57+
code: e.webErrorStatus,
58+
message: 'Navigation failed with error code ' + e.webErrorStatus
59+
},
60+
{ keepCallback: true }
61+
);
5562
}
5663
});
5764

5865
element.addEventListener('MSWebViewUnviewableContentIdentified', function (e) {
5966
// WebView found the content to be not HTML.
6067
// http://msdn.microsoft.com/en-us/library/windows/apps/dn609716.aspx
61-
callback({ type: 'loaderror', url: e.uri, code: e.webErrorStatus, message: 'Navigation failed with error code ' + e.webErrorStatus }, { keepCallback: true });
68+
callback(
69+
{ type: 'loaderror', url: e.uri, code: e.webErrorStatus, message: 'Navigation failed with error code ' + e.webErrorStatus },
70+
{ keepCallback: true }
71+
);
6272
});
6373

6474
element.addEventListener('MSWebViewContentLoading', function (e) {
@@ -78,15 +88,15 @@ function attachNavigationEvents (element, callback) {
7888
});
7989
} else {
8090
var onError = function () {
81-
callback({ type: 'loaderror', url: this.contentWindow.location }, {keepCallback: true});
91+
callback({ type: 'loaderror', url: this.contentWindow.location }, { keepCallback: true });
8292
};
8393

8494
element.addEventListener('unload', function () {
85-
callback({ type: 'loadstart', url: this.contentWindow.location }, {keepCallback: true});
95+
callback({ type: 'loadstart', url: this.contentWindow.location }, { keepCallback: true });
8696
});
8797

8898
element.addEventListener('load', function () {
89-
callback({ type: 'loadstop', url: this.contentWindow.location }, {keepCallback: true});
99+
callback({ type: 'loadstop', url: this.contentWindow.location }, { keepCallback: true });
90100
});
91101

92102
element.addEventListener('error', onError);
@@ -175,7 +185,8 @@ var IAB = {
175185
}
176186

177187
popup = document.createElement(isWebViewAvailable ? 'x-ms-webview' : 'iframe');
178-
if (popup instanceof HTMLIFrameElement) { // eslint-disable-line no-undef
188+
if (popup instanceof HTMLIFrameElement) {
189+
// eslint-disable-line no-undef
179190
// For iframe we need to override bacground color of parent element here
180191
// otherwise pages without background color set will have transparent background
181192
popup.style.backgroundColor = 'white';
@@ -240,14 +251,18 @@ var IAB = {
240251
backButton.innerText = 'back';
241252
backButton.className = 'app-bar-action action-back';
242253
backButton.addEventListener('click', function (e) {
243-
if (popup.canGoBack) { popup.goBack(); }
254+
if (popup.canGoBack) {
255+
popup.goBack();
256+
}
244257
});
245258

246259
forwardButton = document.createElement('div');
247260
forwardButton.innerText = 'forward';
248261
forwardButton.className = 'app-bar-action action-forward';
249262
forwardButton.addEventListener('click', function (e) {
250-
if (popup.canGoForward) { popup.goForward(); }
263+
if (popup.canGoForward) {
264+
popup.goForward();
265+
}
251266
});
252267

253268
closeButton = document.createElement('div');
@@ -292,11 +307,11 @@ var IAB = {
292307
op.oncomplete = function (e) {
293308
if (hasCallback) {
294309
// return null if event target is unavailable by some reason
295-
var result = (e && e.target) ? [e.target.result] : [null];
310+
var result = e && e.target ? [e.target.result] : [null];
296311
win(result);
297312
}
298313
};
299-
op.onerror = function () { };
314+
op.onerror = function () {};
300315
op.start();
301316
}
302317
});
@@ -323,7 +338,7 @@ var IAB = {
323338
win(result);
324339
}
325340
};
326-
op.onerror = function () { };
341+
op.onerror = function () {};
327342
op.start();
328343
});
329344
});
@@ -352,13 +367,18 @@ var IAB = {
352367
if (isWebViewAvailable && browserWrap && popup) {
353368
// CB-12364 getFileFromApplicationUriAsync does not support ms-appx-web
354369
var uri = new Windows.Foundation.Uri(filePath.replace('ms-appx-web:', 'ms-appx:'));
355-
Windows.Storage.StorageFile.getFileFromApplicationUriAsync(uri).then(function (file) {
356-
return Windows.Storage.FileIO.readTextAsync(file);
357-
}).done(function (code) {
358-
injectCSS(popup, code, hasCallback && win);
359-
}, function () {
360-
// no-op, just catch an error
361-
});
370+
Windows.Storage.StorageFile.getFileFromApplicationUriAsync(uri)
371+
.then(function (file) {
372+
return Windows.Storage.FileIO.readTextAsync(file);
373+
})
374+
.done(
375+
function (code) {
376+
injectCSS(popup, code, hasCallback && win);
377+
},
378+
function () {
379+
// no-op, just catch an error
380+
}
381+
);
362382
}
363383
});
364384
}
@@ -367,16 +387,18 @@ var IAB = {
367387
function injectCSS (webView, cssCode, callback) {
368388
// This will automatically escape all thing that we need (quotes, slashes, etc.)
369389
var escapedCode = JSON.stringify(cssCode);
370-
var evalWrapper = '(function(d){var c=d.createElement(\'style\');c.innerHTML=%s;d.head.appendChild(c);})(document)'
371-
.replace('%s', escapedCode);
390+
var evalWrapper = "(function(d){var c=d.createElement('style');c.innerHTML=%s;d.head.appendChild(c);})(document)".replace(
391+
'%s',
392+
escapedCode
393+
);
372394

373395
var op = webView.invokeScriptAsync('eval', evalWrapper);
374396
op.oncomplete = function () {
375397
if (callback) {
376398
callback([]);
377399
}
378400
};
379-
op.onerror = function () { };
401+
op.onerror = function () {};
380402
op.start();
381403
}
382404

tests/resources/inject.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
* KIND, either express or implied. See the License for the
1616
* specific language governing permissions and limitations
1717
* under the License.
18-
*/
18+
*/
19+
1920
var d = document.getElementById('header');
2021
d.innerHTML = 'Script file successfully injected';

0 commit comments

Comments
 (0)