Skip to content

Commit 26dd512

Browse files
alan-agius4mgechev
authored andcommitted
style: collapse if statements (#15449)
1 parent a6fbee6 commit 26dd512

File tree

8 files changed

+49
-65
lines changed

8 files changed

+49
-65
lines changed

packages/angular/cli/commands/generate-impl.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,8 @@ export class GenerateCommand extends SchematicCommand<GenerateCommandSchema> {
9898

9999
let schematicName = options.schematic;
100100

101-
if (schematicName) {
102-
if (schematicName.includes(':')) {
103-
[collectionName, schematicName] = schematicName.split(':', 2);
104-
}
101+
if (schematicName && schematicName.includes(':')) {
102+
[collectionName, schematicName] = schematicName.split(':', 2);
105103
}
106104

107105
return [collectionName, schematicName];

packages/angular/cli/models/architect-command.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,8 @@ export abstract class ArchitectCommand<
179179

180180
// Update options to remove analytics from options if the builder isn't safelisted.
181181
for (const o of this.description.options) {
182-
if (o.userAnalytics) {
183-
if (!isPackageNameSafeForAnalytics(builderConf)) {
184-
o.userAnalytics = undefined;
185-
}
182+
if (o.userAnalytics && !isPackageNameSafeForAnalytics(builderConf)) {
183+
o.userAnalytics = undefined;
186184
}
187185
}
188186
}

packages/angular/cli/models/parser.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,8 @@ function _coerce(str: string | undefined, o: Option | null, v?: Value): Value |
8484
// enum. If there's no enum, just return the first one that matches.
8585
for (const type of types) {
8686
const maybeResult = _coerceType(str, type, v);
87-
if (maybeResult !== undefined) {
88-
if (!o.enum || o.enum.includes(maybeResult)) {
89-
return maybeResult;
90-
}
87+
if (maybeResult !== undefined && (!o.enum || o.enum.includes(maybeResult))) {
88+
return maybeResult;
9189
}
9290
}
9391

@@ -159,11 +157,9 @@ function _assignOption(
159157
value = nextArg;
160158
let shouldShift = true;
161159

162-
if (value && value.startsWith('-')) {
160+
if (value && value.startsWith('-') && _coerce(undefined, maybeOption) !== undefined) {
163161
// Verify if not having a value results in a correct parse, if so don't shift.
164-
if (_coerce(undefined, maybeOption) !== undefined) {
165-
shouldShift = false;
166-
}
162+
shouldShift = false;
167163
}
168164

169165
// Only absorb it if it leads to a better value.

packages/angular/cli/models/schematic-command.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,8 @@ export abstract class SchematicCommand<
103103

104104
// Remove any user analytics from schematics that are NOT part of our safelist.
105105
for (const o of this.description.options) {
106-
if (o.userAnalytics) {
107-
if (!isPackageNameSafeForAnalytics(this.collectionName)) {
108-
o.userAnalytics = undefined;
109-
}
106+
if (o.userAnalytics && !isPackageNameSafeForAnalytics(this.collectionName)) {
107+
o.userAnalytics = undefined;
110108
}
111109
}
112110
}

packages/angular_devkit/build_angular/src/angular-cli-files/plugins/bundle-budget.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,22 +56,18 @@ export class BundleBudgetPlugin {
5656
}
5757

5858
private checkMinimum(threshold: number | undefined, size: Size, messages: string[]) {
59-
if (threshold) {
60-
if (threshold > size.size) {
61-
const sizeDifference = formatSize(threshold - size.size);
62-
messages.push(`budgets, minimum exceeded for ${size.label}. `
63-
+ `Budget ${formatSize(threshold)} was not reached by ${sizeDifference}.`);
64-
}
59+
if (threshold && threshold > size.size) {
60+
const sizeDifference = formatSize(threshold - size.size);
61+
messages.push(`budgets, minimum exceeded for ${size.label}. `
62+
+ `Budget ${formatSize(threshold)} was not reached by ${sizeDifference}.`);
6563
}
6664
}
6765

6866
private checkMaximum(threshold: number | undefined, size: Size, messages: string[]) {
69-
if (threshold) {
70-
if (threshold < size.size) {
71-
const sizeDifference = formatSize(size.size - threshold);
72-
messages.push(`budgets, maximum exceeded for ${size.label}. `
73-
+ `Budget ${formatSize(threshold)} was exceeded by ${sizeDifference}.`);
74-
}
67+
if (threshold && threshold < size.size) {
68+
const sizeDifference = formatSize(size.size - threshold);
69+
messages.push(`budgets, maximum exceeded for ${size.label}. `
70+
+ `Budget ${formatSize(threshold)} was exceeded by ${sizeDifference}.`);
7571
}
7672
}
7773

packages/angular_devkit/build_angular/src/dev-server/index.ts

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -286,20 +286,23 @@ export function buildServerConfig(
286286
browserOptions: BrowserBuilderSchema,
287287
logger: logging.LoggerApi,
288288
): WebpackDevServer.Configuration {
289-
if (serverOptions.host) {
290-
// Check that the host is either localhost or prints out a message.
291-
if (!/^127\.\d+\.\d+\.\d+/g.test(serverOptions.host) && serverOptions.host !== 'localhost') {
292-
logger.warn(tags.stripIndent`
293-
WARNING: This is a simple server for use in testing or debugging Angular applications
294-
locally. It hasn't been reviewed for security issues.
295-
296-
Binding this server to an open connection can result in compromising your application or
297-
computer. Using a different host than the one passed to the "--host" flag might result in
298-
websocket connection issues. You might need to use "--disableHostCheck" if that's the
299-
case.
300-
`);
301-
}
289+
// Check that the host is either localhost or prints out a message.
290+
if (
291+
serverOptions.host
292+
&& !/^127\.\d+\.\d+\.\d+/g.test(serverOptions.host)
293+
&& serverOptions.host !== 'localhost'
294+
) {
295+
logger.warn(tags.stripIndent`
296+
WARNING: This is a simple server for use in testing or debugging Angular applications
297+
locally. It hasn't been reviewed for security issues.
298+
299+
Binding this server to an open connection can result in compromising your application or
300+
computer. Using a different host than the one passed to the "--host" flag might result in
301+
websocket connection issues. You might need to use "--disableHostCheck" if that's the
302+
case.
303+
`);
302304
}
305+
303306
if (serverOptions.disableHostCheck) {
304307
logger.warn(tags.oneLine`
305308
WARNING: Running a server with --disable-host-check is a security risk.

packages/angular_devkit/core/src/json/schema/registry.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -549,18 +549,16 @@ export class CoreSchemaRegistry implements SchemaRegistry {
549549
}
550550
}
551551

552-
if (type === 'list' && !items) {
553-
if (Array.isArray(parentSchema.enum)) {
554-
type = 'list';
555-
items = [];
556-
for (const value of parentSchema.enum) {
557-
if (typeof value == 'string') {
558-
items.push(value);
559-
} else if (typeof value == 'object') {
560-
// Invalid
561-
} else {
562-
items.push({ label: value.toString(), value });
563-
}
552+
if (type === 'list' && !items && Array.isArray(parentSchema.enum)) {
553+
type = 'list';
554+
items = [];
555+
for (const value of parentSchema.enum) {
556+
if (typeof value == 'string') {
557+
items.push(value);
558+
} else if (typeof value == 'object') {
559+
// Invalid
560+
} else {
561+
items.push({ label: value.toString(), value });
564562
}
565563
}
566564
}

packages/angular_devkit/schematics/src/utility/update-buffer.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,15 +128,12 @@ export class Chunk {
128128
}
129129

130130
assert(left: boolean, _content: boolean, right: boolean) {
131-
if (left) {
132-
if (this._assertLeft) {
133-
throw new ContentCannotBeRemovedException();
134-
}
131+
if (left && this._assertLeft) {
132+
throw new ContentCannotBeRemovedException();
135133
}
136-
if (right) {
137-
if (this._assertRight) {
138-
throw new ContentCannotBeRemovedException();
139-
}
134+
135+
if (right && this._assertRight) {
136+
throw new ContentCannotBeRemovedException();
140137
}
141138
}
142139

0 commit comments

Comments
 (0)