Skip to content

Commit

Permalink
chore(npm): bump @cordova/eslint-config@^4.0.0 (#1421)
Browse files Browse the repository at this point in the history
* chore(npm): bump @cordova/eslint-config@^4.0.0
* style(lint): apply auto corrections
* style(lint): convert hasAndroidHome var to let and hoisted
  • Loading branch information
erisu committed Apr 18, 2022
1 parent 62ed71c commit a2bb7f1
Show file tree
Hide file tree
Showing 25 changed files with 1,116 additions and 2,711 deletions.
14 changes: 7 additions & 7 deletions lib/Adb.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
under the License.
*/

var os = require('os');
var execa = require('execa');
var events = require('cordova-common').events;
var CordovaError = require('cordova-common').CordovaError;
const os = require('os');
const execa = require('execa');
const events = require('cordova-common').events;
const CordovaError = require('cordova-common').CordovaError;

var Adb = {};
const Adb = {};

/**
* Lists available/connected devices and emulators
Expand Down Expand Up @@ -50,7 +50,7 @@ Adb.devices = async function () {
Adb.install = function (target, packagePath, { replace = false, execOptions = {} } = {}) {
events.emit('verbose', 'Installing apk ' + packagePath + ' on target ' + target + '...');

var args = ['-s', target, 'install'];
const args = ['-s', target, 'install'];
if (replace) args.push('-r');

const opts = { cwd: os.tmpdir(), ...execOptions };
Expand Down Expand Up @@ -79,7 +79,7 @@ Adb.uninstall = function (target, packageId) {

Adb.shell = function (target, shellCommand) {
events.emit('verbose', 'Running adb shell command "' + shellCommand + '" on target ' + target + '...');
var args = ['-s', target, 'shell'];
const args = ['-s', target, 'shell'];
shellCommand = shellCommand.split(/\s+/);
return execa('adb', args.concat(shellCommand), { cwd: os.tmpdir() })
.then(({ stdout }) => stdout)
Expand Down
10 changes: 5 additions & 5 deletions lib/AndroidManifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
under the License.
*/

var fs = require('fs');
var xml = require('cordova-common').xmlHelpers;
const fs = require('fs');
const xml = require('cordova-common').xmlHelpers;

var DEFAULT_ORIENTATION = 'default';
const DEFAULT_ORIENTATION = 'default';

/** Wraps an AndroidManifest file */
class AndroidManifest {
Expand Down Expand Up @@ -60,7 +60,7 @@ class AndroidManifest {
}

getActivity () {
var activity = this.doc.getroot().find('./application/activity');
const activity = this.doc.getroot().find('./application/activity');
return {
getName: function () {
return activity.attrib['android:name'];
Expand Down Expand Up @@ -103,7 +103,7 @@ class AndroidManifest {
}

setDebuggable (value) {
var application = this.doc.getroot().find('./application');
const application = this.doc.getroot().find('./application');
if (value) {
application.attrib['android:debuggable'] = 'true';
} else {
Expand Down
64 changes: 32 additions & 32 deletions lib/AndroidProject.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,25 @@
under the License.
*/

var fs = require('fs');
var path = require('path');
var properties_parser = require('properties-parser');
var AndroidManifest = require('./AndroidManifest');
var pluginHandlers = require('./pluginHandlers');
const fs = require('fs');
const path = require('path');
const properties_parser = require('properties-parser');
const AndroidManifest = require('./AndroidManifest');
const pluginHandlers = require('./pluginHandlers');

var projectFileCache = {};
let projectFileCache = {};

function addToPropertyList (projectProperties, key, value) {
var i = 1;
let i = 1;
while (projectProperties.get(key + '.' + i)) { i++; }

projectProperties.set(key + '.' + i, value);
projectProperties.dirty = true;
}

function removeFromPropertyList (projectProperties, key, value) {
var i = 1;
var currentValue;
let i = 1;
let currentValue;
while ((currentValue = projectProperties.get(key + '.' + i))) {
if (currentValue === value) {
while ((currentValue = projectProperties.get(key + '.' + (i + 1)))) {
Expand All @@ -51,7 +51,7 @@ function removeFromPropertyList (projectProperties, key, value) {
}

function getRelativeLibraryPath (parentDir, subDir) {
var libraryPath = path.relative(parentDir, subDir);
const libraryPath = path.relative(parentDir, subDir);
return (path.sep === '\\') ? libraryPath.replace(/\\/g, '/') : libraryPath;
}

Expand All @@ -72,27 +72,27 @@ class AndroidProject {
* @return {String} The name of the package
*/
getPackageName () {
var manifestPath = path.join(this.projectDir, 'app/src/main/AndroidManifest.xml');
const manifestPath = path.join(this.projectDir, 'app/src/main/AndroidManifest.xml');
return new AndroidManifest(manifestPath).getPackageId();
}

getCustomSubprojectRelativeDir (plugin_id, src) {
// All custom subprojects are prefixed with the last portion of the package id.
// This is to avoid collisions when opening multiple projects in Eclipse that have subprojects with the same name.
var packageName = this.getPackageName();
var lastDotIndex = packageName.lastIndexOf('.');
var prefix = packageName.substring(lastDotIndex + 1);
var subRelativeDir = path.join(plugin_id, prefix + '-' + path.basename(src));
const packageName = this.getPackageName();
const lastDotIndex = packageName.lastIndexOf('.');
const prefix = packageName.substring(lastDotIndex + 1);
const subRelativeDir = path.join(plugin_id, prefix + '-' + path.basename(src));
return subRelativeDir;
}

addSubProject (parentDir, subDir) {
var parentProjectFile = path.resolve(parentDir, 'project.properties');
var subProjectFile = path.resolve(subDir, 'project.properties');
var parentProperties = this._getPropertiesFile(parentProjectFile);
const parentProjectFile = path.resolve(parentDir, 'project.properties');
const subProjectFile = path.resolve(subDir, 'project.properties');
const parentProperties = this._getPropertiesFile(parentProjectFile);
// TODO: Setting the target needs to happen only for pre-3.7.0 projects
if (fs.existsSync(subProjectFile)) {
var subProperties = this._getPropertiesFile(subProjectFile);
const subProperties = this._getPropertiesFile(subProjectFile);
subProperties.set('target', parentProperties.get('target'));
subProperties.dirty = true;
this._subProjectDirs[subDir] = true;
Expand All @@ -103,37 +103,37 @@ class AndroidProject {
}

removeSubProject (parentDir, subDir) {
var parentProjectFile = path.resolve(parentDir, 'project.properties');
var parentProperties = this._getPropertiesFile(parentProjectFile);
const parentProjectFile = path.resolve(parentDir, 'project.properties');
const parentProperties = this._getPropertiesFile(parentProjectFile);
removeFromPropertyList(parentProperties, 'android.library.reference', getRelativeLibraryPath(parentDir, subDir));
delete this._subProjectDirs[subDir];
this._dirty = true;
}

addGradleReference (parentDir, subDir) {
var parentProjectFile = path.resolve(parentDir, 'project.properties');
var parentProperties = this._getPropertiesFile(parentProjectFile);
const parentProjectFile = path.resolve(parentDir, 'project.properties');
const parentProperties = this._getPropertiesFile(parentProjectFile);
addToPropertyList(parentProperties, 'cordova.gradle.include', getRelativeLibraryPath(parentDir, subDir));
this._dirty = true;
}

removeGradleReference (parentDir, subDir) {
var parentProjectFile = path.resolve(parentDir, 'project.properties');
var parentProperties = this._getPropertiesFile(parentProjectFile);
const parentProjectFile = path.resolve(parentDir, 'project.properties');
const parentProperties = this._getPropertiesFile(parentProjectFile);
removeFromPropertyList(parentProperties, 'cordova.gradle.include', getRelativeLibraryPath(parentDir, subDir));
this._dirty = true;
}

addSystemLibrary (parentDir, value) {
var parentProjectFile = path.resolve(parentDir, 'project.properties');
var parentProperties = this._getPropertiesFile(parentProjectFile);
const parentProjectFile = path.resolve(parentDir, 'project.properties');
const parentProperties = this._getPropertiesFile(parentProjectFile);
addToPropertyList(parentProperties, 'cordova.system.library', value);
this._dirty = true;
}

removeSystemLibrary (parentDir, value) {
var parentProjectFile = path.resolve(parentDir, 'project.properties');
var parentProperties = this._getPropertiesFile(parentProjectFile);
const parentProjectFile = path.resolve(parentDir, 'project.properties');
const parentProperties = this._getPropertiesFile(parentProjectFile);
removeFromPropertyList(parentProperties, 'cordova.system.library', value);
this._dirty = true;
}
Expand All @@ -144,8 +144,8 @@ class AndroidProject {
}
this._dirty = false;

for (var filename in this._propertiesEditors) {
var editor = this._propertiesEditors[filename];
for (const filename in this._propertiesEditors) {
const editor = this._propertiesEditors[filename];
if (editor.dirty) {
fs.writeFileSync(filename, editor.toString());
editor.dirty = false;
Expand All @@ -165,7 +165,7 @@ class AndroidProject {
* This checks if an Android project is clean or has old build artifacts
*/
isClean () {
var build_path = path.join(this.projectDir, 'build');
const build_path = path.join(this.projectDir, 'build');
// If the build directory doesn't exist, it's clean
return !(fs.existsSync(build_path));
}
Expand Down
32 changes: 16 additions & 16 deletions lib/Api.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@
under the License.
*/

var path = require('path');
const path = require('path');

var AndroidProject = require('./AndroidProject');
var PluginManager = require('cordova-common').PluginManager;
const AndroidProject = require('./AndroidProject');
const PluginManager = require('cordova-common').PluginManager;

var CordovaLogger = require('cordova-common').CordovaLogger;
var selfEvents = require('cordova-common').events;
var ConfigParser = require('cordova-common').ConfigParser;
const CordovaLogger = require('cordova-common').CordovaLogger;
const selfEvents = require('cordova-common').events;
const ConfigParser = require('cordova-common').ConfigParser;
const prepare = require('./prepare').prepare;

var PLATFORM = 'android';
const PLATFORM = 'android';
const VERSION = require('../package').version;

function setupEvents (externalEventEmitter) {
Expand Down Expand Up @@ -88,7 +88,7 @@ class Api {
* platform's file structure and other properties of platform.
*/
getPlatformInfo () {
var result = {};
const result = {};
result.locations = this.locations;
result.root = this.root;
result.name = this.platform;
Expand Down Expand Up @@ -139,8 +139,8 @@ class Api {
* CordovaError instance.
*/
addPlugin (plugin, installOptions) {
var project = AndroidProject.getProjectFile(this.root);
var self = this;
const project = AndroidProject.getProjectFile(this.root);
const self = this;

installOptions = installOptions || {};
installOptions.variables = installOptions.variables || {};
Expand Down Expand Up @@ -175,7 +175,7 @@ class Api {
* CordovaError instance.
*/
removePlugin (plugin, uninstallOptions) {
var project = AndroidProject.getProjectFile(this.root);
const project = AndroidProject.getProjectFile(this.root);

if (uninstallOptions && uninstallOptions.usePlatformWww === true) {
uninstallOptions.usePlatformWww = false;
Expand Down Expand Up @@ -239,7 +239,7 @@ class Api {
* arhcitectures is specified.
*/
build (buildOptions) {
var self = this;
const self = this;

return require('./check_reqs').run().then(function () {
return require('./build').run.call(self, buildOptions);
Expand Down Expand Up @@ -269,7 +269,7 @@ class Api {
* successfully, or rejected with CordovaError.
*/
run (runOptions) {
var self = this;
const self = this;
return require('./check_reqs').run().then(function () {
return require('./run').run.call(self, runOptions);
});
Expand All @@ -283,7 +283,7 @@ class Api {
* CordovaError.
*/
clean (cleanOptions) {
var self = this;
const self = this;
// This will lint, checking for null won't
if (typeof cleanOptions === 'undefined') {
cleanOptions = {};
Expand Down Expand Up @@ -328,7 +328,7 @@ class Api {
*/
static createPlatform (destination, config, options, events) {
events = setupEvents(events);
var result;
let result;
try {
result = require('./create').create(destination, config, options, events).then(function (destination) {
return new Api(PLATFORM, destination, events);
Expand Down Expand Up @@ -358,7 +358,7 @@ class Api {
*/
static updatePlatform (destination, options, events) {
events = setupEvents(events);
var result;
let result;
try {
result = require('../../lib/create').update(destination, options, events).then(function (destination) {
return new Api(PLATFORM, destination, events);
Expand Down
8 changes: 4 additions & 4 deletions lib/android_sdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

const execa = require('execa');

var suffix_number_regex = /(\d+)$/;
const suffix_number_regex = /(\d+)$/;
// Used for sorting Android targets, example strings to sort:
// android-19
// android-L
Expand Down Expand Up @@ -66,9 +66,9 @@ module.exports.version_string_to_api_level = {
/* eslint-enable quote-props */

function parse_targets (output) {
var target_out = output.split('\n');
var targets = [];
for (var i = target_out.length - 1; i >= 0; i--) {
const target_out = output.split('\n');
const targets = [];
for (let i = target_out.length - 1; i >= 0; i--) {
if (target_out[i].match(/id:/)) { // if "id:" is in the line...
targets.push(target_out[i].match(/"(.+)"/)[1]); // .. match whatever is in quotes.
}
Expand Down

0 comments on commit a2bb7f1

Please sign in to comment.