Skip to content

Commit e294798

Browse files
SF-CLI-BOTmshanemc
SF-CLI-BOT
andauthored
feat: create on asyncOptionalCreatable requires that P extend object
* chore: updates from devScripts * chore: linter updates * feat: create on asyncOptionalCreatable requires that P extend object * refactor: the tests say object is better Co-authored-by: mshanemc <shane.mclaughlin@salesforce.com>
1 parent da85f8e commit e294798

File tree

7 files changed

+683
-456
lines changed

7 files changed

+683
-456
lines changed

package.json

+12-13
Original file line numberDiff line numberDiff line change
@@ -35,30 +35,29 @@
3535
"tslib": "^2.2.0"
3636
},
3737
"devDependencies": {
38-
"@salesforce/dev-config": "^2.1.3",
39-
"@salesforce/dev-scripts": "^1.0.0",
38+
"@salesforce/dev-config": "^3.0.0",
39+
"@salesforce/dev-scripts": "^3.1.0",
4040
"@salesforce/prettier-config": "^0.0.2",
41-
"@typescript-eslint/eslint-plugin": "^4.2.0",
42-
"@typescript-eslint/parser": "^4.2.0",
41+
"@typescript-eslint/eslint-plugin": "^5.33.0",
42+
"@typescript-eslint/parser": "^5.33.0",
4343
"chai": "^4.2.0",
44-
"eslint": "^7.27.0",
45-
"eslint-config-prettier": "^6.11.0",
46-
"eslint-config-salesforce": "^0.1.6",
44+
"eslint": "^8.21.0",
45+
"eslint-config-prettier": "^8.5.0",
46+
"eslint-config-salesforce": "^1.1.0",
4747
"eslint-config-salesforce-license": "^0.1.6",
48-
"eslint-config-salesforce-typescript": "^0.2.7",
48+
"eslint-config-salesforce-typescript": "^1.1.1",
4949
"eslint-plugin-header": "^3.0.0",
5050
"eslint-plugin-import": "2.26.0",
51-
"eslint-plugin-jsdoc": "^35.1.2",
51+
"eslint-plugin-jsdoc": "^39.3.6",
5252
"eslint-plugin-prefer-arrow": "^1.2.1",
53-
"eslint-plugin-prettier": "^3.1.3",
5453
"husky": "^7.0.4",
5554
"lodash-cli": "^4.17.5",
56-
"mocha": "^8.4.0",
55+
"mocha": "^9.1.3",
5756
"nyc": "^15.1.0",
58-
"prettier": "^2.0.5",
57+
"prettier": "^2.7.1",
5958
"pretty-quick": "^3.1.0",
6059
"sinon": "10.0.0",
6160
"ts-node": "^10.0.0",
6261
"typescript": "^4.8.4"
6362
}
64-
}
63+
}

src/creatable.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export abstract class AsyncOptionalCreatable<O = object> {
5757
*
5858
* @param options An options object providing initialization params to the async constructor.
5959
*/
60-
public static async create<P, T extends AsyncOptionalCreatable<P>>(
60+
public static async create<P extends object, T extends AsyncOptionalCreatable<P>>(
6161
this: new (opts?: P) => T,
6262
options?: P
6363
): Promise<T> {

src/env.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { toNumber, toBoolean } from './nodash';
1414
* for accessing environment variables of different anticipated shapes.
1515
*/
1616
export class Env {
17-
public constructor(private store: Dictionary<string> = (process && process.env) || {}) {
17+
public constructor(private store: Dictionary<string> = process?.env || {}) {
1818
this.store = store;
1919
}
2020

@@ -33,7 +33,7 @@ export class Env {
3333
public getString(key: string, def: string): string;
3434
// underlying method
3535
public getString(key: string, def?: string): Optional<string> {
36-
return this.store[key] || def;
36+
return this.store[key] ?? def;
3737
}
3838

3939
/**

src/errors.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export class NamedError extends Error {
3333

3434
public get fullStack(): string | undefined {
3535
let stack = this.stack;
36-
const causedStack = this.cause?.fullStack || this.cause?.stack;
36+
const causedStack = this.cause?.fullStack ?? this.cause?.stack;
3737
if (causedStack) {
3838
stack = `${stack ? stack + '\n' : ''}Caused by: ${causedStack}`;
3939
}
@@ -82,7 +82,7 @@ export class JsonParseError extends NamedError {
8282

8383
private static format(cause: Error, path?: string, line?: number, errorPortion?: string): string {
8484
if (line == null) return cause.message || 'Unknown cause';
85-
return `Parse error in file ${path || 'unknown'} on line ${line}\n${errorPortion || cause.message}`;
85+
return `Parse error in file ${path ?? 'unknown'} on line ${line}\n${errorPortion ?? cause.message}`;
8686
}
8787
}
8888

src/nodash/internal.ts

+5-8
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,11 @@ export function snakeCase(str: string): string;
6060
export function snakeCase(str?: string): Optional<string>;
6161
// underlying function
6262
export function snakeCase(str?: string): Optional<string> {
63-
return (
64-
str &&
65-
str
66-
.replace(/([a-z])([A-Z])/g, '$1_$2')
67-
.toLowerCase()
68-
.replace(/\W/g, '_')
69-
.replace(/^_+|_+$/g, '')
70-
);
63+
return str
64+
?.replace(/([a-z])([A-Z])/g, '$1_$2')
65+
.toLowerCase()
66+
.replace(/\W/g, '_')
67+
.replace(/^_+|_+$/g, '');
7168
}
7269

7370
/**

test/creatable.test.ts

+2
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ class OptionalConfig extends AsyncOptionalCreatable<OptionalConfig.Options> {
6565
return this.options ? this.options.bazEnabled : false;
6666
}
6767

68+
// eslint-disable-next-line class-methods-use-this
6869
protected async init(): Promise<void> {
6970
// Imagine cool async stuff here
7071
}
@@ -81,6 +82,7 @@ class NoOptionsConfig extends AsyncOptionalCreatable {
8182
super();
8283
}
8384

85+
// eslint-disable-next-line class-methods-use-this
8486
protected async init(): Promise<void> {
8587
// Imagine cool async stuff here
8688
}

0 commit comments

Comments
 (0)