Skip to content

Commit 08f561f

Browse files
refactor: move default values into destructuring assignments
Agent-Logs-Url: https://github.com/microsoft/rushstack/sessions/2fa38687-8cb7-4932-b927-0db70e54c476 Co-authored-by: dmichon-msft <26827560+dmichon-msft@users.noreply.github.com>
1 parent e1a7891 commit 08f561f

10 files changed

Lines changed: 62 additions & 46 deletions

File tree

apps/heft/src/cli/actions/PhaseAction.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,20 @@ export class PhaseAction extends CommandLineAction implements IHeftAction {
2020
private _selectedPhases: Set<HeftPhase> | undefined;
2121

2222
public constructor(options: IPhaseActionOptions) {
23-
const { phase, watch } = options;
23+
const { phase, watch = false } = options;
24+
const { phaseName, phaseDescription } = phase;
2425
super({
25-
actionName: `${phase.phaseName}${watch ? '-watch' : ''}`,
26+
actionName: `${phaseName}${watch ? '-watch' : ''}`,
2627
documentation:
27-
`Runs to the ${phase.phaseName} phase, including all transitive dependencies` +
28+
`Runs to the ${phaseName} phase, including all transitive dependencies` +
2829
(watch ? ', in watch mode.' : '.') +
29-
(phase.phaseDescription ? ` ${phase.phaseDescription}` : ''),
30+
(phaseDescription ? ` ${phaseDescription}` : ''),
3031
summary:
31-
`Runs to the ${phase.phaseName} phase, including all transitive dependencies` +
32+
`Runs to the ${phaseName} phase, including all transitive dependencies` +
3233
(watch ? ', in watch mode.' : '.')
3334
});
3435

35-
this.watch = watch ?? false;
36+
this.watch = watch;
3637
this._phase = phase;
3738
this._actionRunner = new HeftActionRunner({ action: this, ...options });
3839
this._actionRunner.defineParameters();

libraries/operation-graph/src/Operation.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,12 +198,12 @@ export class Operation<TMetadata extends {} = {}, TGroupMetadata extends {} = {}
198198
public readonly metadata: TMetadata;
199199

200200
public constructor(options: IOperationOptions<TMetadata, TGroupMetadata>) {
201-
const { group, runner, weight, name, metadata } = options;
201+
const { group, runner, weight = 1, name, metadata = {} as TMetadata } = options;
202202
this.group = group;
203203
this.runner = runner;
204-
this.weight = weight ?? 1;
204+
this.weight = weight;
205205
this.name = name;
206-
this.metadata = metadata || ({} as TMetadata);
206+
this.metadata = metadata;
207207

208208
if (this.group) {
209209
this.group.addOperation(this);

libraries/rush-lib/src/cli/scriptActions/PhasedScriptAction.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ export class PhasedScriptAction extends BaseScriptAction<IPhasedCommandConfig> i
182182
originalPhases,
183183
initialPhases,
184184
watchPhases,
185-
watchDebounceMs,
185+
watchDebounceMs = RushConstants.defaultWatchDebounceMs,
186186
alwaysWatch,
187187
alwaysInstall,
188188
phases
@@ -194,7 +194,7 @@ export class PhasedScriptAction extends BaseScriptAction<IPhasedCommandConfig> i
194194
this._originalPhases = originalPhases;
195195
this._initialPhases = initialPhases;
196196
this._watchPhases = watchPhases;
197-
this._watchDebounceMs = watchDebounceMs ?? RushConstants.defaultWatchDebounceMs;
197+
this._watchDebounceMs = watchDebounceMs;
198198
this._alwaysWatch = alwaysWatch;
199199
this._alwaysInstall = alwaysInstall;
200200
this._runsBeforeInstall = false;

libraries/rush-lib/src/utilities/RushAlerts.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,14 @@ export class RushAlerts {
103103
rushAlertsStateFilePath,
104104
rushAlertsConfigFilePath,
105105
rushAlertsConfig,
106-
rushAlertsState
106+
rushAlertsState = {}
107107
} = options;
108108
this._terminal = terminal;
109109
this._rushJsonFolder = rushJsonFolder;
110110
this.rushAlertsStateFilePath = rushAlertsStateFilePath;
111111
this.rushAlertsConfigFilePath = rushAlertsConfigFilePath;
112112
this._rushAlertsConfig = rushAlertsConfig;
113-
this._rushAlertsState = rushAlertsState ?? {};
113+
this._rushAlertsState = rushAlertsState;
114114
}
115115

116116
public static async loadFromConfigurationAsync(

libraries/terminal/src/TextRewriterTransform.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,13 @@ export class TextRewriterTransform extends TerminalTransform {
6868
public constructor(options: ITextRewriterTransformOptions) {
6969
super(options);
7070

71-
const { textRewriters: inputTextRewriters, removeColors, normalizeNewlines, ensureNewlineAtEnd } = options;
72-
const textRewriters: TextRewriter[] = inputTextRewriters || [];
71+
const {
72+
textRewriters: inputTextRewriters = [],
73+
removeColors,
74+
normalizeNewlines,
75+
ensureNewlineAtEnd
76+
} = options;
77+
const textRewriters: TextRewriter[] = [...inputTextRewriters];
7378

7479
if (removeColors) {
7580
textRewriters.push(new RemoveColorsTextRewriter());

libraries/ts-command-line/src/providers/AliasCommandLineAction.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ export class AliasCommandLineAction extends CommandLineAction {
6363
private _parameterKeyMap: Map<string, string> = new Map();
6464

6565
public constructor(options: IAliasCommandLineActionOptions) {
66-
const { toolFilename, targetAction, defaultParameters: defaultParams, aliasName } = options;
66+
const { toolFilename, targetAction, defaultParameters: defaultParams = [], aliasName } = options;
6767
const targetActionName: string = targetAction.actionName;
68-
const defaultParametersString: string = (defaultParams || []).join(' ');
68+
const defaultParametersString: string = defaultParams.join(' ');
6969
const summary: string = `An alias for "${toolFilename} ${targetActionName}${
7070
defaultParametersString ? ` ${defaultParametersString}` : ''
7171
}".`;
@@ -79,7 +79,7 @@ export class AliasCommandLineAction extends CommandLineAction {
7979
});
8080

8181
this.targetAction = targetAction;
82-
this.defaultParameters = defaultParams || [];
82+
this.defaultParameters = defaultParams;
8383
}
8484

8585
/** @internal */

libraries/typings-generator/src/TypingsGenerator.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,18 @@ export class TypingsGenerator<TFileContents = string> {
108108
);
109109
public constructor(options: ITypingsGeneratorOptionsWithCustomReadFile<string | undefined, TFileContents>);
110110
public constructor(options: ITypingsGeneratorOptionsWithCustomReadFile<string | undefined, TFileContents>) {
111-
const { readFile, generatedTsFolder, srcFolder, fileExtensions, globsToIgnore, terminal } = options;
111+
const {
112+
readFile = ((filePath: string, relativePath: string): Promise<TFileContents> =>
113+
FileSystem.readFileAsync(filePath) as Promise<TFileContents>) as typeof options.readFile,
114+
generatedTsFolder,
115+
srcFolder,
116+
fileExtensions,
117+
globsToIgnore = [],
118+
terminal = new Terminal(new ConsoleTerminalProvider({ verboseEnabled: true }))
119+
} = options;
112120
this._options = {
113121
...options,
114-
readFile:
115-
readFile ??
116-
((filePath: string, relativePath: string): Promise<TFileContents> =>
117-
FileSystem.readFileAsync(filePath) as Promise<TFileContents>)
122+
readFile
118123
};
119124

120125
if (!generatedTsFolder) {
@@ -138,9 +143,9 @@ export class TypingsGenerator<TFileContents = string> {
138143
throw new Error('At least one file extension must be provided.');
139144
}
140145

141-
this.ignoredFileGlobs = globsToIgnore || [];
146+
this.ignoredFileGlobs = globsToIgnore;
142147

143-
this.terminal = terminal ?? new Terminal(new ConsoleTerminalProvider({ verboseEnabled: true }));
148+
this.terminal = terminal;
144149

145150
this._options.fileExtensions = this._normalizeFileExtensions(fileExtensions);
146151

rush-plugins/rush-azure-storage-build-cache-plugin/src/AzureAuthenticationBase.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -180,20 +180,20 @@ export abstract class AzureAuthenticationBase {
180180
azureEnvironment = 'AzurePublicCloud',
181181
credentialUpdateCommandForLogging,
182182
loginFlow = process.env.CODESPACES === 'true' ? 'AdoCodespacesAuth' : 'VisualStudioCode',
183-
loginFlowFailover
183+
loginFlowFailover = {
184+
AdoCodespacesAuth: 'VisualStudioCode',
185+
VisualStudioCode: 'AzureCli',
186+
AzureCli: 'AzureDeveloperCli',
187+
AzureDeveloperCli: 'AzurePowerShell',
188+
AzurePowerShell: 'InteractiveBrowser',
189+
InteractiveBrowser: 'DeviceCode',
190+
DeviceCode: undefined
191+
}
184192
} = options;
185193
this._azureEnvironment = azureEnvironment;
186194
this._credentialUpdateCommandForLogging = credentialUpdateCommandForLogging;
187195
this._loginFlow = loginFlow;
188-
this._failoverOrder = loginFlowFailover || {
189-
AdoCodespacesAuth: 'VisualStudioCode',
190-
VisualStudioCode: 'AzureCli',
191-
AzureCli: 'AzureDeveloperCli',
192-
AzureDeveloperCli: 'AzurePowerShell',
193-
AzurePowerShell: 'InteractiveBrowser',
194-
InteractiveBrowser: 'DeviceCode',
195-
DeviceCode: undefined
196-
};
196+
this._failoverOrder = loginFlowFailover;
197197
}
198198

199199
public async updateCachedCredentialAsync(terminal: ITerminal, credential: string): Promise<void> {

rush-plugins/rush-http-build-cache-plugin/src/HttpBuildCacheProvider.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,11 @@ export class HttpBuildCacheProvider implements ICloudBuildCacheProvider {
7878
rushJsonFolder,
7979
isCacheWriteAllowed,
8080
url,
81-
uploadMethod,
82-
headers,
81+
uploadMethod = 'PUT',
82+
headers = {},
8383
tokenHandler,
84-
cacheKeyPrefix,
85-
minHttpRetryDelayMs
84+
cacheKeyPrefix = '',
85+
minHttpRetryDelayMs = DEFAULT_MIN_HTTP_RETRY_DELAY_MS
8686
} = options;
8787

8888
this._pluginName = pluginName;
@@ -91,11 +91,11 @@ export class HttpBuildCacheProvider implements ICloudBuildCacheProvider {
9191
this._environmentCredential = EnvironmentConfiguration.buildCacheCredential;
9292
this._isCacheWriteAllowedByConfiguration = isCacheWriteAllowed;
9393
this._url = new URL(url.endsWith('/') ? url : url + '/');
94-
this._uploadMethod = uploadMethod ?? 'PUT';
95-
this._headers = headers ?? {};
94+
this._uploadMethod = uploadMethod;
95+
this._headers = headers;
9696
this._tokenHandler = tokenHandler;
97-
this._cacheKeyPrefix = cacheKeyPrefix ?? '';
98-
this._minHttpRetryDelayMs = minHttpRetryDelayMs ?? DEFAULT_MIN_HTTP_RETRY_DELAY_MS;
97+
this._cacheKeyPrefix = cacheKeyPrefix;
98+
this._minHttpRetryDelayMs = minHttpRetryDelayMs;
9999
}
100100

101101
public async tryGetCacheEntryBufferByIdAsync(

rush-plugins/rush-serve-plugin/src/RushServePlugin.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,16 @@ export class RushServePlugin implements IRushPlugin {
6161
private readonly _buildStatusWebSocketPath: string | undefined;
6262

6363
public constructor(options: IRushServePluginOptions) {
64-
const { phasedCommands, portParameterLongName, globalRouting, logServePath, buildStatusWebSocketPath } =
65-
options;
64+
const {
65+
phasedCommands,
66+
portParameterLongName,
67+
globalRouting = [],
68+
logServePath,
69+
buildStatusWebSocketPath
70+
} = options;
6671
this._phasedCommands = new Set(phasedCommands);
6772
this._portParameterLongName = portParameterLongName;
68-
this._globalRoutingRules = globalRouting ?? [];
73+
this._globalRoutingRules = globalRouting;
6974
this._logServePath = logServePath;
7075
this._buildStatusWebSocketPath = buildStatusWebSocketPath;
7176
}

0 commit comments

Comments
 (0)