breaking: replace jshint with eslint (#277)

* breaking: remove jshint files and references
* breaking: swap jshint with eslint
* chore: apply eslint auto corrections
* chore: remove jslint inline ignore rule
This commit is contained in:
エリス 2020-06-26 19:31:02 +09:00 committed by GitHub
parent 369f8d148f
commit 893ba08e8f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 73 additions and 72 deletions

23
.eslintrc.yml Normal file
View File

@ -0,0 +1,23 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
root: true
extends: '@cordova/eslint-config/browser'
overrides:
- files: [tests/**/*.js]
extends: '@cordova/eslint-config/node-tests'

View File

@ -1,16 +0,0 @@
{
"browser": true
, "devel": true
, "bitwise": true
, "undef": true
, "trailing": true
, "quotmark": false
, "indent": 4
, "unused": "vars"
, "latedef": "nofunc"
, "globals": {
"module": false,
"exports": false,
"require": false
}
}

View File

@ -21,8 +21,8 @@
"cordova-windows" "cordova-windows"
], ],
"scripts": { "scripts": {
"test": "npm run jshint", "test": "npm run lint",
"jshint": "node node_modules/jshint/bin/jshint www && node node_modules/jshint/bin/jshint src && node node_modules/jshint/bin/jshint tests" "lint": "eslint ."
}, },
"engines": { "engines": {
"cordovaDependencies": { "cordovaDependencies": {
@ -41,7 +41,7 @@
"author": "Apache Software Foundation", "author": "Apache Software Foundation",
"license": "Apache-2.0", "license": "Apache-2.0",
"devDependencies": { "devDependencies": {
"jshint": "^2.6.0" "@cordova/eslint-config": "^3.0.0"
}, },
"homepage": "https://github.com/apache/cordova-plugin-splashscreen#readme" "homepage": "https://github.com/apache/cordova-plugin-splashscreen#readme"
} }

View File

@ -22,10 +22,10 @@
// Default parameter values including image size can be changed in `config.xml` // Default parameter values including image size can be changed in `config.xml`
var splashImageWidth = 170; var splashImageWidth = 170;
var splashImageHeight = 200; var splashImageHeight = 200;
var position = { x: 0, y: 0, width: splashImageWidth, height: splashImageHeight }; var position = { x: 0, y: 0, width: splashImageWidth, height: splashImageHeight };
var localSplash; // the image to display var localSplash; // the image to display
var localSplashImage; var localSplashImage;
var bgColor = "#464646"; var bgColor = '#464646';
var imageSrc = '/img/logo.png'; var imageSrc = '/img/logo.png';
var splashScreenDelay = 3000; // in milliseconds var splashScreenDelay = 3000; // in milliseconds
var showSplashScreen = true; // show splashcreen by default var showSplashScreen = true; // show splashcreen by default
@ -33,24 +33,24 @@ var cordova = require('cordova');
var configHelper = cordova.require('cordova/confighelper'); var configHelper = cordova.require('cordova/confighelper');
var autoHideSplashScreen = true; var autoHideSplashScreen = true;
function updateImageLocation() { function updateImageLocation () {
position.width = Math.min(splashImageWidth, window.innerWidth); position.width = Math.min(splashImageWidth, window.innerWidth);
position.height = position.width * (splashImageHeight / splashImageWidth); position.height = position.width * (splashImageHeight / splashImageWidth);
localSplash.style.width = window.innerWidth + "px"; localSplash.style.width = window.innerWidth + 'px';
localSplash.style.height = window.innerHeight + "px"; localSplash.style.height = window.innerHeight + 'px';
localSplash.style.top = "0px"; localSplash.style.top = '0px';
localSplash.style.left = "0px"; localSplash.style.left = '0px';
localSplashImage.style.top = "50%"; localSplashImage.style.top = '50%';
localSplashImage.style.left = "50%"; localSplashImage.style.left = '50%';
localSplashImage.style.height = position.height + "px"; localSplashImage.style.height = position.height + 'px';
localSplashImage.style.width = position.width + "px"; localSplashImage.style.width = position.width + 'px';
localSplashImage.style.marginTop = (-position.height / 2) + "px"; localSplashImage.style.marginTop = (-position.height / 2) + 'px';
localSplashImage.style.marginLeft = (-position.width / 2) + "px"; localSplashImage.style.marginLeft = (-position.width / 2) + 'px';
} }
function onResize() { function onResize () {
updateImageLocation(); updateImageLocation();
} }
@ -62,16 +62,16 @@ var SplashScreen = {
} }
}, },
show: function () { show: function () {
if(!localSplash) { if (!localSplash) {
window.addEventListener("resize", onResize, false); window.addEventListener('resize', onResize, false);
localSplash = document.createElement("div"); localSplash = document.createElement('div');
localSplash.style.backgroundColor = bgColor; localSplash.style.backgroundColor = bgColor;
localSplash.style.position = "absolute"; localSplash.style.position = 'absolute';
localSplash.style["z-index"] = "99999"; localSplash.style['z-index'] = '99999';
localSplashImage = document.createElement("img"); localSplashImage = document.createElement('img');
localSplashImage.src = imageSrc; localSplashImage.src = imageSrc;
localSplashImage.style.position = "absolute"; localSplashImage.style.position = 'absolute';
updateImageLocation(); updateImageLocation();
@ -88,16 +88,16 @@ var SplashScreen = {
} }
}, },
hide: function () { hide: function () {
if(localSplash) { if (localSplash) {
var innerLocalSplash = localSplash; var innerLocalSplash = localSplash;
localSplash = null; localSplash = null;
window.removeEventListener("resize", onResize, false); window.removeEventListener('resize', onResize, false);
innerLocalSplash.style.opacity = '0'; innerLocalSplash.style.opacity = '0';
innerLocalSplash.style["-webkit-transition"] = "opacity 1s ease-in-out"; innerLocalSplash.style['-webkit-transition'] = 'opacity 1s ease-in-out';
innerLocalSplash.style["-moz-transition"] = "opacity 1s ease-in-out"; innerLocalSplash.style['-moz-transition'] = 'opacity 1s ease-in-out';
innerLocalSplash.style["-ms-transition"] = "opacity 1s ease-in-out"; innerLocalSplash.style['-ms-transition'] = 'opacity 1s ease-in-out';
innerLocalSplash.style["-o-transition"] = "opacity 1s ease-in-out"; innerLocalSplash.style['-o-transition'] = 'opacity 1s ease-in-out';
window.setTimeout(function () { window.setTimeout(function () {
document.body.removeChild(innerLocalSplash); document.body.removeChild(innerLocalSplash);
@ -112,10 +112,10 @@ var SplashScreen = {
/** /**
* Reads preferences via ConfigHelper and substitutes default parameters. * Reads preferences via ConfigHelper and substitutes default parameters.
*/ */
function readPreferencesFromCfg(cfg) { function readPreferencesFromCfg (cfg) {
try { try {
var value = cfg.getPreferenceValue('ShowSplashScreen'); var value = cfg.getPreferenceValue('ShowSplashScreen');
if(typeof value != 'undefined') { if (typeof value !== 'undefined') {
showSplashScreen = value === 'true'; showSplashScreen = value === 'true';
} }
@ -128,7 +128,7 @@ function readPreferencesFromCfg(cfg) {
splashImageHeight = cfg.getPreferenceValue('SplashScreenHeight') || splashImageHeight; splashImageHeight = cfg.getPreferenceValue('SplashScreenHeight') || splashImageHeight;
autoHideSplashScreen = cfg.getPreferenceValue('AutoHideSplashScreen') || autoHideSplashScreen; autoHideSplashScreen = cfg.getPreferenceValue('AutoHideSplashScreen') || autoHideSplashScreen;
autoHideSplashScreen = (autoHideSplashScreen === true || autoHideSplashScreen.toLowerCase() === 'true'); autoHideSplashScreen = (autoHideSplashScreen === true || autoHideSplashScreen.toLowerCase() === 'true');
} catch(e) { } catch (e) {
var msg = '[Browser][SplashScreen] Error occurred on loading preferences from config.xml: ' + JSON.stringify(e); var msg = '[Browser][SplashScreen] Error occurred on loading preferences from config.xml: ' + JSON.stringify(e);
console.error(msg); console.error(msg);
} }
@ -137,11 +137,11 @@ function readPreferencesFromCfg(cfg) {
/** /**
* Shows and hides splashscreen if it is enabled, with a delay according the current preferences. * Shows and hides splashscreen if it is enabled, with a delay according the current preferences.
*/ */
function showAndHide() { function showAndHide () {
if(showSplashScreen) { if (showSplashScreen) {
SplashScreen.show(); SplashScreen.show();
window.setTimeout(function() { window.setTimeout(function () {
SplashScreen.hide(); SplashScreen.hide();
}, splashScreenDelay); }, splashScreenDelay);
} }
@ -150,21 +150,19 @@ function showAndHide() {
/** /**
* Tries to read config.xml and override default properties and then shows and hides splashscreen if it is enabled. * Tries to read config.xml and override default properties and then shows and hides splashscreen if it is enabled.
*/ */
(function initAndShow() { (function initAndShow () {
configHelper.readConfig(function(config) { configHelper.readConfig(function (config) {
readPreferencesFromCfg(config); readPreferencesFromCfg(config);
if (autoHideSplashScreen) { if (autoHideSplashScreen) {
showAndHide(); showAndHide();
} else { } else {
SplashScreen.show(); SplashScreen.show();
} }
}, function (err) {
}, function(err) {
console.error(err); console.error(err);
}); });
})(); })();
module.exports = SplashScreen; module.exports = SplashScreen;
require("cordova/exec/proxy").add("SplashScreen", SplashScreen); require('cordova/exec/proxy').add('SplashScreen', SplashScreen);

View File

@ -19,20 +19,18 @@
* *
*/ */
/* jshint jasmine: true */
exports.defineAutoTests = function () { exports.defineAutoTests = function () {
describe('Splashscreen (cordova)', function () { describe('Splashscreen (cordova)', function () {
it("splashscreen.spec.1 should exist", function () { it('splashscreen.spec.1 should exist', function () {
expect(navigator.splashscreen).toBeDefined(); expect(navigator.splashscreen).toBeDefined();
}); });
it("splashscreen.spec.2 show method should exist", function () { it('splashscreen.spec.2 show method should exist', function () {
expect(navigator.splashscreen.show).toBeDefined(); expect(navigator.splashscreen.show).toBeDefined();
expect(typeof navigator.splashscreen.show).toBe('function'); expect(typeof navigator.splashscreen.show).toBe('function');
}); });
it("splashscreen.spec.3 hide method should exist", function () { it('splashscreen.spec.3 hide method should exist', function () {
expect(navigator.splashscreen.hide).toBeDefined(); expect(navigator.splashscreen.hide).toBeDefined();
expect(typeof navigator.splashscreen.hide).toBe('function'); expect(typeof navigator.splashscreen.hide).toBe('function');
}); });
@ -40,7 +38,7 @@ exports.defineAutoTests = function () {
}; };
exports.defineManualTests = function (contentEl, createActionButton) { exports.defineManualTests = function (contentEl, createActionButton) {
function showFor(duration) { function showFor (duration) {
navigator.splashscreen.show(); navigator.splashscreen.show();
window.setTimeout(function () { window.setTimeout(function () {
navigator.splashscreen.hide(); navigator.splashscreen.hide();

View File

@ -22,11 +22,11 @@
var exec = require('cordova/exec'); var exec = require('cordova/exec');
var splashscreen = { var splashscreen = {
show:function() { show: function () {
exec(null, null, "SplashScreen", "show", []); exec(null, null, 'SplashScreen', 'show', []);
}, },
hide:function() { hide: function () {
exec(null, null, "SplashScreen", "hide", []); exec(null, null, 'SplashScreen', 'hide', []);
} }
}; };

View File

@ -1,4 +1,4 @@
/* /*
* *
* Licensed to the Apache Software Foundation (ASF) under one * Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file * or more contributor license agreements. See the NOTICE file
@ -19,8 +19,6 @@
* *
*/ */
/*jslint sloppy:true */
var splash = require('cordova/splashscreen'); var splash = require('cordova/splashscreen');
var SplashScreen = { var SplashScreen = {
@ -34,4 +32,4 @@ var SplashScreen = {
module.exports = SplashScreen; module.exports = SplashScreen;
require("cordova/exec/proxy").add("SplashScreen", SplashScreen); require('cordova/exec/proxy').add('SplashScreen', SplashScreen);