Skip to content
This repository has been archived by the owner on Jul 10, 2023. It is now read-only.

Commit

Permalink
fix: ts errors and changd eslint comment rule name
Browse files Browse the repository at this point in the history
  • Loading branch information
mshanemc committed Nov 18, 2021
1 parent 71464d0 commit 8c021c2
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 22 deletions.
10 changes: 5 additions & 5 deletions src/sfdxCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export abstract class SfdxCommand extends Command {
await this.init();
return (this.result.data = await this.run());
} catch (e) {
err = e;
err = e as Error;
await this.catch(e);
} finally {
await this.finally(err);
Expand All @@ -190,7 +190,7 @@ export abstract class SfdxCommand extends Command {
try {
this.project = await SfdxProject.resolve();
} catch (err) {
if (err.name === 'InvalidProjectWorkspace') {
if (err instanceof Error && err.name === 'InvalidProjectWorkspace') {
throw SfdxError.create('@salesforce/command', 'command', 'RequiresProjectError');
}
throw err;
Expand All @@ -210,7 +210,7 @@ export abstract class SfdxCommand extends Command {
}
} catch (err) {
if (this.statics.requiresUsername) {
if (err.name === 'NoUsername' || err.name === 'AuthInfoCreationError') {
if (err instanceof Error && (err.name === 'NoUsername' || err.name === 'AuthInfoCreationError')) {
throw SfdxError.create('@salesforce/command', 'command', 'RequiresUsernameError');
}
throw err;
Expand All @@ -233,7 +233,7 @@ export abstract class SfdxCommand extends Command {
} catch (err) {
// Throw an error if the command requires a devhub and there is no targetdevhubusername
// flag set and no defaultdevhubusername set.
if (this.statics.requiresDevhubUsername) {
if (this.statics.requiresDevhubUsername && err instanceof Error) {
if (err.name === 'AuthInfoCreationError' || err.name === 'NoUsername') {
throw SfdxError.create('@salesforce/command', 'command', 'RequiresDevhubUsernameError');
}
Expand Down Expand Up @@ -394,7 +394,7 @@ export abstract class SfdxCommand extends Command {
}
// Emit an event for the analytics plugin. The ts-ignore is necessary
// because TS is strict about the events that can be emitted on process.
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
process.emit('cmdError', err, Object.assign({}, this.flags, this.varargs), this.org || this.hubOrg);
}
Expand Down
6 changes: 3 additions & 3 deletions src/sfdxFlags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ function merge<T>(
function merge<T>(kind: flags.Kind, flag: IFlag<T>, describable: flags.Describable): flags.Discriminated<flags.Any<T>> {
if (has(flag, 'validate') && hasFunction(flag, 'parse')) {
const parse = flag.parse.bind(flag);
flag.parse = <T>(val: string, ctx: unknown): T => {
flag.parse = <T2>(val: string, ctx: unknown): T2 => {
validateValue(toValidatorFn(flag.validate)(val), val, kind);
return parse(val, ctx) as T;
return parse(val, ctx) as T2;
};
}

Expand Down Expand Up @@ -648,7 +648,7 @@ function validateCustomFlag<T>(key: string, flag: flags.Any<T>): flags.Any<T> {
return flag;
}

function isBuiltin(flag: object): flag is flags.Builtin {
function isBuiltin(flag: Record<string, unknown>): flag is flags.Builtin {
return hasString(flag, 'type') && flag.type === 'builtin';
}

Expand Down
1 change: 1 addition & 0 deletions src/ux.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
/* eslint-disable @typescript-eslint/ban-types */
import { env } from '@salesforce/kit';
import { ensure } from '@salesforce/ts-types';

Expand Down
18 changes: 10 additions & 8 deletions test/unit/sfdxCommand.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ let jsonToStdout: boolean;
async function mockStdout(test: (outLines: string[]) => Promise<void>) {
const oldStdoutWriter = process.stdout.write.bind(process.stdout);
const lines: string[] = [];
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore TODO: why isn't `create` invokable?!
process.stdout.write = (message) => {
if (message) {
lines.push(message);
Expand Down Expand Up @@ -1116,7 +1116,7 @@ describe('SfdxCommand', () => {
const create = flags[flagType];
class TestCommand extends BaseTestCommand {
public static flagsConfig = {
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore TODO: why isn't `create` invokable?!
doflag: create({ char: 'i', description: 'my desc' }),
};
Expand All @@ -1125,6 +1125,8 @@ describe('SfdxCommand', () => {
if (err) {
const sfdxError = SfdxError.create('@salesforce/command', 'flags', 'InvalidFlagTypeError', [
val,
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore kind doesn't exist
TestCommand.flagsConfig.doflag.kind,
ERR_NEXT_STEPS[flagType] || '',
]);
Expand Down Expand Up @@ -1221,7 +1223,7 @@ describe('SfdxCommand', () => {
TestCommand.flagsConfig = {
myflag: flags.string({
char: 'm',
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore ignore invalid longDescription value
longDescription: false,
description: 'my desc',
Expand All @@ -1235,7 +1237,7 @@ describe('SfdxCommand', () => {
it('should validate description is defined', async () => {
class TestCommand extends BaseTestCommand {}
TestCommand.flagsConfig = {
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore ignore error about not providing description
myflag: flags.string({ char: 'm' }),
};
Expand All @@ -1247,7 +1249,7 @@ describe('SfdxCommand', () => {
class TestCommand extends BaseTestCommand {}
TestCommand.flagsConfig = {
myflag: flags.string({
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore ignore invalid char value length
char: 'foo',
description: 'bar',
Expand All @@ -1260,7 +1262,7 @@ describe('SfdxCommand', () => {
it('should validate char is alphabetical', async () => {
class TestCommand extends BaseTestCommand {}
TestCommand.flagsConfig = {
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore ignore invalid char value
myflag: flags.string({ char: '5', description: 'bar' }),
};
Expand Down Expand Up @@ -1301,7 +1303,7 @@ describe('SfdxCommand', () => {
}),
};

// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore Allow undefined array value against the compiler spec to test underlying engine
const output = await TestCommand.run(['--myflag', undefined]);
expect(output).to.equal(undefined);
Expand Down
2 changes: 1 addition & 1 deletion test/unit/sfdxFlags.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describe('SfdxFlags', () => {
it('should carry forward additional properties on builtins when forced (for legacy toolbelt compatibility)', () => {
const rv = buildSfdxFlags(
{
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore force setting the char to simulate a legacy toolbelt use case
apiversion: flags.builtin({ char: 'a' }),
},
Expand Down
10 changes: 5 additions & 5 deletions test/unit/ux.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ describe('UX', () => {
});

it('logJson() should log to the logger (unformatted) and stdout (formatted)', () => {
let retVal: Optional<object>;
let retVal: Optional<Record<string, unknown>>;
const info = $$.SANDBOX.stub($$.TEST_LOGGER, 'info');
const styledJsonGetter = () => (x: object) => (retVal = x);
const styledJsonGetter = () => (x: Record<string, unknown>) => (retVal = x);
$$.SANDBOX.stub(cli, 'styledJSON').get(styledJsonGetter);
const ux = new UX($$.TEST_LOGGER, true, cli);
const logMsg = { key1: 'foo', key2: 9, key3: true, key4: [1, 2, 3] };
Expand Down Expand Up @@ -269,9 +269,9 @@ describe('UX', () => {
});

it('table() should only log to the logger when output IS NOT enabled', () => {
let retVal: Optional<object>;
let retVal: Optional<Record<string, unknown>>;
const info = $$.SANDBOX.stub($$.TEST_LOGGER, 'info');
const tableGetter = () => (x: object) => (retVal = x);
const tableGetter = () => (x: Record<string, unknown>) => (retVal = x);
$$.SANDBOX.stub(cli, 'table').get(tableGetter);
const ux = new UX($$.TEST_LOGGER, false, cli);
const tableData = [
Expand Down Expand Up @@ -364,7 +364,7 @@ describe('UX', () => {
const question = 'City?';
const answer = 'Louisville';
const ux = new UX($$.TEST_LOGGER, true, cli);
const promptGetter = () => (name: string, options: object) => {
const promptGetter = () => (name: string, options: Record<string, unknown>) => {
expect(name).to.equal(question);
expect(options).to.eql({});
return answer;
Expand Down

0 comments on commit 8c021c2

Please sign in to comment.