Skip to content

Commit

Permalink
Fix lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
cb1kenobi committed Sep 12, 2023
1 parent 3a7f052 commit 089ae24
Show file tree
Hide file tree
Showing 16 changed files with 84 additions and 77 deletions.
4 changes: 2 additions & 2 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ module.exports = {
'no-trailing-spaces': 'error',
'no-unused-vars': 'off',
'no-useless-escape': 'warn',
'promise/always-return': 'error',
'promise/always-return': 'off',
'promise/no-return-wrap': 'error',
'promise/param-names': 'error',
'promise/catch-or-return': 'error',
'promise/no-native': 'off',
'promise/no-nesting': 'warn',
'promise/no-promise-in-callback': 'warn',
'promise/no-callback-in-promise': 'warn',
'promise/no-callback-in-promise': 'off',
'promise/avoid-new': 'off',
'promise/no-new-statics': 'error',
'promise/no-return-in-finally': 'warn',
Expand Down
65 changes: 33 additions & 32 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export class CLI {
sdks: {}
},
getOSInfo: async (callback) => {
const { data } = await detect(this.logger, config, this, { nodejs: true, os: true });
const { data } = await detect(this.logger, ticonfig, this, { nodejs: true, os: true });
const { node, npm, os } = data;
if (typeof callback === 'function') {
callback({
Expand Down Expand Up @@ -330,7 +330,9 @@ export class CLI {
}

// create each hook and immediately fire them
const promise = unique(arrayify(name, true))
const events = unique(arrayify(name, true));

const promise = events
.reduce((promise, name) => promise.then(() => new Promise((resolve, reject) => {
const hook = this.createHook(name, data);
hook((err, result) => {
Expand All @@ -342,6 +344,7 @@ export class CLI {
return promise;
}

// eslint-disable-next-line promise/catch-or-return
promise.then(result => callback(null, result), callback);

return this;
Expand Down Expand Up @@ -409,30 +412,27 @@ export class CLI {
}

this.logger.trace(`Executing command: ${this.command.name()}`);
await new Promise((resolve, reject) => {
try {
const result = run(this.logger, this.config, this, async (err, result) => {
// we need to wrap the post-execute emit in a try/catch so that any exceptions
// it throws aren't confused with command errors
try {
await this.emit('cli:post-execute', { cli: this, command: this.command, err, result });
} catch (ex) {
return reject(ex);
}

if (err) {
return reject(err);
}
const result = await new Promise((resolve, reject) => {
return run(this.logger, this.config, this, async (err, result) => {
// we need to wrap the post-execute emit in a try/catch so that any exceptions
// it throws aren't confused with command errors
try {
await this.emit('cli:post-execute', { cli: this, command: this.command, err, result });
} catch (ex) {
return reject(ex);
}

resolve();
});
if (result instanceof Promise) {
result.then(resolve, reject);
if (err) {
return reject(err);
}
} catch (e) {
reject(e);
}

resolve();
});
});

if (result instanceof Promise) {
await result;
}
}

/**
Expand Down Expand Up @@ -496,15 +496,15 @@ export class CLI {
.option('-s, --sdk [version]', `Titanium SDK version to use ${gray('(default: "latest")')}`)
.on('option:config', cfg => {
try {
config.apply(eval(`(${cfg})`));
if (!config.cli?.colors) {
this.config.apply(eval(`(${cfg})`));
if (!this.config.cli?.colors) {
chalk.level = 0;
}
} catch (e) {
throw new Error(`Failed to parse --config: ${e.message}`);
}
})
.on('option:config-file', file => config.load(file))
.on('option:config-file', file => this.config.load(file))
.on('option:log-level', level => this.logger.setLevel(level))
.on('option:no-banner', () => this.logger.bannerEnabled(false))
.on('option:no-color', () => chalk.level = 0)
Expand Down Expand Up @@ -539,13 +539,13 @@ export class CLI {
.filter(name => conf.options && conf.options[name] && !skipRegExp.test(name))
.sort((a, b) => {
// if we have multiple option groups, then try to process them in order
if (!options[a] || !options[a].order) {
if (!conf.options[a] || !conf.options[a].order) {
return 1;
}
if (!options[b] || !options[b].order) {
if (!conf.options[b] || !conf.options[b].order) {
return -1;
}
return options[b].order - options[a].order;
return conf.options[b].order - conf.options[a].order;
});

for (const name of optionBranches) {
Expand Down Expand Up @@ -739,7 +739,7 @@ export class CLI {
conflicting.map((c, i) => {
return i === 0
? ` Loaded: ${c.file} ${c.version ? `(version ${version})` : ''}`
: ` Didn't load: ${c.file} ${c.version ? `(version ${version})` : ''}`
: ` Didn't load: ${c.file} ${c.version ? `(version ${version})` : ''}`;
}).join('\n')
}`)
.join('\n')
Expand Down Expand Up @@ -829,7 +829,7 @@ export class CLI {
try {
const jsfile = /\.js$/;
const ignore = /^[._]/;
const files = fs.statSync(dir).isDirectory() ? fs.readdirSync(dir).map(n => join(dir, n)) : [ dir ];
const files = fs.statSync(dir).isDirectory() ? fs.readdirSync(dir).map(n => join(dir, n)) : [dir];
let appc;

for (const file of files) {
Expand Down Expand Up @@ -951,6 +951,7 @@ export class CLI {

// this while loop is essentially a pump that processes missing/invalid
// options one at a time, recalculating them each iteration
// eslint-disable-next-line no-constant-condition
while (true) {
const invalid = {};
let invalidCount = 0;
Expand Down Expand Up @@ -1044,7 +1045,7 @@ export class CLI {
if (Object.keys(invalid).length) {
for (const name of Object.keys(invalid)) {
const opt = invalid[name];
const msg = `Invalid "${opt.label || `--${name}`}" value "${argv[opt.name]}"`;
const msg = `Invalid "${opt.label || `--${name}`}" value "${this.argv[opt.name]}"`;

if (typeof opt.helpNoPrompt === 'function') {
opt.helpNoPrompt(this.logger, msg);
Expand Down
6 changes: 4 additions & 2 deletions src/commands/config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable max-len */

import chalk from 'chalk';
import { ticonfig } from '../util/ticonfig.js';
import { TiError } from '../util/tierror.js';
Expand Down Expand Up @@ -84,7 +86,7 @@ export function validate(_logger, _config, cli) {
if (cli.argv.remove) {
if (len === 0) {
throw new TiError('Missing key of the config setting to remove', {
after: `Run ${cyan(`titanium config --remove <key>`)} to remove the config setting.`
after: `Run ${cyan('titanium config --remove <key>')} to remove the config setting.`
});
}

Expand Down Expand Up @@ -171,7 +173,7 @@ export async function run(logger, config, cli) {
for (let v of argv._) {
v = expand(v);
if (!config.paths[subPath].includes(v)) {
config.paths[subPath].push(v)
config.paths[subPath].push(v);
}
}
} else if (argv.remove) {
Expand Down
3 changes: 2 additions & 1 deletion src/commands/info.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { BusyIndicator } from '../util/busyindicator.js';
import chalk from 'chalk';
import { detect } from '../util/detect.js';
import wrapAnsi from 'wrap-ansi';
import { basename } from 'node:path';

const { bold, cyan, gray, magenta, red, yellow } = chalk;
const typesList = ['all', 'os', 'nodejs', 'titanium', 'jdk', 'android', 'ios'];
Expand Down Expand Up @@ -179,7 +180,7 @@ export async function run(logger, config, cli) {
// the keychain names are the only left side label that isn't fixed length, so
// if we're displaying ios info, find the longest keychain name
for (const keychain of data.iosKeychains) {
indent = max(indent, path.basename(keychain).length + 2);
indent = Math.max(indent, basename(keychain).length + 2);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/commands/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,4 @@ ModuleSubcommands.list = {
}
}
}
}
};
13 changes: 7 additions & 6 deletions src/commands/sdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ SdkSubcommands.list = {
async fn(logger, config, cli) {
const os = cli.env.os.name;

const [ releases, branches, branchBuilds ] = (await Promise.allSettled([
const [releases, branches, branchBuilds] = (await Promise.allSettled([
(cli.argv.releases || cli.argv.unstable) && getReleases(cli.argv.unstable),
cli.argv.branches && getBranches(),
cli.argv.branch && getBranchBuilds(cli.argv.branch, os)
Expand Down Expand Up @@ -393,7 +393,7 @@ SdkSubcommands.install = {
}

const destDir = join(modulesDest, platform, moduleName, ver);
if (!force || fs.statSync(destDir).isDirectory()) {
if (!cli.argv.force || fs.statSync(destDir).isDirectory()) {
continue;
}

Expand Down Expand Up @@ -677,6 +677,7 @@ async function checkSDKFile({ force, logger, filename, name, noPrompt, osName, s
}

let renameTo;
// eslint-disable-next-line no-constant-condition
for (let i = 2; true; i++) {
try {
renameTo = `${name}-${i}`;
Expand Down Expand Up @@ -779,7 +780,7 @@ SdkSubcommands.uninstall = {

if (!found.length) {
for (const v of versions) {
logger.log(` • ${cyan(v.padEnd(maxlen))} ${cli.env.sdks[v]?.path || yellow('not found')}`)
logger.log(` • ${cyan(v.padEnd(maxlen))} ${cli.env.sdks[v]?.path || yellow('not found')}`);
}
process.exit(0);
}
Expand All @@ -788,7 +789,7 @@ SdkSubcommands.uninstall = {
// prompt for confirmation
logger.log(`${yellow('WARNING!')} This will permanently remove the following Titanium SDKs:\n`);
for (const v of versions) {
logger.log(` • ${cyan(v.padEnd(maxlen))} ${cli.env.sdks[v]?.path || yellow('not found')}`)
logger.log(` • ${cyan(v.padEnd(maxlen))} ${cli.env.sdks[v]?.path || yellow('not found')}`);
}
logger.log();

Expand Down Expand Up @@ -852,8 +853,8 @@ async function getBranches() {
});
return Object
.entries(await res.body.json())
.filter(([ , count ]) => count)
.map(([ name ]) => name);
.filter(([, count]) => count)
.map(([name]) => name);
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/util/apply-command-config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Argument, Command, Option } from 'commander';
import { ticonfig } from './ticonfig.js';
import { TiError } from './tierror.js';

export function applyCommandConfig(cmdName, cmd, conf) {
if (conf.title) {
Expand Down
2 changes: 1 addition & 1 deletion src/util/arrayify.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
* @returns {Array}
*/
export function arrayify(it, removeFalsey) {
const arr = typeof it === 'undefined' ? [] : it instanceof Set ? Array.from(it) : Array.isArray(it) ? it : [ it ];
const arr = typeof it === 'undefined' ? [] : it instanceof Set ? Array.from(it) : Array.isArray(it) ? it : [it];
return removeFalsey ? arr.filter(v => typeof v !== 'undefined' && v !== null && v !== '' && v !== false && (typeof v !== 'number' || !isNaN(v))) : arr;
}
4 changes: 3 additions & 1 deletion src/util/detect.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { detectTitaniumSDKs } from './tisdk.js';
import { join } from 'node:path';
import { pathToFileURL } from 'node:url';
import chalk from 'chalk';
import { readFile } from 'node:fs/promises';

const { cyan } = chalk;

Expand Down Expand Up @@ -99,6 +100,7 @@ async function osInfo() {
let version = '?';
let m;
let n;
let _;

if (name === 'darwin') {
const { stdout } = await $`sw_vers`;
Expand Down Expand Up @@ -159,7 +161,7 @@ async function titaniumInfo(config) {
platforms: Object.keys(sdk.platforms),
githash: sdk.githash,
timestamp: sdk.timestamp
}
};
}

return results;
Expand Down
6 changes: 3 additions & 3 deletions src/util/jdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export async function detect(config) {
} catch {}

try {
const p = await which('javac');
let p = await which('javac');
p = await realpath(dirname(dirname(p)));
if (!jdkPaths.includes(p) && isJDK(p)) {
jdkPaths.push(p);
Expand Down Expand Up @@ -113,8 +113,8 @@ export async function detect(config) {
type: 'warning',
message: `JDK (Java Development Kit) at ${home} missing required programs: __${missingTools.join(', ')}__
${process.env.JAVA_HOME
? `Please verify your __JAVA_HOME__ environment variable is correctly set to the JDK install location\n__JAVA_HOME__ is currently set to "${process.env.JAVA_HOME}".`
: 'Please set the __JAVA_HOME__ environment variable to the JDK install location and not the JRE (Java Runtime Environment).'}
? `Please verify your __JAVA_HOME__ environment variable is correctly set to the JDK install location\n__JAVA_HOME__ is currently set to "${process.env.JAVA_HOME}".`
: 'Please set the __JAVA_HOME__ environment variable to the JDK install location and not the JRE (Java Runtime Environment).'}
The __JAVA_HOME__ environment variable must point to the JDK and not the JRE (Java Runtime Environment).
You may want to reinstall the JDK by downloading it from __https://www.oracle.com/java/technologies/downloads/__
or __https://jdk.java.net/archive/__.`
Expand Down
2 changes: 1 addition & 1 deletion src/util/progress.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class ProgressBar {
incomplete = Array(incomplete + 1).join(this.chars.incomplete);

// The extra space at the end prevents shrinking progress bars from ghosting
const str = this.fmt
let str = this.fmt
.replace(':bar', complete + incomplete)
.replace(':current', this.curr)
.replace(':total', this.total)
Expand Down
Loading

0 comments on commit 089ae24

Please sign in to comment.