Skip to content

style: collapse if statements #15449

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions packages/angular/cli/commands/generate-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,8 @@ export class GenerateCommand extends SchematicCommand<GenerateCommandSchema> {

let schematicName = options.schematic;

if (schematicName) {
if (schematicName.includes(':')) {
[collectionName, schematicName] = schematicName.split(':', 2);
}
if (schematicName && schematicName.includes(':')) {
[collectionName, schematicName] = schematicName.split(':', 2);
}

return [collectionName, schematicName];
Expand Down
6 changes: 2 additions & 4 deletions packages/angular/cli/models/architect-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,8 @@ export abstract class ArchitectCommand<

// Update options to remove analytics from options if the builder isn't safelisted.
for (const o of this.description.options) {
if (o.userAnalytics) {
if (!isPackageNameSafeForAnalytics(builderConf)) {
o.userAnalytics = undefined;
}
if (o.userAnalytics && !isPackageNameSafeForAnalytics(builderConf)) {
o.userAnalytics = undefined;
}
}
}
Expand Down
12 changes: 4 additions & 8 deletions packages/angular/cli/models/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,8 @@ function _coerce(str: string | undefined, o: Option | null, v?: Value): Value |
// enum. If there's no enum, just return the first one that matches.
for (const type of types) {
const maybeResult = _coerceType(str, type, v);
if (maybeResult !== undefined) {
if (!o.enum || o.enum.includes(maybeResult)) {
return maybeResult;
}
if (maybeResult !== undefined && (!o.enum || o.enum.includes(maybeResult))) {
return maybeResult;
}
}

Expand Down Expand Up @@ -159,11 +157,9 @@ function _assignOption(
value = nextArg;
let shouldShift = true;

if (value && value.startsWith('-')) {
if (value && value.startsWith('-') && _coerce(undefined, maybeOption) !== undefined) {
// Verify if not having a value results in a correct parse, if so don't shift.
if (_coerce(undefined, maybeOption) !== undefined) {
shouldShift = false;
}
shouldShift = false;
}

// Only absorb it if it leads to a better value.
Expand Down
6 changes: 2 additions & 4 deletions packages/angular/cli/models/schematic-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,8 @@ export abstract class SchematicCommand<

// Remove any user analytics from schematics that are NOT part of our safelist.
for (const o of this.description.options) {
if (o.userAnalytics) {
if (!isPackageNameSafeForAnalytics(this.collectionName)) {
o.userAnalytics = undefined;
}
if (o.userAnalytics && !isPackageNameSafeForAnalytics(this.collectionName)) {
o.userAnalytics = undefined;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,18 @@ export class BundleBudgetPlugin {
}

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

private checkMaximum(threshold: number | undefined, size: Size, messages: string[]) {
if (threshold) {
if (threshold < size.size) {
const sizeDifference = formatSize(size.size - threshold);
messages.push(`budgets, maximum exceeded for ${size.label}. `
+ `Budget ${formatSize(threshold)} was exceeded by ${sizeDifference}.`);
}
if (threshold && threshold < size.size) {
const sizeDifference = formatSize(size.size - threshold);
messages.push(`budgets, maximum exceeded for ${size.label}. `
+ `Budget ${formatSize(threshold)} was exceeded by ${sizeDifference}.`);
}
}

Expand Down
29 changes: 16 additions & 13 deletions packages/angular_devkit/build_angular/src/dev-server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,20 +286,23 @@ export function buildServerConfig(
browserOptions: BrowserBuilderSchema,
logger: logging.LoggerApi,
): WebpackDevServer.Configuration {
if (serverOptions.host) {
// Check that the host is either localhost or prints out a message.
if (!/^127\.\d+\.\d+\.\d+/g.test(serverOptions.host) && serverOptions.host !== 'localhost') {
logger.warn(tags.stripIndent`
WARNING: This is a simple server for use in testing or debugging Angular applications
locally. It hasn't been reviewed for security issues.

Binding this server to an open connection can result in compromising your application or
computer. Using a different host than the one passed to the "--host" flag might result in
websocket connection issues. You might need to use "--disableHostCheck" if that's the
case.
`);
}
// Check that the host is either localhost or prints out a message.
if (
serverOptions.host
&& !/^127\.\d+\.\d+\.\d+/g.test(serverOptions.host)
&& serverOptions.host !== 'localhost'
) {
logger.warn(tags.stripIndent`
WARNING: This is a simple server for use in testing or debugging Angular applications
locally. It hasn't been reviewed for security issues.

Binding this server to an open connection can result in compromising your application or
computer. Using a different host than the one passed to the "--host" flag might result in
websocket connection issues. You might need to use "--disableHostCheck" if that's the
case.
`);
}

if (serverOptions.disableHostCheck) {
logger.warn(tags.oneLine`
WARNING: Running a server with --disable-host-check is a security risk.
Expand Down
22 changes: 10 additions & 12 deletions packages/angular_devkit/core/src/json/schema/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -549,18 +549,16 @@ export class CoreSchemaRegistry implements SchemaRegistry {
}
}

if (type === 'list' && !items) {
if (Array.isArray(parentSchema.enum)) {
type = 'list';
items = [];
for (const value of parentSchema.enum) {
if (typeof value == 'string') {
items.push(value);
} else if (typeof value == 'object') {
// Invalid
} else {
items.push({ label: value.toString(), value });
}
if (type === 'list' && !items && Array.isArray(parentSchema.enum)) {
type = 'list';
items = [];
for (const value of parentSchema.enum) {
if (typeof value == 'string') {
items.push(value);
} else if (typeof value == 'object') {
// Invalid
} else {
items.push({ label: value.toString(), value });
}
}
}
Expand Down
13 changes: 5 additions & 8 deletions packages/angular_devkit/schematics/src/utility/update-buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,12 @@ export class Chunk {
}

assert(left: boolean, _content: boolean, right: boolean) {
if (left) {
if (this._assertLeft) {
throw new ContentCannotBeRemovedException();
}
if (left && this._assertLeft) {
throw new ContentCannotBeRemovedException();
}
if (right) {
if (this._assertRight) {
throw new ContentCannotBeRemovedException();
}

if (right && this._assertRight) {
throw new ContentCannotBeRemovedException();
}
}

Expand Down