Skip to content

Commit

Permalink
fix: add ts strict null checks (#677)
Browse files Browse the repository at this point in the history
* fix: add strict null checks

@W-12220467@

* chore: remove unneeded dev dep

* chore: dep cleanup

---------

Co-authored-by: mshanemc <[email protected]>
  • Loading branch information
peternhale and mshanemc authored Apr 24, 2023
1 parent d8fe80f commit 239a175
Show file tree
Hide file tree
Showing 12 changed files with 184 additions and 226 deletions.
3 changes: 3 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@
*/
module.exports = {
extends: ['eslint-config-salesforce-typescript', 'eslint-config-salesforce-license', 'plugin:sf-plugin/recommended'],
rules: {
'jsdoc/newline-after-description': 'off',
},
};
26 changes: 11 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@
"bugs": "https://github.com/forcedotcom/cli/issues",
"main": "lib/index.js",
"dependencies": {
"@oclif/core": "^2.6.4",
"@salesforce/core": "^3.34.1",
"@oclif/core": "^2.8.2",
"@salesforce/core": "^3.34.7",
"@salesforce/kit": "^1.9.2",
"@salesforce/sf-plugins-core": "^2.2.5",
"@salesforce/sf-plugins-core": "^2.2.9",
"chalk": "^4.1.2",
"fs-extra": "^10.0.1",
"inquirer": "^8.2.5",
"open": "^8.2.1",
"tslib": "^2"
Expand All @@ -21,27 +20,24 @@
"@salesforce/cli-plugins-testkit": "^3.3.3",
"@salesforce/dev-config": "^3.1.0",
"@salesforce/dev-scripts": "^4.3.0",
"@salesforce/plugin-command-reference": "^2",
"@salesforce/plugin-command-reference": "^2.2.9",
"@salesforce/plugin-settings": "^1.4.4",
"@salesforce/prettier-config": "^0.0.2",
"@salesforce/ts-sinon": "^1.4.4",
"@swc/core": "1.3.30",
"@types/fs-extra": "^9.0.13",
"@types/graceful-fs": "^4.1.6",
"@salesforce/ts-sinon": "^1.4.6",
"@swc/core": "1.3.39",
"@types/inquirer": "^8.2.0",
"@types/mkdirp": "^1.0.1",
"@typescript-eslint/eslint-plugin": "^5.59.0",
"@typescript-eslint/parser": "^5.58.0",
"@typescript-eslint/parser": "^5.59.0",
"chai": "^4.3.7",
"eslint": "^8.39.0",
"eslint-config-prettier": "^8.8.0",
"eslint-config-salesforce": "^1.2.0",
"eslint-config-salesforce-license": "^0.2.0",
"eslint-config-salesforce-typescript": "^1.1.1",
"eslint-plugin-header": "^3.0.0",
"eslint-plugin-header": "^3.1.1",
"eslint-plugin-import": "2.27.5",
"eslint-plugin-jsdoc": "^39.9.1",
"eslint-plugin-sf-plugin": "^1.14.0",
"eslint-plugin-jsdoc": "^43.0.7",
"eslint-plugin-sf-plugin": "^1.15.1",
"husky": "^7.0.4",
"mocha": "^9.1.3",
"nyc": "^15.1.0",
Expand All @@ -51,7 +47,7 @@
"shx": "0.3.4",
"sinon": "10.0.0",
"ts-node": "^10.0.0",
"typescript": "^4.9.4",
"typescript": "^4.9.5",
"wireit": "^0.9.5"
},
"engines": {
Expand Down
11 changes: 5 additions & 6 deletions src/commands/org/list/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default class ListAuth extends SfCommand<AuthListResults> {
public static readonly description = messages.getMessage('description');
public static readonly examples = messages.getMessages('examples');
public static readonly deprecateAliases = true;
public static aliases = ['force:auth:list', 'auth:list'];
public static readonly aliases = ['force:auth:list', 'auth:list'];

public static readonly flags = {
loglevel,
Expand All @@ -31,13 +31,12 @@ export default class ListAuth extends SfCommand<AuthListResults> {
this.log(messages.getMessage('noResultsFound'));
return [];
}
const mappedAuths = auths.map((auth: OrgAuthorization & { alias: string }) => {
const mappedAuths: AuthListResults = auths.map((auth: OrgAuthorization) => {
const { aliases, ...rest } = auth;
// core3 moved to aliases as a string[], revert to alias as a string
auth.alias = auth.aliases ? auth.aliases.join(',') : '';

delete auth.aliases;
return auth;
return { ...rest, alias: aliases ? aliases.join(',') : '' };
});

const hasErrors = auths.filter((auth) => !!auth.error).length > 0;
let columns = {
alias: { header: 'ALIAS' },
Expand Down
2 changes: 1 addition & 1 deletion src/commands/org/login/access-token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export default class LoginAccessToken extends AuthBaseCommand<AuthFields> {
loglevel,
};

private flags: Interfaces.InferredFlags<typeof LoginAccessToken.flags>;
private flags!: Interfaces.InferredFlags<typeof LoginAccessToken.flags>;

public async run(): Promise<AuthFields> {
const { flags } = await this.parse(LoginAccessToken);
Expand Down
2 changes: 1 addition & 1 deletion src/commands/org/login/jwt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export default class LoginJwt extends AuthBaseCommand<AuthFields> {
}),
loglevel,
};
private flags: Interfaces.InferredFlags<typeof LoginJwt.flags>;
private flags!: Interfaces.InferredFlags<typeof LoginJwt.flags>;
private logger = Logger.childFromRoot(this.constructor.name);

public async run(): Promise<AuthFields> {
Expand Down
8 changes: 4 additions & 4 deletions src/commands/org/login/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export default class LoginWeb extends AuthBaseCommand<AuthFields> {
loglevel,
};

private flags: Interfaces.InferredFlags<typeof LoginWeb.flags>;
private flags!: Interfaces.InferredFlags<typeof LoginWeb.flags>;

public async run(): Promise<AuthFields> {
const { flags } = await this.parse(LoginWeb);
Expand Down Expand Up @@ -130,9 +130,9 @@ export default class LoginWeb extends AuthBaseCommand<AuthFields> {
private async executeLoginFlow(oauthConfig: OAuth2Config): Promise<AuthInfo> {
const oauthServer = await WebOAuthServer.create({ oauthConfig });
await oauthServer.start();
const openOptions = this.flags.browser
? { app: { name: open.apps[this.flags.browser] as open.AppName }, wait: false }
: { wait: false };
const app =
this.flags.browser && this.flags.browser in open.apps ? (this.flags.browser as open.AppName) : undefined;
const openOptions = app ? { app: { name: open.apps[app] }, wait: false } : { wait: false };
await open(oauthServer.getAuthorizationUrl(), openOptions);
return oauthServer.authorizeAndSave();
}
Expand Down
2 changes: 1 addition & 1 deletion src/commands/org/logout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export default class Logout extends AuthBaseCommand<AuthLogoutResults> {
loglevel,
};

private flags: Interfaces.InferredFlags<typeof Logout.flags>;
private flags!: Interfaces.InferredFlags<typeof Logout.flags>;

private static buildChoices(orgAuths: OrgAuthorization[], all: boolean): Array<choice | Separator> {
const maxUsernameLength = Math.max('Username'.length, ...orgAuths.map((orgAuth) => orgAuth.username.length));
Expand Down
1 change: 1 addition & 0 deletions test/commands/scratch-identify.nut.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
*/

import * as path from 'path';
import { expect } from 'chai';

Expand Down
51 changes: 26 additions & 25 deletions test/common.test.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
*/

import { ConfigContents, SfdcUrl, SfError } from '@salesforce/core';
import { expect } from 'chai';
import { TestContext, uniqid } from '@salesforce/core/lib/testSetup';
Expand Down Expand Up @@ -38,10 +39,10 @@ describe('common unit tests', () => {
packageDirectories: [
{
path: 'force-app',
default: true
}
default: true,
},
],
sourceApiVersion: '50.0'
sourceApiVersion: '50.0',
});
const loginUrl = await Common.resolveLoginUrl(undefined);
expect(loginUrl).to.equal(SfdcUrl.PRODUCTION);
Expand All @@ -51,11 +52,11 @@ describe('common unit tests', () => {
packageDirectories: [
{
path: 'force-app',
default: true
}
default: true,
},
],
sfdcLoginUrl: 'https://login.salesforce.com',
sourceApiVersion: '50.0'
sourceApiVersion: '50.0',
});
const loginUrl = await Common.resolveLoginUrl(undefined);
expect(loginUrl).to.equal(SfdcUrl.PRODUCTION);
Expand All @@ -65,11 +66,11 @@ describe('common unit tests', () => {
packageDirectories: [
{
path: 'force-app',
default: true
}
default: true,
},
],
sfdcLoginUrl: 'https://shanedevhub.lightning.force.com',
sourceApiVersion: '50.0'
sourceApiVersion: '50.0',
});
try {
await Common.resolveLoginUrl(undefined);
Expand Down Expand Up @@ -105,25 +106,25 @@ describe('common unit tests', () => {
packageDirectories: [
{
path: 'force-app',
default: true
}
default: true,
},
],
sourceApiVersion: '50.0'
}
sourceApiVersion: '50.0',
},
});
const loginUrl = await Common.resolveLoginUrl(INSTANCE_URL_1);
expect(loginUrl).to.equal(INSTANCE_URL_1);
});
it('should return custom login URL if project with property sfdcLoginUrl present and not equal to production URL', async () => {
await projectSetup($$, true, {
packageDirectories: [
{
path: 'force-app',
default: true
}
],
sfdcLoginUrl: INSTANCE_URL_2,
sourceApiVersion: '50.0'
packageDirectories: [
{
path: 'force-app',
default: true,
},
],
sfdcLoginUrl: INSTANCE_URL_2,
sourceApiVersion: '50.0',
});
const loginUrl = await Common.resolveLoginUrl(undefined);
expect(loginUrl).to.equal(INSTANCE_URL_2);
Expand All @@ -134,12 +135,12 @@ describe('common unit tests', () => {
packageDirectories: [
{
path: 'force-app',
default: true
}
default: true,
},
],
sfdcLoginUrl: INSTANCE_URL_2,
sourceApiVersion: '50.0'
}
sourceApiVersion: '50.0',
},
});
const loginUrl = await Common.resolveLoginUrl(INSTANCE_URL_1);
expect(loginUrl).to.equal(INSTANCE_URL_1);
Expand Down
2 changes: 1 addition & 1 deletion test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "@salesforce/dev-config/tsconfig-test",
"extends": "@salesforce/dev-config/tsconfig-test-strict",
"include": ["./**/*.ts"],
"compilerOptions": {
"skipLibCheck": true,
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "@salesforce/dev-config/tsconfig",
"extends": "@salesforce/dev-config/tsconfig-strict",
"compilerOptions": {
"outDir": "lib",
"rootDir": "src",
Expand Down
Loading

0 comments on commit 239a175

Please sign in to comment.