From 893ba08e8fb6c83abc36204e42f5e740d5be5254 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=A8=E3=83=AA=E3=82=B9?= Date: Fri, 26 Jun 2020 19:31:02 +0900 Subject: [PATCH] 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 --- .eslintrc.yml | 23 ++++++++++ .jshintrc | 16 ------- package.json | 6 +-- src/browser/SplashScreenProxy.js | 76 ++++++++++++++++---------------- tests/tests.js | 10 ++--- www/splashscreen.js | 8 ++-- www/windows/SplashScreenProxy.js | 6 +-- 7 files changed, 73 insertions(+), 72 deletions(-) create mode 100644 .eslintrc.yml delete mode 100644 .jshintrc diff --git a/.eslintrc.yml b/.eslintrc.yml new file mode 100644 index 0000000..e651750 --- /dev/null +++ b/.eslintrc.yml @@ -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' diff --git a/.jshintrc b/.jshintrc deleted file mode 100644 index cf48aac..0000000 --- a/.jshintrc +++ /dev/null @@ -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 - } -} diff --git a/package.json b/package.json index 309c214..746ac06 100644 --- a/package.json +++ b/package.json @@ -21,8 +21,8 @@ "cordova-windows" ], "scripts": { - "test": "npm run jshint", - "jshint": "node node_modules/jshint/bin/jshint www && node node_modules/jshint/bin/jshint src && node node_modules/jshint/bin/jshint tests" + "test": "npm run lint", + "lint": "eslint ." }, "engines": { "cordovaDependencies": { @@ -41,7 +41,7 @@ "author": "Apache Software Foundation", "license": "Apache-2.0", "devDependencies": { - "jshint": "^2.6.0" + "@cordova/eslint-config": "^3.0.0" }, "homepage": "https://github.com/apache/cordova-plugin-splashscreen#readme" } diff --git a/src/browser/SplashScreenProxy.js b/src/browser/SplashScreenProxy.js index 1a5cd30..9df6e54 100644 --- a/src/browser/SplashScreenProxy.js +++ b/src/browser/SplashScreenProxy.js @@ -22,10 +22,10 @@ // Default parameter values including image size can be changed in `config.xml` var splashImageWidth = 170; 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 localSplashImage; -var bgColor = "#464646"; +var bgColor = '#464646'; var imageSrc = '/img/logo.png'; var splashScreenDelay = 3000; // in milliseconds var showSplashScreen = true; // show splashcreen by default @@ -33,24 +33,24 @@ var cordova = require('cordova'); var configHelper = cordova.require('cordova/confighelper'); var autoHideSplashScreen = true; -function updateImageLocation() { +function updateImageLocation () { position.width = Math.min(splashImageWidth, window.innerWidth); position.height = position.width * (splashImageHeight / splashImageWidth); - localSplash.style.width = window.innerWidth + "px"; - localSplash.style.height = window.innerHeight + "px"; - localSplash.style.top = "0px"; - localSplash.style.left = "0px"; + localSplash.style.width = window.innerWidth + 'px'; + localSplash.style.height = window.innerHeight + 'px'; + localSplash.style.top = '0px'; + localSplash.style.left = '0px'; - localSplashImage.style.top = "50%"; - localSplashImage.style.left = "50%"; - localSplashImage.style.height = position.height + "px"; - localSplashImage.style.width = position.width + "px"; - localSplashImage.style.marginTop = (-position.height / 2) + "px"; - localSplashImage.style.marginLeft = (-position.width / 2) + "px"; + localSplashImage.style.top = '50%'; + localSplashImage.style.left = '50%'; + localSplashImage.style.height = position.height + 'px'; + localSplashImage.style.width = position.width + 'px'; + localSplashImage.style.marginTop = (-position.height / 2) + 'px'; + localSplashImage.style.marginLeft = (-position.width / 2) + 'px'; } -function onResize() { +function onResize () { updateImageLocation(); } @@ -62,16 +62,16 @@ var SplashScreen = { } }, show: function () { - if(!localSplash) { - window.addEventListener("resize", onResize, false); - localSplash = document.createElement("div"); + if (!localSplash) { + window.addEventListener('resize', onResize, false); + localSplash = document.createElement('div'); localSplash.style.backgroundColor = bgColor; - localSplash.style.position = "absolute"; - localSplash.style["z-index"] = "99999"; + localSplash.style.position = 'absolute'; + localSplash.style['z-index'] = '99999'; - localSplashImage = document.createElement("img"); + localSplashImage = document.createElement('img'); localSplashImage.src = imageSrc; - localSplashImage.style.position = "absolute"; + localSplashImage.style.position = 'absolute'; updateImageLocation(); @@ -88,16 +88,16 @@ var SplashScreen = { } }, hide: function () { - if(localSplash) { + if (localSplash) { var innerLocalSplash = localSplash; localSplash = null; - window.removeEventListener("resize", onResize, false); + window.removeEventListener('resize', onResize, false); innerLocalSplash.style.opacity = '0'; - innerLocalSplash.style["-webkit-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["-o-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['-ms-transition'] = 'opacity 1s ease-in-out'; + innerLocalSplash.style['-o-transition'] = 'opacity 1s ease-in-out'; window.setTimeout(function () { document.body.removeChild(innerLocalSplash); @@ -112,10 +112,10 @@ var SplashScreen = { /** * Reads preferences via ConfigHelper and substitutes default parameters. */ -function readPreferencesFromCfg(cfg) { +function readPreferencesFromCfg (cfg) { try { var value = cfg.getPreferenceValue('ShowSplashScreen'); - if(typeof value != 'undefined') { + if (typeof value !== 'undefined') { showSplashScreen = value === 'true'; } @@ -128,7 +128,7 @@ function readPreferencesFromCfg(cfg) { splashImageHeight = cfg.getPreferenceValue('SplashScreenHeight') || splashImageHeight; autoHideSplashScreen = cfg.getPreferenceValue('AutoHideSplashScreen') || autoHideSplashScreen; 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); 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. */ -function showAndHide() { - if(showSplashScreen) { +function showAndHide () { + if (showSplashScreen) { SplashScreen.show(); - window.setTimeout(function() { + window.setTimeout(function () { SplashScreen.hide(); }, 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. */ -(function initAndShow() { - configHelper.readConfig(function(config) { +(function initAndShow () { + configHelper.readConfig(function (config) { readPreferencesFromCfg(config); if (autoHideSplashScreen) { showAndHide(); } else { SplashScreen.show(); } - - }, function(err) { + }, function (err) { console.error(err); }); })(); module.exports = SplashScreen; -require("cordova/exec/proxy").add("SplashScreen", SplashScreen); - +require('cordova/exec/proxy').add('SplashScreen', SplashScreen); diff --git a/tests/tests.js b/tests/tests.js index 6129692..ecf4889 100644 --- a/tests/tests.js +++ b/tests/tests.js @@ -19,20 +19,18 @@ * */ -/* jshint jasmine: true */ - exports.defineAutoTests = function () { describe('Splashscreen (cordova)', function () { - it("splashscreen.spec.1 should exist", function () { + it('splashscreen.spec.1 should exist', function () { 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(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(typeof navigator.splashscreen.hide).toBe('function'); }); @@ -40,7 +38,7 @@ exports.defineAutoTests = function () { }; exports.defineManualTests = function (contentEl, createActionButton) { - function showFor(duration) { + function showFor (duration) { navigator.splashscreen.show(); window.setTimeout(function () { navigator.splashscreen.hide(); diff --git a/www/splashscreen.js b/www/splashscreen.js index 7cb48bd..8235e8e 100644 --- a/www/splashscreen.js +++ b/www/splashscreen.js @@ -22,11 +22,11 @@ var exec = require('cordova/exec'); var splashscreen = { - show:function() { - exec(null, null, "SplashScreen", "show", []); + show: function () { + exec(null, null, 'SplashScreen', 'show', []); }, - hide:function() { - exec(null, null, "SplashScreen", "hide", []); + hide: function () { + exec(null, null, 'SplashScreen', 'hide', []); } }; diff --git a/www/windows/SplashScreenProxy.js b/www/windows/SplashScreenProxy.js index 1003f06..b359df6 100644 --- a/www/windows/SplashScreenProxy.js +++ b/www/windows/SplashScreenProxy.js @@ -1,4 +1,4 @@ -/* +/* * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -19,8 +19,6 @@ * */ -/*jslint sloppy:true */ - var splash = require('cordova/splashscreen'); var SplashScreen = { @@ -34,4 +32,4 @@ var SplashScreen = { module.exports = SplashScreen; -require("cordova/exec/proxy").add("SplashScreen", SplashScreen); +require('cordova/exec/proxy').add('SplashScreen', SplashScreen);