Skip to content

Commit

Permalink
refactor (eslint): use cordova-eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
erisu committed Jan 29, 2020
1 parent 6372ca3 commit 3ec2884
Show file tree
Hide file tree
Showing 30 changed files with 198 additions and 217 deletions.
37 changes: 27 additions & 10 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@
root: true
extends: semistandard
rules:
indent:
- error
- 4
camelcase: off
padded-blocks: off
operator-linebreak: off
no-throw-literal: off
# 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.

extends: '@cordova/eslint-config/node'

overrides:
- files: [spec/**/*.js]
extends: '@cordova/eslint-config/node-tests'
rules:
prefer-promise-reject-errors: off

- files: [cordova-js-src/**/*.js]
extends: '@cordova/eslint-config/browser'
10 changes: 5 additions & 5 deletions bin/create
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ var ConfigParser = require('cordova-common').ConfigParser;
var Api = require('./templates/cordova/Api');

var argv = require('nopt')({
'help': Boolean,
'cli': Boolean,
'shared': Boolean,
'link': Boolean,
help: Boolean,
cli: Boolean,
shared: Boolean,
link: Boolean,
'activity-name': [String, undefined]
}, { 'd': '--verbose' });
}, { d: '--verbose' });

if (argv.help || argv.argv.remain.length === 0) {
console.log('Usage: ' + path.relative(process.cwd(), path.join(__dirname, 'create')) + ' <path_to_new_project> <package_name> <project_name> [<template_path>] [--activity-name <activity_name>] [--link]');
Expand Down
10 changes: 4 additions & 6 deletions bin/lib/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ function copyScripts (projectPath) {
// Copy in the new ones.
fs.copySync(srcScriptsDir, destScriptsDir);

let nodeModulesDir = path.join(ROOT, 'node_modules');
const nodeModulesDir = path.join(ROOT, 'node_modules');
if (fs.existsSync(nodeModulesDir)) fs.copySync(nodeModulesDir, path.join(destScriptsDir, 'node_modules'));

fs.copySync(path.join(bin, 'check_reqs'), path.join(destScriptsDir, 'check_reqs'));
Expand All @@ -156,7 +156,7 @@ function copyScripts (projectPath) {
// `require` path for the two libraries. if there's a better way to share
// modules across both the repo and generated projects, we should make sure
// to remove/update this.
let templatesCordovaRegex = /templates\/cordova\//;
const templatesCordovaRegex = /templates\/cordova\//;
utils.replaceFileContents(android_sdk_version, templatesCordovaRegex, '');
utils.replaceFileContents(check_reqs, templatesCordovaRegex, '');
}
Expand Down Expand Up @@ -218,7 +218,6 @@ function validateProjectName (project_name) {
* @return {Promise<String>} Directory where application has been created
*/
exports.create = function (project_path, config, options, events) {

options = options || {};

// Set default values for path, package and name
Expand All @@ -229,8 +228,8 @@ exports.create = function (project_path, config, options, events) {
}

var package_name = config.android_packageName() || config.packageName() || 'my.cordova.project';
var project_name = config.name() ?
config.name().replace(/[^\w.]/g, '_') : 'CordovaExample';
var project_name = config.name()
? config.name().replace(/[^\w.]/g, '_') : 'CordovaExample';

var safe_activity_name = config.android_activityName() || options.activityName || 'MainActivity';
var target_api = check_reqs.get_target();
Expand Down Expand Up @@ -312,7 +311,6 @@ function generateDoneMessage (type, link) {

// Returns a promise.
exports.update = function (projectPath, options, events) {

var errorString =
'An in-place platform update is not supported. \n' +
'The `platforms` folder is always treated as a build artifact in the CLI workflow.\n' +
Expand Down
14 changes: 7 additions & 7 deletions bin/templates/cordova/build
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ if (['--help', '/?', '-h', 'help', '-help', '/help'].indexOf(args[2]) >= 0) {

// Do some basic argument parsing
var buildOpts = nopt({
'verbose': Boolean,
'silent': Boolean,
'debug': Boolean,
'release': Boolean,
'nobuild': Boolean,
'buildConfig': path
}, { 'd': '--verbose' });
verbose: Boolean,
silent: Boolean,
debug: Boolean,
release: Boolean,
nobuild: Boolean,
buildConfig: path
}, { d: '--verbose' });

// Make buildOptions compatible with PlatformApi build method spec
buildOpts.argv = buildOpts.argv.original;
Expand Down
6 changes: 3 additions & 3 deletions bin/templates/cordova/clean
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,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;
Expand Down
10 changes: 5 additions & 5 deletions bin/templates/cordova/lib/android_sdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ module.exports.print_newest_available_sdk_target = function () {
module.exports.version_string_to_api_level = {
'4.0': 14,
'4.0.3': 15,
'4.1': 16,
'4.2': 17,
'4.3': 18,
'4.4': 19,
4.1: 16,
4.2: 17,
4.3: 18,
4.4: 19,
'4.4W': 20,
'5.0': 21,
'5.1': 22,
5.1: 22,
'6.0': 23,
'7.0': 24,
'7.1.1': 25,
Expand Down
2 changes: 1 addition & 1 deletion bin/templates/cordova/lib/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ function parseOpts (options, resolvedTarget, projectRoot) {
let shouldWarn = false;
const signingKeys = ['keystore', 'alias', 'storePassword', 'password', 'keystoreType'];

for (let key in packageArgs) {
for (const key in packageArgs) {
if (!shouldWarn && signingKeys.indexOf(key) > -1) {
// If we enter this condition, we have a key used for signing a build,
// but we are missing some required signing properties
Expand Down
2 changes: 1 addition & 1 deletion bin/templates/cordova/lib/builders/ProjectBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function findOutputFilesHelper (dir, build_type, arch, extension) {
if (files.length === 0) return files;

// Assume arch-specific build if newest apk has -x86 or -arm.
let archSpecific = !!/-x86|-arm/.exec(path.basename(files[0]));
const archSpecific = !!/-x86|-arm/.exec(path.basename(files[0]));

// And show only arch-specific ones (or non-arch-specific)
files = files.filter(p => !!/-x86|-arm/.exec(path.basename(p)) === archSpecific);
Expand Down
10 changes: 4 additions & 6 deletions bin/templates/cordova/lib/check_reqs.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@ var android_sdk = require('./android_sdk');
const { createEditor } = require('properties-parser');

function forgivingWhichSync (cmd) {
let whichResult = which.sync(cmd, { nothrow: true });
const whichResult = which.sync(cmd, { nothrow: true });

// On null, returns empty string to maintain backwards compatibility
// realpathSync follows symlinks
return whichResult === null ? '' : fs.realpathSync(whichResult);
}

function getJDKDirectory (directory) {
let p = path.resolve(directory, 'java');
const p = path.resolve(directory, 'java');
if (fs.existsSync(p)) {
let directories = fs.readdirSync(p);
const directories = fs.readdirSync(p);
for (let i = 0; i < directories.length; i++) {
let dir = directories[i];
const dir = directories[i];
if (/^(jdk)+./.test(dir)) {
return path.resolve(directory, 'java', dir);
}
Expand Down Expand Up @@ -119,7 +119,6 @@ module.exports.get_gradle_wrapper = function () {
var program_dir;
// OK, This hack only works on Windows, not on Mac OS or Linux. We will be deleting this eventually!
if (module.exports.isWindows()) {

var result = execa.sync(path.join(__dirname, 'getASPath.bat'));
// console.log('result.stdout =' + result.stdout.toString());
// console.log('result.stderr =' + result.stderr.toString());
Expand Down Expand Up @@ -431,7 +430,6 @@ var Requirement = function (id, name, version, installed) {
* @return Promise<Requirement[]> Array of requirements. Due to implementation, promise is always fulfilled.
*/
module.exports.check_all = function () {

var requirements = [
new Requirement('java', 'Java JDK'),
new Requirement('androidSdk', 'Android SDK'),
Expand Down
10 changes: 5 additions & 5 deletions bin/templates/cordova/lib/config/GradlePropertiesParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
under the License.
*/

let fs = require('fs');
let path = require('path');
let propertiesParser = require('properties-parser');
let events = require('cordova-common').events;
const fs = require('fs');
const path = require('path');
const propertiesParser = require('properties-parser');
const events = require('cordova-common').events;

class GradlePropertiesParser {
/**
Expand Down Expand Up @@ -82,7 +82,7 @@ class GradlePropertiesParser {
_configureProperties (properties) {
// Iterate though the properties and set only if missing.
Object.keys(properties).forEach(key => {
let value = this.gradleFile.get(key);
const value = this.gradleFile.get(key);

if (!value) {
// Handles the case of adding missing defaults or new properties that are missing.
Expand Down
7 changes: 1 addition & 6 deletions bin/templates/cordova/lib/emulator.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const CHECK_BOOTED_INTERVAL = 3 * ONE_SECOND; // in milliseconds
const EXEC_KILL_SIGNAL = 'SIGKILL';

function forgivingWhichSync (cmd) {
let whichResult = which.sync(cmd, { nothrow: true });
const whichResult = which.sync(cmd, { nothrow: true });

// On null, returns empty string to maintain backwards compatibility
// realpathSync follows symlinks
Expand Down Expand Up @@ -104,7 +104,6 @@ module.exports.list_images_using_avdmanager = function () {
if (response[i].match(/Name:\s/)) {
emulator_list.push(response[i].split('Name: ')[1].replace('\r', '');
} */

}
return emulator_list;
});
Expand Down Expand Up @@ -147,7 +146,6 @@ module.exports.list_images_using_android = function () {
if (response[i].match(/Name:\s/)) {
emulator_list.push(response[i].split('Name: ')[1].replace('\r', '');
} */

}
return emulator_list;
});
Expand Down Expand Up @@ -429,7 +427,6 @@ module.exports.resolveTarget = function (target) {
* Returns a promise.
*/
module.exports.install = function (givenTarget, buildResults) {

var target;
// We need to find the proper path to the Android Manifest
const manifestPath = path.join(__dirname, '..', '..', 'app', 'src', 'main', 'AndroidManifest.xml');
Expand All @@ -453,7 +450,6 @@ module.exports.install = function (givenTarget, buildResults) {
// This promise is always resolved, even if 'adb uninstall' fails to uninstall app
// or the app doesn't installed at all, so no error catching needed.
return Promise.resolve().then(function () {

var apk_path = build.findBestApkForArchitecture(buildResults, target.arch);
var execOptions = {
cwd: os.tmpdir(),
Expand Down Expand Up @@ -512,7 +508,6 @@ module.exports.install = function (givenTarget, buildResults) {
});
// unlock screen
}).then(function () {

events.emit('verbose', 'Unlocking screen...');
return Adb.shell(target.target, 'input keyevent 82');
}).then(function () {
Expand Down
2 changes: 1 addition & 1 deletion bin/templates/cordova/lib/pluginHandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ var handlers = {
removeFile(path.resolve(project.projectDir, dest));
}
},
'framework': {
framework: {
install: function (obj, plugin, project, options) {
var src = obj.src;
if (!src) throw new CordovaError(generateAttributeError('src', 'framework', plugin.id));
Expand Down
Loading

0 comments on commit 3ec2884

Please sign in to comment.