diff --git a/.eslintrc.yml b/.eslintrc.yml index f6aae321c..31281afba 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -1,10 +1,26 @@ +# 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: semistandard -rules: - indent: - - error - - 4 - camelcase: off - padded-blocks: off - operator-linebreak: off - no-throw-literal: off +extends: '@cordova/eslint-config/node' + +overrides: + - files: [tests/spec/**/*.js] + extends: '@cordova/eslint-config/node-tests' + + - files: [cordova-js-src/**/*.js] + extends: '@cordova/eslint-config/browser' diff --git a/.travis.yml b/.travis.yml index 629c21e45..576aa4ac4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,7 +22,7 @@ install: script: - node --version - npm --version - - npm run eslint + - npm run lint - npm run unit-tests - npm run test:component - npm run e2e-tests diff --git a/appveyor.yml b/appveyor.yml index a3a77f248..9e7c6ac1b 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -12,5 +12,5 @@ build: off test_script: - node --version - npm --version + - npm run lint - npm run unit-tests - - npm run eslint diff --git a/bin/create b/bin/create index 088ff933c..f8c148c7d 100755 --- a/bin/create +++ b/bin/create @@ -34,11 +34,11 @@ var ConfigParser = require('cordova-common').ConfigParser; var Api = require('./templates/scripts/cordova/Api'); var argv = require('nopt')({ - 'help': Boolean, - 'cli': Boolean, - 'shared': Boolean, // alias for --link - 'link': Boolean -}, { 'd': '--verbose' }); + help: Boolean, + cli: Boolean, + shared: Boolean, // alias for --link + link: Boolean +}, { d: '--verbose' }); var projectPath = argv.argv.remain[0]; diff --git a/bin/lib/create.js b/bin/lib/create.js index 88f48e9b6..6842869bc 100755 --- a/bin/lib/create.js +++ b/bin/lib/create.js @@ -75,7 +75,7 @@ function copyScripts (projectPath, projectName) { var binDir = path.join(ROOT, 'bin'); shell.cp('-r', srcScriptsDir, projectPath); - let nodeModulesDir = path.join(ROOT, 'node_modules'); + const nodeModulesDir = path.join(ROOT, 'node_modules'); if (fs.existsSync(nodeModulesDir)) shell.cp('-r', nodeModulesDir, destScriptsDir); // Copy the check_reqs script diff --git a/bin/templates/scripts/cordova/Api.js b/bin/templates/scripts/cordova/Api.js index e45b7822c..19de9ff9f 100644 --- a/bin/templates/scripts/cordova/Api.js +++ b/bin/templates/scripts/cordova/Api.js @@ -66,7 +66,6 @@ function Api (platform, platformRootDir, events) { var xcodeCordovaProj; try { - var xcodeProjDir_array = fs.readdirSync(this.root).filter(function (e) { return e.match(/\.xcodeproj$/i); }); if (xcodeProjDir_array.length > 1) { for (var x = 0; x < xcodeProjDir_array.length; x++) { @@ -230,7 +229,6 @@ Api.prototype.prepare = function (cordovaProject) { * CordovaError instance. */ Api.prototype.addPlugin = function (plugin, installOptions) { - var xcodeproj = projectFile.parse(this.locations); var self = this; @@ -401,7 +399,6 @@ Api.prototype.addPodSpecs = function (plugin, podSpecs, frameworkPods) { podfileFile.addSpec(podJson.name, podJson); } }); - }); } @@ -525,7 +522,6 @@ Api.prototype.removePodSpecs = function (plugin, podSpecs, frameworkPods) { podfileFile.removeSpec(podJson.name); } }); - }); } diff --git a/bin/templates/scripts/cordova/build b/bin/templates/scripts/cordova/build index e795d13dd..507e80e61 100755 --- a/bin/templates/scripts/cordova/build +++ b/bin/templates/scripts/cordova/build @@ -31,23 +31,23 @@ if (['--help', '/?', '-h', 'help', '-help', '/help'].indexOf(process.argv[2]) >= // Parse arguments var buildOpts = nopt({ - 'verbose': Boolean, - 'silent': Boolean, - 'archs': String, - 'debug': Boolean, - 'release': Boolean, - 'device': Boolean, - 'emulator': Boolean, - 'codeSignIdentity': String, - 'codeSignResourceRules': String, - 'provisioningProfile': String, - 'automaticProvisioning': Boolean, - 'developmentTeam': String, - 'packageType': String, - 'buildConfig': String, - 'buildFlag': [String, Array], - 'noSign': Boolean -}, { '-r': '--release', 'd': '--verbose' }, args); + verbose: Boolean, + silent: Boolean, + archs: String, + debug: Boolean, + release: Boolean, + device: Boolean, + emulator: Boolean, + codeSignIdentity: String, + codeSignResourceRules: String, + provisioningProfile: String, + automaticProvisioning: Boolean, + developmentTeam: String, + packageType: String, + buildConfig: String, + buildFlag: [String, Array], + noSign: Boolean +}, { '-r': '--release', d: '--verbose' }, args); // Make buildOptions compatible with PlatformApi build method spec buildOpts.argv = buildOpts.argv.remain; diff --git a/bin/templates/scripts/cordova/clean b/bin/templates/scripts/cordova/clean index ccd4a56d5..6699e4741 100755 --- a/bin/templates/scripts/cordova/clean +++ b/bin/templates/scripts/cordova/clean @@ -29,9 +29,9 @@ if (['--help', '/?', '-h', 'help', '-help', '/help'].indexOf(process.argv[2]) >= // Do some basic argument parsing var opts = nopt({ - 'verbose': Boolean, - 'silent': Boolean -}, { 'd': '--verbose' }); + verbose: Boolean, + silent: Boolean +}, { d: '--verbose' }); // Make buildOptions compatible with PlatformApi clean method spec opts.argv = opts.argv.original; diff --git a/bin/templates/scripts/cordova/lib/build.js b/bin/templates/scripts/cordova/lib/build.js index f8d301dfd..1e2684e45 100644 --- a/bin/templates/scripts/cordova/lib/build.js +++ b/bin/templates/scripts/cordova/lib/build.js @@ -33,14 +33,14 @@ var events = require('cordova-common').events; // These are regular expressions to detect if the user is changing any of the built-in xcodebuildArgs /* eslint-disable no-useless-escape */ var buildFlagMatchers = { - 'workspace': /^\-workspace\s*(.*)/, - 'scheme': /^\-scheme\s*(.*)/, - 'configuration': /^\-configuration\s*(.*)/, - 'sdk': /^\-sdk\s*(.*)/, - 'destination': /^\-destination\s*(.*)/, - 'archivePath': /^\-archivePath\s*(.*)/, - 'configuration_build_dir': /^(CONFIGURATION_BUILD_DIR=.*)/, - 'shared_precomps_dir': /^(SHARED_PRECOMPS_DIR=.*)/ + workspace: /^\-workspace\s*(.*)/, + scheme: /^\-scheme\s*(.*)/, + configuration: /^\-configuration\s*(.*)/, + sdk: /^\-sdk\s*(.*)/, + destination: /^\-destination\s*(.*)/, + archivePath: /^\-archivePath\s*(.*)/, + configuration_build_dir: /^(CONFIGURATION_BUILD_DIR=.*)/, + shared_precomps_dir: /^(SHARED_PRECOMPS_DIR=.*)/ }; /* eslint-enable no-useless-escape */ @@ -227,7 +227,6 @@ module.exports.run = function (buildOpts) { var xcodebuildArgs = getXcodeBuildArgs(projectName, projectPath, configuration, buildOpts.device, buildOpts.buildFlag, emulatorTarget, buildOpts.automaticProvisioning); return superspawn.spawn('xcodebuild', xcodebuildArgs, { cwd: projectPath, printCommand: true, stdio: 'inherit' }); - }).then(function () { if (!buildOpts.device || buildOpts.noSign) { return; @@ -235,7 +234,7 @@ module.exports.run = function (buildOpts) { var project = createProjectObject(projectPath, projectName); var bundleIdentifier = getBundleIdentifier(project); - var exportOptions = { 'compileBitcode': false, 'method': 'development' }; + var exportOptions = { compileBitcode: false, method: 'development' }; if (buildOpts.packageType) { exportOptions.method = buildOpts.packageType; @@ -250,7 +249,7 @@ module.exports.run = function (buildOpts) { } if (buildOpts.provisioningProfile && bundleIdentifier) { - exportOptions.provisioningProfiles = { [ bundleIdentifier ]: String(buildOpts.provisioningProfile) }; + exportOptions.provisioningProfiles = { [bundleIdentifier]: String(buildOpts.provisioningProfile) }; exportOptions.signingStyle = 'manual'; } @@ -346,7 +345,7 @@ function getXcodeBuildArgs (projectName, projectPath, configuration, isDevice, b '-destination', customArgs.destination || 'generic/platform=iOS', '-archivePath', customArgs.archivePath || projectName + '.xcarchive' ]; - buildActions = [ 'archive' ]; + buildActions = ['archive']; settings = [ customArgs.configuration_build_dir || 'CONFIGURATION_BUILD_DIR=' + path.join(projectPath, 'build', 'device'), customArgs.shared_precomps_dir || 'SHARED_PRECOMPS_DIR=' + path.join(projectPath, 'build', 'sharedpch') @@ -368,7 +367,7 @@ function getXcodeBuildArgs (projectName, projectPath, configuration, isDevice, b '-sdk', customArgs.sdk || 'iphonesimulator', '-destination', customArgs.destination || 'platform=iOS Simulator,name=' + emulatorTarget ]; - buildActions = [ 'build' ]; + buildActions = ['build']; settings = [ customArgs.configuration_build_dir || 'CONFIGURATION_BUILD_DIR=' + path.join(projectPath, 'build', 'emulator'), customArgs.shared_precomps_dir || 'SHARED_PRECOMPS_DIR=' + path.join(projectPath, 'build', 'sharedpch') diff --git a/bin/templates/scripts/cordova/lib/check_reqs.js b/bin/templates/scripts/cordova/lib/check_reqs.js index f786fc46a..6356df92e 100644 --- a/bin/templates/scripts/cordova/lib/check_reqs.js +++ b/bin/templates/scripts/cordova/lib/check_reqs.js @@ -24,7 +24,7 @@ const shell = require('shelljs'); const util = require('util'); const versions = require('./versions'); -const SUPPORTED_OS_PLATFORMS = [ 'darwin' ]; +const SUPPORTED_OS_PLATFORMS = ['darwin']; const XCODEBUILD_MIN_VERSION = '9.0.0'; const XCODEBUILD_NOT_FOUND_MESSAGE = @@ -63,9 +63,9 @@ module.exports.check_ios_deploy = function () { module.exports.check_os = function () { // Build iOS apps available for OSX platform only, so we reject on others platforms - return os_platform_is_supported() ? - Q.resolve(process.platform) : - Q.reject('Cordova tooling for iOS requires Apple macOS'); + return os_platform_is_supported() + ? Q.resolve(process.platform) + : Q.reject('Cordova tooling for iOS requires Apple macOS'); }; function os_platform_is_supported () { @@ -78,8 +78,8 @@ function check_cocoapod_tool (toolChecker) { return toolChecker('pod', COCOAPODS_MIN_VERSION, COCOAPODS_NOT_FOUND_MESSAGE, 'CocoaPods'); } else { return Q.resolve({ - 'ignore': true, - 'ignoreMessage': `CocoaPods check and installation ignored on ${process.platform}` + ignore: true, + ignoreMessage: `CocoaPods check and installation ignored on ${process.platform}` }); } } @@ -92,10 +92,10 @@ module.exports.check_cocoapods_repo_size = function () { return check_cocoapod_tool() .then(function (toolOptions) { // check size of ~/.cocoapods repo - let commandString = util.format('du -sh %s/.cocoapods', process.env.HOME); - let command = shell.exec(commandString, { silent: true }); + const commandString = util.format('du -sh %s/.cocoapods', process.env.HOME); + const command = shell.exec(commandString, { silent: true }); // command.output is e.g "750M path/to/.cocoapods", we just scan the number - let size = toolOptions.ignore ? 0 : parseFloat(command.output); + const size = toolOptions.ignore ? 0 : parseFloat(command.output); if (toolOptions.ignore || command.code === 0) { // success, parse output return Q.resolve(size, toolOptions); @@ -128,8 +128,8 @@ module.exports.check_cocoapods = function (toolChecker) { return toolOptions; } - let code = shell.exec('pod repo | grep -e "^0 repos"', { silent: true }).code; - let repoIsSynced = (code !== 0); + const code = shell.exec('pod repo | grep -e "^0 repos"', { silent: true }).code; + const repoIsSynced = (code !== 0); if (repoIsSynced) { // return check_cocoapods_repo_size(); @@ -153,7 +153,7 @@ function checkTool (tool, minVersion, message, toolFriendlyName) { toolFriendlyName = toolFriendlyName || tool; // Check whether tool command is available at all - let tool_command = shell.which(tool); + const tool_command = shell.which(tool); if (!tool_command) { return Q.reject(toolFriendlyName + ' was not found. ' + (message || '')); } @@ -161,9 +161,9 @@ function checkTool (tool, minVersion, message, toolFriendlyName) { // check if tool version is greater than specified one return versions.get_tool_version(tool).then(function (version) { version = version.trim(); - return versions.compareVersions(version, minVersion) >= 0 ? - Q.resolve({ 'version': version }) : - Q.reject('Cordova needs ' + toolFriendlyName + ' version ' + minVersion + + return versions.compareVersions(version, minVersion) >= 0 + ? Q.resolve({ version: version }) + : Q.reject('Cordova needs ' + toolFriendlyName + ' version ' + minVersion + ' or greater, you have version ' + version + '. ' + (message || '')); }); } @@ -175,7 +175,7 @@ function checkTool (tool, minVersion, message, toolFriendlyName) { * @param {Boolean} isFatal Marks the requirement as fatal. If such requirement will fail * next requirements' checks will be skipped. */ -let Requirement = function (id, name, isFatal) { +const Requirement = function (id, name, isFatal) { this.id = id; this.name = name; this.installed = false; @@ -190,7 +190,6 @@ let Requirement = function (id, name, isFatal) { * @return Promise Array of requirements. Due to implementation, promise is always fulfilled. */ module.exports.check_all = function () { - const requirements = [ new Requirement('os', 'Apple macOS', true), new Requirement('xcode', 'Xcode'), @@ -198,10 +197,10 @@ module.exports.check_all = function () { new Requirement('CocoaPods', 'CocoaPods') ]; - let result = []; + const result = []; let fatalIsHit = false; - let checkFns = [ + const checkFns = [ module.exports.check_os, module.exports.check_xcodebuild, module.exports.check_ios_deploy, @@ -215,7 +214,7 @@ module.exports.check_all = function () { // we don't need to check others if (fatalIsHit) return Q(); - let requirement = requirements[idx]; + const requirement = requirements[idx]; return checkFn() .then(function (version) { requirement.installed = true; diff --git a/bin/templates/scripts/cordova/lib/plugman/pluginHandlers.js b/bin/templates/scripts/cordova/lib/plugman/pluginHandlers.js index bd9d853e3..878e706e4 100644 --- a/bin/templates/scripts/cordova/lib/plugman/pluginHandlers.js +++ b/bin/templates/scripts/cordova/lib/plugman/pluginHandlers.js @@ -80,7 +80,7 @@ var handlers = { shell.rm('-rf', destFile); } }, - 'framework': { // CB-5238 custom frameworks only + framework: { // CB-5238 custom frameworks only install: function (obj, plugin, project, options) { var src = obj.src; var custom = !!(obj.custom); // convert to boolean (if truthy/falsy) @@ -96,7 +96,7 @@ var handlers = { } else { project.frameworks[src] = project.frameworks[src] || 0; project.frameworks[src]++; - let opt = { customFramework: false, embed: false, link: true, weak: obj.weak }; + const opt = { customFramework: false, embed: false, link: true, weak: obj.weak }; events.emit('verbose', util.format('Adding non-custom framework to project... %s -> %s', src, JSON.stringify(opt))); project.xcode.addFramework(src, opt); events.emit('verbose', util.format('Non-custom framework added to project. %s -> %s', src, JSON.stringify(opt))); @@ -118,7 +118,7 @@ var handlers = { events.emit('verbose', '"Embed Frameworks" Build Phase (Embedded Binaries) does not exist, creating it.'); project.xcode.addBuildPhase([], 'PBXCopyFilesBuildPhase', 'Embed Frameworks', null, 'frameworks'); } - let opt = { customFramework: true, embed: embed, link: link, sign: true }; + const opt = { customFramework: true, embed: embed, link: link, sign: true }; events.emit('verbose', util.format('Adding custom framework to project... %s -> %s', src, JSON.stringify(opt))); project.xcode.addFramework(project_relative, opt); events.emit('verbose', util.format('Custom framework added to project. %s -> %s', src, JSON.stringify(opt))); @@ -160,7 +160,7 @@ var handlers = { events.emit('verbose', ' uninstall is not supported for iOS plugins'); } }, - 'asset': { + asset: { install: function (obj, plugin, project, options) { if (!obj.src) { throw new CordovaError(generateAttributeError('src', 'asset', plugin.id)); diff --git a/bin/templates/scripts/cordova/lib/prepare.js b/bin/templates/scripts/cordova/lib/prepare.js index 16ffd4e71..1cd53dc35 100644 --- a/bin/templates/scripts/cordova/lib/prepare.js +++ b/bin/templates/scripts/cordova/lib/prepare.js @@ -184,7 +184,6 @@ function cleanWww (projectRoot, locations) { * @param {Object} locations A map of locations for this platform (In/Out) */ function updateProject (platformConfig, locations) { - // CB-6992 it is necessary to normalize characters // because node and shell scripts handles unicode symbols differently // We need to normalize the name to NFD form since iOS uses NFD unicode form @@ -251,26 +250,25 @@ function updateProject (platformConfig, locations) { } function handleOrientationSettings (platformConfig, infoPlist) { - switch (getOrientationValue(platformConfig)) { case 'portrait': - infoPlist['UIInterfaceOrientation'] = [ 'UIInterfaceOrientationPortrait' ]; - infoPlist['UISupportedInterfaceOrientations'] = [ 'UIInterfaceOrientationPortrait', 'UIInterfaceOrientationPortraitUpsideDown' ]; - infoPlist['UISupportedInterfaceOrientations~ipad'] = [ 'UIInterfaceOrientationPortrait', 'UIInterfaceOrientationPortraitUpsideDown' ]; + infoPlist['UIInterfaceOrientation'] = ['UIInterfaceOrientationPortrait']; + infoPlist['UISupportedInterfaceOrientations'] = ['UIInterfaceOrientationPortrait', 'UIInterfaceOrientationPortraitUpsideDown']; + infoPlist['UISupportedInterfaceOrientations~ipad'] = ['UIInterfaceOrientationPortrait', 'UIInterfaceOrientationPortraitUpsideDown']; break; case 'landscape': - infoPlist['UIInterfaceOrientation'] = [ 'UIInterfaceOrientationLandscapeLeft' ]; - infoPlist['UISupportedInterfaceOrientations'] = [ 'UIInterfaceOrientationLandscapeLeft', 'UIInterfaceOrientationLandscapeRight' ]; - infoPlist['UISupportedInterfaceOrientations~ipad'] = [ 'UIInterfaceOrientationLandscapeLeft', 'UIInterfaceOrientationLandscapeRight' ]; + infoPlist['UIInterfaceOrientation'] = ['UIInterfaceOrientationLandscapeLeft']; + infoPlist['UISupportedInterfaceOrientations'] = ['UIInterfaceOrientationLandscapeLeft', 'UIInterfaceOrientationLandscapeRight']; + infoPlist['UISupportedInterfaceOrientations~ipad'] = ['UIInterfaceOrientationLandscapeLeft', 'UIInterfaceOrientationLandscapeRight']; break; case 'all': - infoPlist['UIInterfaceOrientation'] = [ 'UIInterfaceOrientationPortrait' ]; - infoPlist['UISupportedInterfaceOrientations'] = [ 'UIInterfaceOrientationPortrait', 'UIInterfaceOrientationPortraitUpsideDown', 'UIInterfaceOrientationLandscapeLeft', 'UIInterfaceOrientationLandscapeRight' ]; - infoPlist['UISupportedInterfaceOrientations~ipad'] = [ 'UIInterfaceOrientationPortrait', 'UIInterfaceOrientationPortraitUpsideDown', 'UIInterfaceOrientationLandscapeLeft', 'UIInterfaceOrientationLandscapeRight' ]; + infoPlist['UIInterfaceOrientation'] = ['UIInterfaceOrientationPortrait']; + infoPlist['UISupportedInterfaceOrientations'] = ['UIInterfaceOrientationPortrait', 'UIInterfaceOrientationPortraitUpsideDown', 'UIInterfaceOrientationLandscapeLeft', 'UIInterfaceOrientationLandscapeRight']; + infoPlist['UISupportedInterfaceOrientations~ipad'] = ['UIInterfaceOrientationPortrait', 'UIInterfaceOrientationPortraitUpsideDown', 'UIInterfaceOrientationLandscapeLeft', 'UIInterfaceOrientationLandscapeRight']; break; case 'default': - infoPlist['UISupportedInterfaceOrientations'] = [ 'UIInterfaceOrientationPortrait', 'UIInterfaceOrientationLandscapeLeft', 'UIInterfaceOrientationLandscapeRight' ]; - infoPlist['UISupportedInterfaceOrientations~ipad'] = [ 'UIInterfaceOrientationPortrait', 'UIInterfaceOrientationPortraitUpsideDown', 'UIInterfaceOrientationLandscapeLeft', 'UIInterfaceOrientationLandscapeRight' ]; + infoPlist['UISupportedInterfaceOrientations'] = ['UIInterfaceOrientationPortrait', 'UIInterfaceOrientationLandscapeLeft', 'UIInterfaceOrientationLandscapeRight']; + infoPlist['UISupportedInterfaceOrientations~ipad'] = ['UIInterfaceOrientationPortrait', 'UIInterfaceOrientationPortraitUpsideDown', 'UIInterfaceOrientationLandscapeLeft', 'UIInterfaceOrientationLandscapeRight']; delete infoPlist['UIInterfaceOrientation']; } } @@ -515,9 +513,9 @@ function updateFileResources (cordovaProject, locations) { return; } - let resourceMap = {}; + const resourceMap = {}; files.forEach(function (res) { - let src = res.src; + const src = res.src; let target = res.target; if (!target) { @@ -553,7 +551,7 @@ function cleanFileResources (projectRoot, projectConfig, locations) { var resourceMap = {}; files.forEach(function (res) { - let src = res.src; + const src = res.src; let target = res.target; if (!target) { @@ -707,7 +705,6 @@ function mapLaunchStoryboardResources (splashScreens, launchStoryboardImagesDir) * @return {Object} */ function getLaunchStoryboardContentsJSON (splashScreens, launchStoryboardImagesDir) { - var platformLaunchStoryboardImages = mapLaunchStoryboardContents(splashScreens, launchStoryboardImagesDir); var contentsJSON = { images: [], @@ -933,7 +930,6 @@ function cleanLaunchStoryboardImages (projectRoot, projectConfig, locations) { * (or empty string if both are undefined). */ function getOrientationValue (platformConfig) { - var ORIENTATION_DEFAULT = 'default'; var orientation = platformConfig.getPreference('orientation'); @@ -1005,7 +1001,7 @@ function processAccessAndAllowNavigationEntries (config) { item = {}; } for (var o in obj) { - if (obj.hasOwnProperty(o)) { + if (Object.prototype.hasOwnProperty.call(obj, o)) { item[o] = obj[o]; } } @@ -1120,7 +1116,7 @@ function writeATSEntries (config) { var ats = {}; for (var hostname in pObj) { - if (pObj.hasOwnProperty(hostname)) { + if (Object.prototype.hasOwnProperty.call(pObj, hostname)) { var entry = pObj[hostname]; // Guiding principle: we only set values if they are available @@ -1147,7 +1143,7 @@ function writeATSEntries (config) { var exceptionDomain = {}; for (var key in entry) { - if (entry.hasOwnProperty(key) && key !== 'Hostname') { + if (Object.prototype.hasOwnProperty.call(entry, key) && key !== 'Hostname') { exceptionDomain[key] = entry[key]; } } @@ -1181,7 +1177,7 @@ function default_CFBundleVersion (version) { // Converts cordova specific representation of target device to XCode value function parseTargetDevicePreference (value) { if (!value) return null; - var map = { 'universal': '"1,2"', 'handset': '"1"', 'tablet': '"2"' }; + var map = { universal: '"1,2"', handset: '"1"', tablet: '"2"' }; if (map[value.toLowerCase()]) { return map[value.toLowerCase()]; } diff --git a/bin/templates/scripts/cordova/lib/run.js b/bin/templates/scripts/cordova/lib/run.js index f21fee69b..d012e68c0 100644 --- a/bin/templates/scripts/cordova/lib/run.js +++ b/bin/templates/scripts/cordova/lib/run.js @@ -31,7 +31,6 @@ var cordovaPath = path.join(__dirname, '..'); var projectPath = path.join(__dirname, '..', '..'); module.exports.run = function (runOptions) { - // Validate args if (runOptions.device && runOptions.emulator) { return Q.reject('Only one of "device"/"emulator" options should be specified'); @@ -79,7 +78,7 @@ module.exports.run = function (runOptions) { var ipafile = path.join(buildOutputDir, projectName + '.ipa'); // unpack the existing platform/ios/build/device/appname.ipa (zipfile), will create a Payload folder - return superspawn.spawn('unzip', [ '-o', '-qq', ipafile ], { cwd: buildOutputDir, printCommand: true, stdio: 'inherit' }); + return superspawn.spawn('unzip', ['-o', '-qq', ipafile], { cwd: buildOutputDir, printCommand: true, stdio: 'inherit' }); }) .then(function () { // Uncompress IPA (zip file) diff --git a/bin/templates/scripts/cordova/run b/bin/templates/scripts/cordova/run index 81741c84f..e42df5075 100755 --- a/bin/templates/scripts/cordova/run +++ b/bin/templates/scripts/cordova/run @@ -31,23 +31,23 @@ if (['--help', '/?', '-h', 'help', '-help', '/help'].indexOf(process.argv[2]) >= // Parse arguments (includes build params as well) var opts = nopt({ - 'verbose': Boolean, - 'silent': Boolean, - 'debug': Boolean, - 'release': Boolean, - 'nobuild': Boolean, - 'archs': String, - 'list': Boolean, - 'device': Boolean, - 'emulator': Boolean, - 'target': String, - 'codeSignIdentity': String, - 'codeSignResourceRules': String, - 'provisioningProfile': String, - 'automaticProvisioning': Boolean, - 'buildConfig': String, - 'noSign': Boolean -}, { 'd': '--verbose' }, args); + verbose: Boolean, + silent: Boolean, + debug: Boolean, + release: Boolean, + nobuild: Boolean, + archs: String, + list: Boolean, + device: Boolean, + emulator: Boolean, + target: String, + codeSignIdentity: String, + codeSignResourceRules: String, + provisioningProfile: String, + automaticProvisioning: Boolean, + buildConfig: String, + noSign: Boolean +}, { d: '--verbose' }, args); // Make options compatible with PlatformApi build method spec opts.argv = opts.argv.remain; diff --git a/bin/update b/bin/update index 704ab1f3f..abaf87f36 100755 --- a/bin/update +++ b/bin/update @@ -22,10 +22,10 @@ var path = require('path'); var Api = require('./templates/scripts/cordova/Api'); var args = require('nopt')({ - 'link': Boolean, - 'shared': Boolean, // alias for --link - 'help': Boolean -}, { 'd': '--verbose' }); + link: Boolean, + shared: Boolean, // alias for --link + help: Boolean +}, { d: '--verbose' }); if (args.help || args.argv.remain.length === 0) { console.log('Usage: ' + path.relative(process.cwd(), path.join(__dirname, 'update')) + ' [--link]'); diff --git a/cordova-js-src/.eslintrc.yml b/cordova-js-src/.eslintrc.yml deleted file mode 100644 index e3d49d8a0..000000000 --- a/cordova-js-src/.eslintrc.yml +++ /dev/null @@ -1,4 +0,0 @@ -env: - node: false - commonjs: true - browser: true diff --git a/cordova-js-src/exec.js b/cordova-js-src/exec.js index e7f6ce1c6..422582e74 100644 --- a/cordova-js-src/exec.js +++ b/cordova-js-src/exec.js @@ -41,8 +41,8 @@ function massageArgsJsToNative (args) { args.forEach(function (arg, i) { if (utils.typeName(arg) === 'ArrayBuffer') { ret.push({ - 'CDVType': 'ArrayBuffer', - 'data': base64.fromArrayBuffer(arg) + CDVType: 'ArrayBuffer', + data: base64.fromArrayBuffer(arg) }); } else { ret.push(arg); @@ -70,7 +70,7 @@ function massageMessageNativeToJs (message) { function convertMessageToArgsNativeToJs (message) { var args = []; - if (!message || !message.hasOwnProperty('CDVType')) { + if (!message || !Object.prototype.hasOwnProperty.call(message, 'CDVType')) { args.push(message); } else if (message.CDVType === 'MultiPart') { message.messages.forEach(function (e) { @@ -83,7 +83,6 @@ function convertMessageToArgsNativeToJs (message) { } function iOSExec () { - var successCallback, failCallback, service, action, actionArgs; var callbackId = null; if (typeof arguments[0] !== 'string') { diff --git a/cordova-js-src/plugin/ios/logger.js b/cordova-js-src/plugin/ios/logger.js index 7dc82e36a..6f59e1c8e 100644 --- a/cordova-js-src/plugin/ios/logger.js +++ b/cordova-js-src/plugin/ios/logger.js @@ -312,7 +312,6 @@ function __format (formatString, args) { } function __formatted (object, formatChar) { - try { switch (formatChar) { case 'j': diff --git a/package.json b/package.json index 7fb38fe8b..46410b252 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ "scripts": { "test": "npm run unit-tests && npm run test:component && npm run objc-tests && npm run e2e-tests", "test:component": "jasmine --config=tests/spec/component.json", - "posttest": "npm run eslint", + "posttest": "npm run lint", "cover": "nyc jasmine --config=tests/spec/coverage.json", "e2e-tests": "jasmine tests/spec/create.spec.js", "objc-tests": "npm run objc-tests-lib && npm run objc-tests-framework", @@ -29,18 +29,12 @@ "xcodebuild": "xcodebuild -quiet test -workspace tests/cordova-ios.xcworkspace -destination \"platform=iOS Simulator,name=iPhone 8\" CONFIGURATION_BUILD_DIR=\"`mktemp -d 2>/dev/null || mktemp -d -t 'cordova-ios'`\"", "preobjc-tests": "tests/scripts/killsim.js", "unit-tests": "jasmine --config=tests/spec/unit.json", - "eslint": "eslint . \"bin/**/!(*.*)\"" + "lint": "eslint . \"bin/**/!(*.*)\"" }, "author": "Apache Software Foundation", "license": "Apache-2.0", "devDependencies": { - "eslint": "^5.12.0", - "eslint-config-semistandard": "^13.0.0", - "eslint-config-standard": "^12.0.0", - "eslint-plugin-import": "^2.14.0", - "eslint-plugin-node": "^8.0.1", - "eslint-plugin-promise": "^4.0.1", - "eslint-plugin-standard": "^4.0.0", + "@cordova/eslint-config": "^2.0.0", "jasmine": "^3.4.0", "nyc": "^14.0.0", "rewire": "^4.0.1", diff --git a/tests/spec/.eslintrc.yml b/tests/spec/.eslintrc.yml deleted file mode 100644 index 6afba65af..000000000 --- a/tests/spec/.eslintrc.yml +++ /dev/null @@ -1,2 +0,0 @@ -env: - jasmine: true \ No newline at end of file diff --git a/tests/spec/create.spec.js b/tests/spec/create.spec.js index dbb04f8dc..5a4aa1dbe 100644 --- a/tests/spec/create.spec.js +++ b/tests/spec/create.spec.js @@ -51,7 +51,6 @@ function createAndBuild (projectname, projectid) { } describe('create', function () { - it('Test#001 : create project with ascii name, no spaces', function () { var projectname = 'testcreate'; var projectid = 'com.test.app1'; diff --git a/tests/spec/unit/Api.spec.js b/tests/spec/unit/Api.spec.js index 227f4270d..072324eb7 100644 --- a/tests/spec/unit/Api.spec.js +++ b/tests/spec/unit/Api.spec.js @@ -47,7 +47,6 @@ function compareListWithoutOrder (list1, list2) { } describe('Platform Api', function () { - describe('constructor', function () { it('Test 001 : should throw if provided directory does not contain an xcodeproj file', function () { expect(() => @@ -149,16 +148,16 @@ describe('Platform Api', function () { 'https://github.com/CocoaPods/Specs.git': { source: 'https://github.com/CocoaPods/Specs.git' } }, libraries: { - 'AFNetworking': { + AFNetworking: { name: 'AFNetworking', spec: '~> 3.2' }, - 'Eureka': { + Eureka: { name: 'Eureka', spec: '4.0', 'swift-version': '4.1' }, - 'HogeLib': { + HogeLib: { name: 'HogeLib', git: 'https://github.com/hoge/HogewLib.git', branch: 'develop' @@ -388,16 +387,16 @@ describe('Platform Api', function () { 'https://github.com/CocoaPods/Specs.git': { source: 'https://github.com/CocoaPods/Specs.git' } }, libraries: { - 'AFNetworking': { + AFNetworking: { name: 'AFNetworking', spec: '~> 3.2' }, - 'Eureka': { + Eureka: { name: 'Eureka', spec: '4.0', 'swift-version': '4.1' }, - 'HogeLib': { + HogeLib: { name: 'HogeLib', git: 'https://github.com/hoge/HogewLib.git', branch: 'develop' diff --git a/tests/spec/unit/BridgingHeader.spec.js b/tests/spec/unit/BridgingHeader.spec.js index f28bcb889..cf2c4d3ca 100644 --- a/tests/spec/unit/BridgingHeader.spec.js +++ b/tests/spec/unit/BridgingHeader.spec.js @@ -124,7 +124,5 @@ describe('unit tests for BridgingHeader module', function () { text_list = result_json.text.split('\n'); expect(text_list.filter(function (line) { return line === headerImportText(dummy_plugin.header_path); }).length).toEqual(0); expect(text_list.filter(function (line) { return line === headerImportText(dummy_plugin2.header_path); }).length).toEqual(0); - }); - }); diff --git a/tests/spec/unit/Plugman/common.spec.js b/tests/spec/unit/Plugman/common.spec.js index 5608c51ea..4845a09e6 100644 --- a/tests/spec/unit/Plugman/common.spec.js +++ b/tests/spec/unit/Plugman/common.spec.js @@ -38,7 +38,6 @@ var copyNewFile = common.__get__('copyNewFile'); var removeFileAndParents = common.__get__('removeFileAndParents'); describe('common handler routines', function () { - describe('copyFile', function () { it('Test 001 : should throw if source path not found', function () { shell.rm('-rf', test_dir); @@ -118,7 +117,6 @@ describe('common handler routines', function () { shell.rm('-rf', project_dir); }); - }); describe('copyNewFile', function () { @@ -128,7 +126,6 @@ describe('common handler routines', function () { .toThrow(new Error('"' + dest + '" already exists!')); shell.rm('-rf', dest); }); - }); describe('deleteJava', function () { diff --git a/tests/spec/unit/Plugman/pluginHandler.spec.js b/tests/spec/unit/Plugman/pluginHandler.spec.js index cdcc22c37..f98bf8b6b 100644 --- a/tests/spec/unit/Plugman/pluginHandler.spec.js +++ b/tests/spec/unit/Plugman/pluginHandler.spec.js @@ -82,7 +82,6 @@ describe('ios plugin handler', function () { }); describe('installation', function () { - describe('of elements', function () { var install = pluginHandlers.getInstaller('source-file'); @@ -232,7 +231,6 @@ describe('ios plugin handler', function () { }); describe('of elements', function () { - var install = pluginHandlers.getInstaller('framework'); beforeEach(function () { spyOn(dummyProject.xcode, 'addFramework'); @@ -482,7 +480,6 @@ describe('ios plugin handler', function () { }); describe('without custom="true" attribute ', function () { - it('Test 041 : should decrease framework counter after uninstallation', function () { var install = pluginHandlers.getInstaller('framework'); var dummyNonCustomFrameworks = dummyPluginInfo.getFrameworks('ios').filter(function (f) { diff --git a/tests/spec/unit/Podfile.spec.js b/tests/spec/unit/Podfile.spec.js index 96be921d4..b398be109 100644 --- a/tests/spec/unit/Podfile.spec.js +++ b/tests/spec/unit/Podfile.spec.js @@ -33,7 +33,6 @@ describe('unit tests for Podfile module', function () { var podfile = new Podfile(fixturePodfile, PROJECT_NAME); describe('tests', function () { - it('Test 001 : throws CordovaError when the path filename is not named Podfile', function () { var dummyPath = 'NotAPodfile'; expect(function () { @@ -100,8 +99,8 @@ describe('unit tests for Podfile module', function () { podfile.addSpec('Foo-Baz', '4.0'); podfile.addSpec('Foo~Baz@!%@!%!', '5.0'); podfile.addSpec('Bla', ':configurations => [\'Debug\', \'Beta\']'); - podfile.addSpec('Bla2', { 'configurations': 'Debug,Release' }); - podfile.addSpec('Bla3', { 'configurations': 'Debug, Release' }); + podfile.addSpec('Bla2', { configurations: 'Debug,Release' }); + podfile.addSpec('Bla3', { configurations: 'Debug, Release' }); podfile.write(); @@ -163,7 +162,6 @@ describe('unit tests for Podfile module', function () { expect(actualProjectName).toBe(expectedProjectName); }); - }); it('Test 012 : tear down', function () { diff --git a/tests/spec/unit/PodsJson.spec.js b/tests/spec/unit/PodsJson.spec.js index 5667a41b0..103950bd1 100644 --- a/tests/spec/unit/PodsJson.spec.js +++ b/tests/spec/unit/PodsJson.spec.js @@ -36,7 +36,6 @@ describe('unit tests for Podfile module', function () { }); describe('tests', function () { - it('Test 001 : throws CordovaError when the path filename is not named pods.json', function () { var dummyPath = 'NotPodsJson'; expect(function () { @@ -153,9 +152,9 @@ describe('unit tests for Podfile module', function () { podsjson.clear(); var vals = { - 'Foo': { name: 'Foo', type: 'podspec', spec: '1.0', count: 1 }, - 'Bar': { name: 'Bar', type: 'podspec', spec: '2.0', count: 2 }, - 'Baz': { name: 'Baz', type: 'podspec', spec: '3.0', count: 3 } + Foo: { name: 'Foo', type: 'podspec', spec: '1.0', count: 1 }, + Bar: { name: 'Bar', type: 'podspec', spec: '2.0', count: 2 }, + Baz: { name: 'Baz', type: 'podspec', spec: '3.0', count: 3 } }; podsjson.setJsonLibrary('Foo', vals.Foo); @@ -245,7 +244,6 @@ describe('unit tests for Podfile module', function () { expect(writeFileSyncSpy).toHaveBeenCalled(); expect(JSON.parse(result).sources[json2.source]).toEqual(json2); }); - }); // it('Test 008 : tear down', function () { diff --git a/tests/spec/unit/build.spec.js b/tests/spec/unit/build.spec.js index dcac7dcb1..c553e20d9 100644 --- a/tests/spec/unit/build.spec.js +++ b/tests/spec/unit/build.spec.js @@ -34,7 +34,6 @@ describe('build', function () { }); describe('getXcodeBuildArgs method', function () { - var getXcodeBuildArgs = build.__get__('getXcodeBuildArgs'); build.__set__('__dirname', path.join('/test', 'dir')); @@ -208,7 +207,6 @@ describe('build', function () { }); describe('getXcodeArchiveArgs method', function () { - var getXcodeArchiveArgs = build.__get__('getXcodeArchiveArgs'); it('should generate the appropriate arguments', function () { @@ -238,82 +236,81 @@ describe('build', function () { }); describe('parseBuildFlag method', function () { - var parseBuildFlag = build.__get__('parseBuildFlag'); it('should detect a workspace change', function () { var buildFlag = '-workspace MyTestWorkspace'; - var args = { 'otherFlags': [] }; + var args = { otherFlags: [] }; parseBuildFlag(buildFlag, args); expect(args.workspace).toEqual('MyTestWorkspace'); expect(args.otherFlags.length).toEqual(0); }); it('should detect a scheme change', function () { var buildFlag = '-scheme MyTestScheme'; - var args = { 'otherFlags': [] }; + var args = { otherFlags: [] }; parseBuildFlag(buildFlag, args); expect(args.scheme).toEqual('MyTestScheme'); expect(args.otherFlags.length).toEqual(0); }); it('should detect a configuration change', function () { var buildFlag = '-configuration MyTestConfiguration'; - var args = { 'otherFlags': [] }; + var args = { otherFlags: [] }; parseBuildFlag(buildFlag, args); expect(args.configuration).toEqual('MyTestConfiguration'); expect(args.otherFlags.length).toEqual(0); }); it('should detect an sdk change', function () { var buildFlag = '-sdk NotARealSDK'; - var args = { 'otherFlags': [] }; + var args = { otherFlags: [] }; parseBuildFlag(buildFlag, args); expect(args.sdk).toEqual('NotARealSDK'); expect(args.otherFlags.length).toEqual(0); }); it('should detect a destination change', function () { var buildFlag = '-destination MyTestDestination'; - var args = { 'otherFlags': [] }; + var args = { otherFlags: [] }; parseBuildFlag(buildFlag, args); expect(args.destination).toEqual('MyTestDestination'); expect(args.otherFlags.length).toEqual(0); }); it('should detect an archivePath change', function () { var buildFlag = '-archivePath MyTestArchivePath'; - var args = { 'otherFlags': [] }; + var args = { otherFlags: [] }; parseBuildFlag(buildFlag, args); expect(args.archivePath).toEqual('MyTestArchivePath'); expect(args.otherFlags.length).toEqual(0); }); it('should detect a configuration_build_dir change', function () { var buildFlag = 'CONFIGURATION_BUILD_DIR=/path/to/fake/config/build/dir'; - var args = { 'otherFlags': [] }; + var args = { otherFlags: [] }; parseBuildFlag(buildFlag, args); expect(args.configuration_build_dir).toEqual('CONFIGURATION_BUILD_DIR=/path/to/fake/config/build/dir'); expect(args.otherFlags.length).toEqual(0); }); it('should detect a shared_precomps_dir change', function () { var buildFlag = 'SHARED_PRECOMPS_DIR=/path/to/fake/shared/precomps/dir'; - var args = { 'otherFlags': [] }; + var args = { otherFlags: [] }; parseBuildFlag(buildFlag, args); expect(args.shared_precomps_dir).toEqual('SHARED_PRECOMPS_DIR=/path/to/fake/shared/precomps/dir'); expect(args.otherFlags.length).toEqual(0); }); it('should parse arbitrary build settings', function () { var buildFlag = 'MY_ARBITRARY_BUILD_SETTING=ValueOfArbitraryBuildSetting'; - var args = { 'otherFlags': [] }; + var args = { otherFlags: [] }; parseBuildFlag(buildFlag, args); expect(args.otherFlags[0]).toEqual('MY_ARBITRARY_BUILD_SETTING=ValueOfArbitraryBuildSetting'); expect(args.otherFlags.length).toEqual(1); }); it('should parse userdefaults', function () { var buildFlag = '-myuserdefault=TestUserDefaultValue'; - var args = { 'otherFlags': [] }; + var args = { otherFlags: [] }; parseBuildFlag(buildFlag, args); expect(args.otherFlags[0]).toEqual('-myuserdefault=TestUserDefaultValue'); expect(args.otherFlags.length).toEqual(1); }); it('should parse settings with a space', function () { var buildFlag = '-anotherxcodebuildsetting withASpace'; - var args = { 'otherFlags': [] }; + var args = { otherFlags: [] }; parseBuildFlag(buildFlag, args); expect(args.otherFlags[0]).toEqual('-anotherxcodebuildsetting'); expect(args.otherFlags[1]).toEqual('withASpace'); @@ -450,12 +447,12 @@ describe('build', function () { findXCodeProjectIn(fakePath); // Emit - let actualEmit = emitSpy.calls.argsFor(0)[1]; + const actualEmit = emitSpy.calls.argsFor(0)[1]; expect(emitSpy).toHaveBeenCalled(); expect(actualEmit).toContain('Found multiple .xcodeproj directories in'); // Resolve - let actualResolve = resolveSpy.calls.argsFor(0)[0]; + const actualResolve = resolveSpy.calls.argsFor(0)[0]; expect(resolveSpy).toHaveBeenCalled(); expect(actualResolve).toContain('Test1'); }); @@ -469,7 +466,7 @@ describe('build', function () { expect(emitSpy).not.toHaveBeenCalled(); // Resolve - let actualResolve = resolveSpy.calls.argsFor(0)[0]; + const actualResolve = resolveSpy.calls.argsFor(0)[0]; expect(resolveSpy).toHaveBeenCalled(); expect(actualResolve).toContain('Test1'); }); diff --git a/tests/spec/unit/prepare.spec.js b/tests/spec/unit/prepare.spec.js index 6f05245b7..6fff3d29d 100644 --- a/tests/spec/unit/prepare.spec.js +++ b/tests/spec/unit/prepare.spec.js @@ -286,7 +286,6 @@ describe('prepare', function () { it('should be true with typical and legacy launch storyboard images', function () { expect(platformHasLegacyLaunchImages(cfgs['modern-and-legacy'])).toEqual(true); }); - }); describe('#updateProjectPlistForLaunchStoryboard', function () { @@ -349,7 +348,6 @@ describe('prepare', function () { updateProjectPlistForLaunchStoryboard(cfgs['modern-and-legacy'].config, plist); expect(plist.UILaunchStoryboardName).toEqual('AnotherStoryboard'); }); - }); describe('#updateLaunchStoryboardImages', function () { @@ -389,7 +387,7 @@ describe('prepare', function () { 'Default@3x~universal~anyany.png': 'res/screen/ios/Default@3x~universal~anyany.png' }; // update keys with path to storyboardImagesDir for (var k in expectedResourceMap) { - if (expectedResourceMap.hasOwnProperty(k)) { + if (Object.prototype.hasOwnProperty.call(expectedResourceMap, k)) { expectedResourceMap[storyboardImagesDir + k] = expectedResourceMap[k]; delete expectedResourceMap[k]; } @@ -412,7 +410,6 @@ describe('prepare', function () { var logFileOp = prepare.__get__('logFileOp'); it('should move launch images and update contents.json', function () { - var projectRoot = iosProject; var platformProjDir = path.join('platforms', 'ios', 'SampleApp'); var storyboardImagesDir = getLaunchStoryboardImagesDir(projectRoot, platformProjDir); @@ -439,7 +436,7 @@ describe('prepare', function () { 'Default@3x~universal~anyany.png': null }; // update keys with path to storyboardImagesDir for (var k in expectedResourceMap) { - if (expectedResourceMap.hasOwnProperty(k)) { + if (Object.prototype.hasOwnProperty.call(expectedResourceMap, k)) { expectedResourceMap[storyboardImagesDir + k] = null; delete expectedResourceMap[k]; } @@ -495,7 +492,6 @@ describe('prepare', function () { updateProjectPlistForLaunchStoryboard(cfg.config, cfg.plist); expect(checkIfBuildSettingsNeedUpdatedForLaunchStoryboard(cfg.config, cfg.plist)).toEqual(false); }); - }); describe('#updateBuildSettingsForLaunchStoryboard', function () { @@ -532,7 +528,6 @@ describe('prepare', function () { expect(proj.getBuildProperty('ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME')).toBeUndefined(); }); }); - }); describe('updateProject method', function () { @@ -558,7 +553,6 @@ describe('prepare', function () { spyOn(plist, 'parse').and.returnValue({}); spyOn(plist, 'build').and.returnValue(''); spyOn(xcode, 'project').and.callFake(function (pbxproj) { - var xc = new xcOrig(pbxproj); /* eslint new-cap : 0 */ update_name = spyOn(xc, 'updateProductName').and.callThrough(); return xc; @@ -681,9 +675,9 @@ describe('prepare', function () { it('Test#005 : should write out the orientation preference value', function () { cfg.getPreference.and.callThrough(); return updateProject(cfg, p.locations).then(() => { - expect(plist.build.calls.mostRecent().args[0].UISupportedInterfaceOrientations).toEqual([ 'UIInterfaceOrientationPortrait', 'UIInterfaceOrientationPortraitUpsideDown' ]); - expect(plist.build.calls.mostRecent().args[0]['UISupportedInterfaceOrientations~ipad']).toEqual([ 'UIInterfaceOrientationPortrait', 'UIInterfaceOrientationPortraitUpsideDown' ]); - expect(plist.build.calls.mostRecent().args[0].UIInterfaceOrientation).toEqual([ 'UIInterfaceOrientationPortrait' ]); + expect(plist.build.calls.mostRecent().args[0].UISupportedInterfaceOrientations).toEqual(['UIInterfaceOrientationPortrait', 'UIInterfaceOrientationPortraitUpsideDown']); + expect(plist.build.calls.mostRecent().args[0]['UISupportedInterfaceOrientations~ipad']).toEqual(['UIInterfaceOrientationPortrait', 'UIInterfaceOrientationPortraitUpsideDown']); + expect(plist.build.calls.mostRecent().args[0].UIInterfaceOrientation).toEqual(['UIInterfaceOrientationPortrait']); }); }); it('Test#006 : should handle no orientation', function () { @@ -697,37 +691,37 @@ describe('prepare', function () { it('Test#007 : should handle default orientation', function () { cfg.getPreference.and.returnValue('default'); return updateProject(cfg, p.locations).then(() => { - expect(plist.build.calls.mostRecent().args[0].UISupportedInterfaceOrientations).toEqual([ 'UIInterfaceOrientationPortrait', 'UIInterfaceOrientationLandscapeLeft', 'UIInterfaceOrientationLandscapeRight' ]); - expect(plist.build.calls.mostRecent().args[0]['UISupportedInterfaceOrientations~ipad']).toEqual([ 'UIInterfaceOrientationPortrait', 'UIInterfaceOrientationPortraitUpsideDown', 'UIInterfaceOrientationLandscapeLeft', 'UIInterfaceOrientationLandscapeRight' ]); + expect(plist.build.calls.mostRecent().args[0].UISupportedInterfaceOrientations).toEqual(['UIInterfaceOrientationPortrait', 'UIInterfaceOrientationLandscapeLeft', 'UIInterfaceOrientationLandscapeRight']); + expect(plist.build.calls.mostRecent().args[0]['UISupportedInterfaceOrientations~ipad']).toEqual(['UIInterfaceOrientationPortrait', 'UIInterfaceOrientationPortraitUpsideDown', 'UIInterfaceOrientationLandscapeLeft', 'UIInterfaceOrientationLandscapeRight']); expect(plist.build.calls.mostRecent().args[0].UIInterfaceOrientation).toBeUndefined(); }); }); it('Test#008 : should handle portrait orientation', function () { cfg.getPreference.and.returnValue('portrait'); return updateProject(cfg, p.locations).then(() => { - expect(plist.build.calls.mostRecent().args[0].UISupportedInterfaceOrientations).toEqual([ 'UIInterfaceOrientationPortrait', 'UIInterfaceOrientationPortraitUpsideDown' ]); - expect(plist.build.calls.mostRecent().args[0].UIInterfaceOrientation).toEqual([ 'UIInterfaceOrientationPortrait' ]); + expect(plist.build.calls.mostRecent().args[0].UISupportedInterfaceOrientations).toEqual(['UIInterfaceOrientationPortrait', 'UIInterfaceOrientationPortraitUpsideDown']); + expect(plist.build.calls.mostRecent().args[0].UIInterfaceOrientation).toEqual(['UIInterfaceOrientationPortrait']); }); }); it('Test#009 : should handle landscape orientation', function () { cfg.getPreference.and.returnValue('landscape'); return updateProject(cfg, p.locations).then(() => { - expect(plist.build.calls.mostRecent().args[0].UISupportedInterfaceOrientations).toEqual([ 'UIInterfaceOrientationLandscapeLeft', 'UIInterfaceOrientationLandscapeRight' ]); - expect(plist.build.calls.mostRecent().args[0].UIInterfaceOrientation).toEqual([ 'UIInterfaceOrientationLandscapeLeft' ]); + expect(plist.build.calls.mostRecent().args[0].UISupportedInterfaceOrientations).toEqual(['UIInterfaceOrientationLandscapeLeft', 'UIInterfaceOrientationLandscapeRight']); + expect(plist.build.calls.mostRecent().args[0].UIInterfaceOrientation).toEqual(['UIInterfaceOrientationLandscapeLeft']); }); }); it('Test#010 : should handle all orientation on ios', function () { cfg.getPreference.and.returnValue('all'); return updateProject(cfg, p.locations).then(() => { - expect(plist.build.calls.mostRecent().args[0].UISupportedInterfaceOrientations).toEqual([ 'UIInterfaceOrientationPortrait', 'UIInterfaceOrientationPortraitUpsideDown', 'UIInterfaceOrientationLandscapeLeft', 'UIInterfaceOrientationLandscapeRight' ]); - expect(plist.build.calls.mostRecent().args[0].UIInterfaceOrientation).toEqual([ 'UIInterfaceOrientationPortrait' ]); + expect(plist.build.calls.mostRecent().args[0].UISupportedInterfaceOrientations).toEqual(['UIInterfaceOrientationPortrait', 'UIInterfaceOrientationPortraitUpsideDown', 'UIInterfaceOrientationLandscapeLeft', 'UIInterfaceOrientationLandscapeRight']); + expect(plist.build.calls.mostRecent().args[0].UIInterfaceOrientation).toEqual(['UIInterfaceOrientationPortrait']); }); }); it('Test#011 : should handle custom orientation', function () { cfg.getPreference.and.returnValue('some-custom-orientation'); return updateProject(cfg, p.locations).then(() => { - expect(plist.build.calls.mostRecent().args[0].UISupportedInterfaceOrientations).toEqual([ 'UIInterfaceOrientationPortrait', 'UIInterfaceOrientationLandscapeLeft', 'UIInterfaceOrientationLandscapeRight' ]); - expect(plist.build.calls.mostRecent().args[0]['UISupportedInterfaceOrientations~ipad']).toEqual([ 'UIInterfaceOrientationPortrait', 'UIInterfaceOrientationPortraitUpsideDown', 'UIInterfaceOrientationLandscapeLeft', 'UIInterfaceOrientationLandscapeRight' ]); + expect(plist.build.calls.mostRecent().args[0].UISupportedInterfaceOrientations).toEqual(['UIInterfaceOrientationPortrait', 'UIInterfaceOrientationLandscapeLeft', 'UIInterfaceOrientationLandscapeRight']); + expect(plist.build.calls.mostRecent().args[0]['UISupportedInterfaceOrientations~ipad']).toEqual(['UIInterfaceOrientationPortrait', 'UIInterfaceOrientationPortraitUpsideDown', 'UIInterfaceOrientationLandscapeLeft', 'UIInterfaceOrientationLandscapeRight']); expect(plist.build.calls.mostRecent().args[0].UIInterfaceOrientation).toBeUndefined(); }); }); @@ -748,7 +742,6 @@ describe('prepare', function () { }); it(' - should handle wildcard, with NSAllowsArbitraryLoadsInWebContent', function () { - const origReadFile = fse.readFileSync; var readFile = spyOn(fse, 'readFileSync'); var configXml = 'SampleApp' + @@ -775,7 +768,6 @@ describe('prepare', function () { }); it(' - should handle wildcard, with NSAllowsArbitraryLoadsForMedia set (fixed allows-arbitrary-loads-for-media)', function () { - const origReadFile = fse.readFileSync; var readFile = spyOn(fse, 'readFileSync'); var configXml = 'SampleApp' + @@ -801,7 +793,6 @@ describe('prepare', function () { }); it(' - should handle wildcard, with NSAllowsArbitraryLoadsForMedia not set (fixed allows-arbitrary-loads-for-media)', function () { - const origReadFile = fse.readFileSync; var readFile = spyOn(fse, 'readFileSync'); var configXml = 'SampleApp' + @@ -827,7 +818,6 @@ describe('prepare', function () { }); it(' - should handle wildcard, with NSAllowsArbitraryLoadsForMedia set (deprecated allows-arbitrary-loads-in-media)', function () { - const origReadFile = fse.readFileSync; var readFile = spyOn(fse, 'readFileSync'); var configXml = 'SampleApp' + @@ -853,7 +843,6 @@ describe('prepare', function () { }); it(' - should handle wildcard, with NSAllowsArbitraryLoadsForMedia not set (deprecated allows-arbitrary-loads-in-media)', function () { - const origReadFile = fse.readFileSync; var readFile = spyOn(fse, 'readFileSync'); var configXml = 'SampleApp' + @@ -879,7 +868,6 @@ describe('prepare', function () { }); it(' - should handle wildcard, with NSAllowsLocalNetworking', function () { - const origReadFile = fse.readFileSync; var readFile = spyOn(fse, 'readFileSync'); var configXml = 'SampleApp' + @@ -906,7 +894,6 @@ describe('prepare', function () { }); it(' - should handle wildcard, with NSAllowsArbitraryLoadsInWebContent, NSAllowsArbitraryLoadsForMedia, NSAllowsLocalNetworking', function () { - const origReadFile = fse.readFileSync; var readFile = spyOn(fse, 'readFileSync'); var configXml = 'SampleApp' + @@ -932,7 +919,6 @@ describe('prepare', function () { }); }); it(' - sanity check - no wildcard but has NSAllowsArbitraryLoadsInWebContent, NSAllowsArbitraryLoadsForMedia, NSAllowsLocalNetworking', function () { - const origReadFile = fse.readFileSync; var readFile = spyOn(fse, 'readFileSync'); var configXml = 'SampleApp' + @@ -1103,7 +1089,6 @@ describe('prepare', function () { expect(d.NSExceptionMinimumTLSVersion).toEqual('TLSv1.1'); expect(d.NSExceptionRequiresForwardSecrecy).toEqual(false); expect(d.NSRequiresCertificateTransparency).toEqual(true); - }); }); it('Test#015 : - https, no wildcard', function () { @@ -1205,7 +1190,6 @@ describe('prepare', function () { /// /////////////////////////////////////////////// it(' - should handle wildcard', function () { - const origReadFile = fse.readFileSync; var readFile = spyOn(fse, 'readFileSync'); var configXml = 'SampleApp' + @@ -1232,7 +1216,6 @@ describe('prepare', function () { }); it(' - sanity check - no wildcard but has NSAllowsArbitraryLoadsInWebContent, NSAllowsArbitraryLoadsForMedia, NSAllowsLocalNetworking', function () { - const origReadFile = fse.readFileSync; var readFile = spyOn(fse, 'readFileSync'); var configXml = 'SampleApp' + @@ -1403,7 +1386,6 @@ describe('prepare', function () { expect(d.NSExceptionMinimumTLSVersion).toEqual('TLSv1.1'); expect(d.NSExceptionRequiresForwardSecrecy).toEqual(false); expect(d.NSRequiresCertificateTransparency).toEqual(true); - }); }); @@ -1552,7 +1534,6 @@ describe('prepare', function () { expect(d.NSExceptionMinimumTLSVersion).toEqual('TLSv1.1'); expect(d.NSExceptionRequiresForwardSecrecy).toEqual(false); expect(d.NSRequiresCertificateTransparency).toEqual(true); - }); }); it('Test#018 : - wildcard scheme, no subdomain', function () { @@ -1626,7 +1607,6 @@ describe('prepare', function () { expect(d.NSExceptionMinimumTLSVersion).toEqual('TLSv1.1'); expect(d.NSExceptionRequiresForwardSecrecy).toEqual(false); expect(d.NSRequiresCertificateTransparency).toEqual(true); - }); }); it('Test#019 : - should ignore wildcards like data:*, https:*, https://*', function () { @@ -1650,16 +1630,16 @@ describe('prepare', function () { // image-8888.png target attribute is missing in config.xml as a test const images = [ { - 'src': 'image-5678.png', - 'target': 'image-5678.png' + src: 'image-5678.png', + target: 'image-5678.png' }, { - 'src': 'image-1234.png', - 'target': path.join('images', 'image-3456.png') + src: 'image-1234.png', + target: path.join('images', 'image-3456.png') }, { - 'src': 'image-8888.png', - 'target': 'image-8888.png' + src: 'image-8888.png', + target: 'image-8888.png' } ]; const projectRoot = path.join(FIXTURES, 'resource-file-support'); @@ -1706,16 +1686,16 @@ describe('prepare', function () { // for the 3 total file references attempted to be added above, // it should only have one file reference after the fact - for (let image of images) { + for (const image of images) { // check whether the file is copied to the target location - let copiedImageFile = path.join(project.resources_dir, image.target); + const copiedImageFile = path.join(project.resources_dir, image.target); expect(fs.existsSync(copiedImageFile)).toEqual(true); // find PBXBuildFile file reference - let imagefileRefs = findImageFileRef(project.xcode, path.basename(image.target)); + const imagefileRefs = findImageFileRef(project.xcode, path.basename(image.target)); expect(imagefileRefs.length).toEqual(1); // find file reference in PBXResourcesBuildPhase - let resBuildPhaseFileRefs = findResourcesBuildPhaseRef(project.xcode, imagefileRefs[0]); + const resBuildPhaseFileRefs = findResourcesBuildPhaseRef(project.xcode, imagefileRefs[0]); expect(resBuildPhaseFileRefs.length).toEqual(1); } }); @@ -1724,16 +1704,16 @@ describe('prepare', function () { cleanFileResources(projectRoot, cfgResourceFiles, p.locations); const project = projectFile.parse(p.locations); - for (let image of images) { + for (const image of images) { // check whether the file is removed from the target location - let copiedImageFile = path.join(project.resources_dir, image.target); + const copiedImageFile = path.join(project.resources_dir, image.target); expect(fs.existsSync(copiedImageFile)).toEqual(false); // find PBXBuildFile file reference - let imagefileRefs = findImageFileRef(project.xcode, path.basename(image.target)); + const imagefileRefs = findImageFileRef(project.xcode, path.basename(image.target)); expect(imagefileRefs.length).toEqual(0); // find file reference in PBXResourcesBuildPhase - let resBuildPhaseFileRefs = findResourcesBuildPhaseRef(project.xcode, imagefileRefs[0]); + const resBuildPhaseFileRefs = findResourcesBuildPhaseRef(project.xcode, imagefileRefs[0]); expect(resBuildPhaseFileRefs.length).toEqual(0); } }); @@ -1757,7 +1737,7 @@ describe('prepare', function () { shell.mkdir('-p', merges_path); updateWww(project, p.locations); expect(FileUpdater.mergeAndUpdateDir).toHaveBeenCalledWith( - [ 'www', path.join('platforms', 'ios', 'platform_www'), path.join('merges', 'ios') ], + ['www', path.join('platforms', 'ios', 'platform_www'), path.join('merges', 'ios')], path.join('platforms', 'ios', 'www'), { rootDir: iosProject }, logFileOp); @@ -1767,7 +1747,7 @@ describe('prepare', function () { shell.rm('-rf', merges_path); updateWww(project, p.locations); expect(FileUpdater.mergeAndUpdateDir).toHaveBeenCalledWith( - [ 'www', path.join('platforms', 'ios', 'platform_www') ], + ['www', path.join('platforms', 'ios', 'platform_www')], path.join('platforms', 'ios', 'www'), { rootDir: iosProject }, logFileOp); diff --git a/tests/spec/unit/preparePlatform.spec.js b/tests/spec/unit/preparePlatform.spec.js index 47a60f4f7..236a83cdd 100644 --- a/tests/spec/unit/preparePlatform.spec.js +++ b/tests/spec/unit/preparePlatform.spec.js @@ -43,7 +43,7 @@ describe('prepare after plugin add', function () { api = new Api('ios', iosPlatform, new EventEmitter()); jasmine.addMatchers({ - 'toBeInstalledIn': function () { + toBeInstalledIn: function () { return { compare: function (actual, expected) { var result = {};