style: collapse if statements (#15449)

This commit is contained in:
Alan Agius 2019-08-27 19:25:15 +02:00 committed by Minko Gechev
parent a6fbee6865
commit 26dd51221a
8 changed files with 48 additions and 64 deletions

View File

@ -98,11 +98,9 @@ export class GenerateCommand extends SchematicCommand<GenerateCommandSchema> {
let schematicName = options.schematic;
if (schematicName) {
if (schematicName.includes(':')) {
if (schematicName && schematicName.includes(':')) {
[collectionName, schematicName] = schematicName.split(':', 2);
}
}
return [collectionName, schematicName];
}

View File

@ -179,13 +179,11 @@ 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)) {
if (o.userAnalytics && !isPackageNameSafeForAnalytics(builderConf)) {
o.userAnalytics = undefined;
}
}
}
}
async run(options: ArchitectCommandOptions & Arguments) {
return await this.runArchitectTarget(options);

View File

@ -84,12 +84,10 @@ 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)) {
if (maybeResult !== undefined && (!o.enum || o.enum.includes(maybeResult))) {
return maybeResult;
}
}
}
return undefined;
}
@ -159,12 +157,10 @@ 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;
}
}
// Only absorb it if it leads to a better value.
if (shouldShift && _coerce(value, maybeOption) !== undefined) {

View File

@ -103,14 +103,12 @@ 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)) {
if (o.userAnalytics && !isPackageNameSafeForAnalytics(this.collectionName)) {
o.userAnalytics = undefined;
}
}
}
}
}
public async printHelp(options: T & Arguments) {
await super.printHelp(options);

View File

@ -56,24 +56,20 @@ export class BundleBudgetPlugin {
}
private checkMinimum(threshold: number | undefined, size: Size, messages: string[]) {
if (threshold) {
if (threshold > size.size) {
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) {
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}.`);
}
}
}
private calculate(budget: Budget): Thresholds {
const thresholds: Thresholds = {};

View File

@ -286,9 +286,12 @@ 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') {
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.
@ -299,7 +302,7 @@ export function buildServerConfig(
case.
`);
}
}
if (serverOptions.disableHostCheck) {
logger.warn(tags.oneLine`
WARNING: Running a server with --disable-host-check is a security risk.

View File

@ -549,8 +549,7 @@ export class CoreSchemaRegistry implements SchemaRegistry {
}
}
if (type === 'list' && !items) {
if (Array.isArray(parentSchema.enum)) {
if (type === 'list' && !items && Array.isArray(parentSchema.enum)) {
type = 'list';
items = [];
for (const value of parentSchema.enum) {
@ -563,7 +562,6 @@ export class CoreSchemaRegistry implements SchemaRegistry {
}
}
}
}
const definition: PromptDefinition = {
id: path,

View File

@ -128,17 +128,14 @@ export class Chunk {
}
assert(left: boolean, _content: boolean, right: boolean) {
if (left) {
if (this._assertLeft) {
if (left && this._assertLeft) {
throw new ContentCannotBeRemovedException();
}
}
if (right) {
if (this._assertRight) {
if (right && this._assertRight) {
throw new ContentCannotBeRemovedException();
}
}
}
remove(left: boolean, content: boolean, right: boolean) {
if (left) {