Skip to content

Commit

Permalink
chore: more style rules for eslint (#9517)
Browse files Browse the repository at this point in the history
Configure `comma-spacing`, `no-multi-spaces`, `array-bracket-spacing`,
`array-bracket-newline`, `object-curly-spacing`, `object-curly-newline` and
`object-property-newline` to uniformize arrays and objects.

* Valid arrays (no bracket spacing, no space before comma, a single space after
comma):

```ts
[1, 2, 3]

[
  1,
  2,
  3,
]

[
  1, 2,
  3, 4,
]
```
* Valid objects (curly spacing):

```ts
{ key: 'value' }

{ key1: 'value1', key2: 'value2 }

{
  key1: 'value1',
  key2: 'value2',
}
```

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
jogold committed Aug 17, 2020
1 parent 44f7753 commit 90de605
Show file tree
Hide file tree
Showing 545 changed files with 3,202 additions and 2,627 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ function createSelfUpdatingStack(pipelineStack: cdk.Stack): SelfUpdatingPipeline
stageName: 'build',
actions: [buildAction],
});
return {synthesizedApp: buildOutput, pipeline};
return { synthesizedApp: buildOutput, pipeline };
}

function hasPipelineAction(expectedAction: any): (props: any) => boolean {
Expand Down
6 changes: 3 additions & 3 deletions packages/@aws-cdk/assert/test/assertions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ passingExample('expect <synthStack> to be a superset of <template> with paramete
// Added
new TestResource(stack, 'NewResource', { type: 'AWS::S3::Bucket' });
// Expected
new TestParameter(stack, 'TestParameterA', {type: parameterType});
new TestParameter(stack, 'TestParameterB', {type: parameterType, default: { Foo: 'Bar' } });
new TestParameter(stack, 'TestParameterA', { type: parameterType });
new TestParameter(stack, 'TestParameterB', { type: parameterType, default: { Foo: 'Bar' } });
});
const expected = {
Parameters: {
Expand Down Expand Up @@ -261,7 +261,7 @@ passingExample('expect <stack> to count resources like props - expected no resou
const synthStack = synthesizedStack(stack => {
new TestResource(stack, 'R1', { type: resourceType, properties: { parentId: 123, name: 'A' } });
new TestResource(stack, 'R2', { type: resourceType });
new TestResource(stack, 'R3', { type: 'Foo', properties: { parentId: 456} });
new TestResource(stack, 'R3', { type: 'Foo', properties: { parentId: 456 } });
});
cdkExpect(synthStack).to(countResourcesLike(resourceType, 0, { parentId: 456 }));
});
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/assert/test/have-output.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ test('haveOutput should throw Error when none of outputName and exportName is pr

test('haveOutput should be able to handle complex exportName values', () => {
expect(synthStack).toHaveOutput({
exportName: {'Fn::Sub': '${AWS::StackName}-ComplexExportNameOutput'},
exportName: { 'Fn::Sub': '${AWS::StackName}-ComplexExportNameOutput' },
outputValue: {
'Fn::GetAtt': [
'ComplexOutputResource',
Expand Down
4 changes: 2 additions & 2 deletions packages/@aws-cdk/assets/test/test.staging.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as fs from 'fs';
import * as path from 'path';
import { App, Stack } from '@aws-cdk/core';
import * as cxapi from '@aws-cdk/cx-api';
import * as fs from 'fs';
import { Test } from 'nodeunit';
import * as path from 'path';
import { Staging } from '../lib';

export = {
Expand Down
6 changes: 3 additions & 3 deletions packages/@aws-cdk/aws-apigateway/lib/access-log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -504,10 +504,10 @@ export class AccessLogFormat {
* Generate Common Log Format.
*/
public static clf(): AccessLogFormat {
const requester = [AccessLogField.contextIdentitySourceIp(), AccessLogField.contextIdentityCaller(), AccessLogField.contextIdentityUser() ].join(' ');
const requester = [AccessLogField.contextIdentitySourceIp(), AccessLogField.contextIdentityCaller(), AccessLogField.contextIdentityUser()].join(' ');
const requestTime = AccessLogField.contextRequestTime();
const request = [ AccessLogField.contextHttpMethod(), AccessLogField.contextResourcePath(), AccessLogField.contextProtocol()].join(' ');
const status = [ AccessLogField.contextStatus(), AccessLogField.contextResponseLength(), AccessLogField.contextRequestId()].join(' ');
const request = [AccessLogField.contextHttpMethod(), AccessLogField.contextResourcePath(), AccessLogField.contextProtocol()].join(' ');
const status = [AccessLogField.contextStatus(), AccessLogField.contextResponseLength(), AccessLogField.contextRequestId()].join(' ');

return new AccessLogFormat(`${requester} [${requestTime}] "${request}" ${status}`);
}
Expand Down
44 changes: 22 additions & 22 deletions packages/@aws-cdk/aws-apigateway/lib/apigatewayv2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ export class CfnApiV2 extends cdk.CfnResource implements cdk.IInspectable {
inspector.addAttribute('aws:cdk:cloudformation:props', this.cfnProperties);
}

protected get cfnProperties(): { [key: string]: any } {
protected get cfnProperties(): { [key: string]: any } {
return {
apiKeySelectionExpression: this.apiKeySelectionExpression,
basePath: this.basePath,
Expand All @@ -341,7 +341,7 @@ export class CfnApiV2 extends cdk.CfnResource implements cdk.IInspectable {
version: this.version,
};
}
protected renderProperties(props: {[key: string]: any}): { [key: string]: any } {
protected renderProperties(props: {[key: string]: any}): { [key: string]: any } {
return cfnApiV2PropsToCloudFormation(props);
}
}
Expand Down Expand Up @@ -640,15 +640,15 @@ export class CfnApiMappingV2 extends cdk.CfnResource implements cdk.IInspectable
inspector.addAttribute('aws:cdk:cloudformation:props', this.cfnProperties);
}

protected get cfnProperties(): { [key: string]: any } {
protected get cfnProperties(): { [key: string]: any } {
return {
apiId: this.apiId,
domainName: this.domainName,
stage: this.stage,
apiMappingKey: this.apiMappingKey,
};
}
protected renderProperties(props: {[key: string]: any}): { [key: string]: any } {
protected renderProperties(props: {[key: string]: any}): { [key: string]: any } {
return cfnApiMappingV2PropsToCloudFormation(props);
}
}
Expand Down Expand Up @@ -872,7 +872,7 @@ export class CfnAuthorizerV2 extends cdk.CfnResource implements cdk.IInspectable
inspector.addAttribute('aws:cdk:cloudformation:props', this.cfnProperties);
}

protected get cfnProperties(): { [key: string]: any } {
protected get cfnProperties(): { [key: string]: any } {
return {
apiId: this.apiId,
authorizerType: this.authorizerType,
Expand All @@ -885,7 +885,7 @@ export class CfnAuthorizerV2 extends cdk.CfnResource implements cdk.IInspectable
jwtConfiguration: this.jwtConfiguration,
};
}
protected renderProperties(props: {[key: string]: any}): { [key: string]: any } {
protected renderProperties(props: {[key: string]: any}): { [key: string]: any } {
return cfnAuthorizerV2PropsToCloudFormation(props);
}
}
Expand Down Expand Up @@ -1068,14 +1068,14 @@ export class CfnDeploymentV2 extends cdk.CfnResource implements cdk.IInspectable
inspector.addAttribute('aws:cdk:cloudformation:props', this.cfnProperties);
}

protected get cfnProperties(): { [key: string]: any } {
protected get cfnProperties(): { [key: string]: any } {
return {
apiId: this.apiId,
description: this.description,
stageName: this.stageName,
};
}
protected renderProperties(props: {[key: string]: any}): { [key: string]: any } {
protected renderProperties(props: {[key: string]: any}): { [key: string]: any } {
return cfnDeploymentV2PropsToCloudFormation(props);
}
}
Expand Down Expand Up @@ -1215,14 +1215,14 @@ export class CfnDomainNameV2 extends cdk.CfnResource implements cdk.IInspectable
inspector.addAttribute('aws:cdk:cloudformation:props', this.cfnProperties);
}

protected get cfnProperties(): { [key: string]: any } {
protected get cfnProperties(): { [key: string]: any } {
return {
domainName: this.domainName,
domainNameConfigurations: this.domainNameConfigurations,
tags: this.tags.renderTags(),
};
}
protected renderProperties(props: {[key: string]: any}): { [key: string]: any } {
protected renderProperties(props: {[key: string]: any}): { [key: string]: any } {
return cfnDomainNameV2PropsToCloudFormation(props);
}
}
Expand Down Expand Up @@ -1579,7 +1579,7 @@ export class CfnIntegrationV2 extends cdk.CfnResource implements cdk.IInspectabl
inspector.addAttribute('aws:cdk:cloudformation:props', this.cfnProperties);
}

protected get cfnProperties(): { [key: string]: any } {
protected get cfnProperties(): { [key: string]: any } {
return {
apiId: this.apiId,
integrationType: this.integrationType,
Expand All @@ -1597,7 +1597,7 @@ export class CfnIntegrationV2 extends cdk.CfnResource implements cdk.IInspectabl
timeoutInMillis: this.timeoutInMillis,
};
}
protected renderProperties(props: {[key: string]: any}): { [key: string]: any } {
protected renderProperties(props: {[key: string]: any}): { [key: string]: any } {
return cfnIntegrationV2PropsToCloudFormation(props);
}
}
Expand Down Expand Up @@ -1789,7 +1789,7 @@ export class CfnIntegrationResponseV2 extends cdk.CfnResource implements cdk.IIn
inspector.addAttribute('aws:cdk:cloudformation:props', this.cfnProperties);
}

protected get cfnProperties(): { [key: string]: any } {
protected get cfnProperties(): { [key: string]: any } {
return {
apiId: this.apiId,
integrationId: this.integrationId,
Expand All @@ -1800,7 +1800,7 @@ export class CfnIntegrationResponseV2 extends cdk.CfnResource implements cdk.IIn
templateSelectionExpression: this.templateSelectionExpression,
};
}
protected renderProperties(props: {[key: string]: any}): { [key: string]: any } {
protected renderProperties(props: {[key: string]: any}): { [key: string]: any } {
return cfnIntegrationResponseV2PropsToCloudFormation(props);
}
}
Expand Down Expand Up @@ -1962,7 +1962,7 @@ export class CfnModelV2 extends cdk.CfnResource implements cdk.IInspectable {
inspector.addAttribute('aws:cdk:cloudformation:props', this.cfnProperties);
}

protected get cfnProperties(): { [key: string]: any } {
protected get cfnProperties(): { [key: string]: any } {
return {
apiId: this.apiId,
name: this.name,
Expand All @@ -1971,7 +1971,7 @@ export class CfnModelV2 extends cdk.CfnResource implements cdk.IInspectable {
description: this.description,
};
}
protected renderProperties(props: {[key: string]: any}): { [key: string]: any } {
protected renderProperties(props: {[key: string]: any}): { [key: string]: any } {
return cfnModelV2PropsToCloudFormation(props);
}
}
Expand Down Expand Up @@ -2236,7 +2236,7 @@ export class CfnRouteV2 extends cdk.CfnResource implements cdk.IInspectable {
inspector.addAttribute('aws:cdk:cloudformation:props', this.cfnProperties);
}

protected get cfnProperties(): { [key: string]: any } {
protected get cfnProperties(): { [key: string]: any } {
return {
apiId: this.apiId,
routeKey: this.routeKey,
Expand All @@ -2252,7 +2252,7 @@ export class CfnRouteV2 extends cdk.CfnResource implements cdk.IInspectable {
target: this.target,
};
}
protected renderProperties(props: {[key: string]: any}): { [key: string]: any } {
protected renderProperties(props: {[key: string]: any}): { [key: string]: any } {
return cfnRouteV2PropsToCloudFormation(props);
}
}
Expand Down Expand Up @@ -2478,7 +2478,7 @@ export class CfnRouteResponseV2 extends cdk.CfnResource implements cdk.IInspecta
inspector.addAttribute('aws:cdk:cloudformation:props', this.cfnProperties);
}

protected get cfnProperties(): { [key: string]: any } {
protected get cfnProperties(): { [key: string]: any } {
return {
apiId: this.apiId,
routeId: this.routeId,
Expand All @@ -2488,7 +2488,7 @@ export class CfnRouteResponseV2 extends cdk.CfnResource implements cdk.IInspecta
responseParameters: this.responseParameters,
};
}
protected renderProperties(props: {[key: string]: any}): { [key: string]: any } {
protected renderProperties(props: {[key: string]: any}): { [key: string]: any } {
return cfnRouteResponseV2PropsToCloudFormation(props);
}
}
Expand Down Expand Up @@ -2787,7 +2787,7 @@ export class CfnStageV2 extends cdk.CfnResource implements cdk.IInspectable {
inspector.addAttribute('aws:cdk:cloudformation:props', this.cfnProperties);
}

protected get cfnProperties(): { [key: string]: any } {
protected get cfnProperties(): { [key: string]: any } {
return {
apiId: this.apiId,
stageName: this.stageName,
Expand All @@ -2802,7 +2802,7 @@ export class CfnStageV2 extends cdk.CfnResource implements cdk.IInspectable {
tags: this.tags.renderTags(),
};
}
protected renderProperties(props: {[key: string]: any}): { [key: string]: any } {
protected renderProperties(props: {[key: string]: any}): { [key: string]: any } {
return cfnStageV2PropsToCloudFormation(props);
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-apigateway/lib/authorizers/lambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ abstract class LambdaAuthorizer extends Authorizer implements IAuthorizer {
this.role.attachInlinePolicy(new iam.Policy(this, 'authorizerInvokePolicy', {
statements: [
new iam.PolicyStatement({
resources: [ this.handler.functionArn ],
actions: [ 'lambda:InvokeFunction' ],
resources: [this.handler.functionArn],
actions: ['lambda:InvokeFunction'],
}),
],
}));
Expand Down
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-apigateway/lib/cors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,12 @@ export class Cors {
/**
* All origins.
*/
public static readonly ALL_ORIGINS = [ '*' ];
public static readonly ALL_ORIGINS = ['*'];

/**
* The set of default headers allowed for CORS and useful for API Gateway.
*/
public static readonly DEFAULT_HEADERS = [ 'Content-Type', 'X-Amz-Date', 'Authorization', 'X-Api-Key', 'X-Amz-Security-Token', 'X-Amz-User-Agent' ];
public static readonly DEFAULT_HEADERS = ['Content-Type', 'X-Amz-Date', 'Authorization', 'X-Api-Key', 'X-Amz-Security-Token', 'X-Amz-User-Agent'];

// utility class
private constructor() { }
Expand Down
6 changes: 3 additions & 3 deletions packages/@aws-cdk/aws-apigateway/lib/deployment.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import * as crypto from 'crypto';
import { Construct, Lazy, RemovalPolicy, Resource, CfnResource } from '@aws-cdk/core';
import { CfnDeployment } from './apigateway.generated';
import { IRestApi, RestApi, SpecRestApi, RestApiBase } from './restapi';
import { Method } from './method';
import { IRestApi, RestApi, SpecRestApi, RestApiBase } from './restapi';

export interface DeploymentProps {
export interface DeploymentProps {
/**
* The Rest API to deploy.
*/
Expand Down Expand Up @@ -158,7 +158,7 @@ class LatestDeploymentResource extends CfnDeployment {
}

private calculateLogicalId() {
const hash = [ ...this.hashComponents ];
const hash = [...this.hashComponents];

if (this.api instanceof RestApi || this.api instanceof SpecRestApi) { // Ignore IRestApi that are imported

Expand Down
22 changes: 12 additions & 10 deletions packages/@aws-cdk/aws-apigateway/lib/integrations/aws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,18 @@ export class AwsIntegration extends Integration {
super({
type,
integrationHttpMethod: props.integrationHttpMethod || 'POST',
uri: cdk.Lazy.stringValue({ produce: () => {
if (!this.scope) { throw new Error('AwsIntegration must be used in API'); }
return cdk.Stack.of(this.scope).formatArn({
service: 'apigateway',
account: backend,
resource: apiType,
sep: '/',
resourceName: apiValue,
});
}}),
uri: cdk.Lazy.stringValue({
produce: () => {
if (!this.scope) { throw new Error('AwsIntegration must be used in API'); }
return cdk.Stack.of(this.scope).formatArn({
service: 'apigateway',
account: backend,
resource: apiType,
sep: '/',
resourceName: apiValue,
});
},
}),
options: props.options,
});
}
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-apigateway/lib/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ export abstract class ResourceBase extends ResourceConstruct implements IResourc
const integrationResponseParams: { [p: string]: string } = { };
const methodReponseParams: { [p: string]: boolean } = { };

for (const [ name, value ] of Object.entries(headers)) {
for (const [name, value] of Object.entries(headers)) {
const key = `method.response.header.${name}`;
integrationResponseParams[key] = value;
methodReponseParams[key] = true;
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-apigateway/lib/restapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ export class RestApi extends RestApiBase {
*/
protected validate() {
if (this.methods.length === 0) {
return [ "The REST API doesn't contain any methods" ];
return ["The REST API doesn't contain any methods"];
}

return [];
Expand Down
5 changes: 3 additions & 2 deletions packages/@aws-cdk/aws-apigateway/lib/stage.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Construct, Duration, IResource, Resource, Stack } from '@aws-cdk/core';
import { AccessLogFormat, IAccessLogDestination} from './access-log';
import { AccessLogFormat, IAccessLogDestination } from './access-log';
import { CfnStage } from './apigateway.generated';
import { Deployment } from './deployment';
import { IRestApi } from './restapi';
Expand Down Expand Up @@ -305,7 +305,8 @@ export class Stage extends Resource implements IStage {
const { httpMethod, resourcePath } = parseMethodOptionsPath(path);

return {
httpMethod, resourcePath,
httpMethod,
resourcePath,
cacheDataEncrypted: options.cacheDataEncrypted,
cacheTtlInSeconds: options.cacheTtl && options.cacheTtl.toSeconds(),
cachingEnabled: options.cachingEnabled,
Expand Down
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-apigateway/lib/util.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { format as formatUrl } from 'url';
import * as jsonSchema from './json-schema';

export const ALL_METHODS = [ 'OPTIONS', 'GET', 'PUT', 'POST', 'DELETE', 'PATCH', 'HEAD' ];
export const ALL_METHODS = ['OPTIONS', 'GET', 'PUT', 'POST', 'DELETE', 'PATCH', 'HEAD'];

const ALLOWED_METHODS = [ 'ANY', ...ALL_METHODS ];
const ALLOWED_METHODS = ['ANY', ...ALL_METHODS];

export function validateHttpMethod(method: string, messagePrefix: string = '') {
if (!ALLOWED_METHODS.includes(method)) {
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-apigateway/lib/vpc-link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export class VpcLink extends Resource implements IVpcLink {

protected validate(): string[] {
if (this.targets.length === 0) {
return [ 'No targets added to vpc link' ];
return ['No targets added to vpc link'];
}
return [];
}
Expand Down

0 comments on commit 90de605

Please sign in to comment.