Skip to content

Commit

Permalink
fix: trim trailing whitespace in code, templates, and generated code (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-fenster committed Dec 29, 2019
1 parent cb9136d commit 096630c
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 95 deletions.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@

This tool is a TypeScript client library generator for network APIs specified
by [protocol
buffers](https://developers.google.com/protocol-buffers/) (including, but
not limited to, [client libraries](https://www.npmjs.com/search?q=%40google-cloud)
buffers](https://developers.google.com/protocol-buffers/) (including, but
not limited to, [client libraries](https://www.npmjs.com/search?q=%40google-cloud)
for Google Cloud APIs).

It can be used for any API that uses protocol buffers and follows the conventions
It can be used for any API that uses protocol buffers and follows the conventions
described in [API Improvement Proposals](https://aip.dev/).

## Getting started

The [Showcase API](https://github.com/googleapis/gapic-showcase) is a good API to
The [Showcase API](https://github.com/googleapis/gapic-showcase) is a good API to
play with if you want to start generating your own client libraries. It has several
services, we'll use `Echo` service as an example.

Expand Down Expand Up @@ -119,12 +119,12 @@ $ gapic-generator-typescript -I . \
google/cloud/common_resources.proto
```
Line by line:
`-I .` means pass the current directory (i.e. `googleapis`) to `protoc`
`--output_dir /tmp/translate-v3-typescript` is where to put the result
Line by line:
`-I .` means pass the current directory (i.e. `googleapis`) to `protoc`
`--output_dir /tmp/translate-v3-typescript` is where to put the result
`--grpc-service-config google/cloud/translate/v3/translate_grpc_service_config.json`
is an optional configuration file for timeouts and stuff
Then we add all the `translate` `v3` proto file to the command line, as well as the
is an optional configuration file for timeouts and stuff
Then we add all the `translate` `v3` proto file to the command line, as well as the
proto file that defines common resources (some APIs need it, some others don't).

If you like the changes, make sure that tests pass!
Expand Down
20 changes: 13 additions & 7 deletions templates/typescript_gapic/_util.njk
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,19 @@ limitations under the License.
{%- macro printCommentsForService(service) -%}
{%- set lines = service.comments -%}
{% for line in lines %}
* {{ line | safe}}
{%- set trimmed = line.replace(r/\s+$/, '') -%}
{%- if trimmed.length > 0 %}
* {{ trimmed.replaceAll('*/', '* /') | safe}}
{%- else %}
*
{%- endif %}
{%- endfor %}
{%- endmacro -%}

{%- macro printCommentsForMethod(method) -%}
{%- set lines = method.comments -%}
{% for line in lines %}
*{{ line.replaceAll('*/', '* /') | safe}}
*{{ line.replaceAll('*/', '* /').replace(r/\s+$/, '') | safe}}
{%- endfor %}
{%- endmacro -%}

Expand Down Expand Up @@ -80,9 +85,10 @@ limitations under the License.
{%- endif -%}
{%- set lines = oneComment.comments -%}
{%- for line in lines %}
{%- if line.length > 0 %}
* {{ line.replaceAll('*/', '* /') | safe}}
{%- else %}
{%- set trimmed = line.replace(r/\s+$/, '') -%}
{%- if trimmed.length > 0 %}
* {{ trimmed.replaceAll('*/', '* /') | safe}}
{%- else %}
*
{%- endif -%}
{%- endfor -%}
Expand Down Expand Up @@ -141,12 +147,12 @@ limitations under the License.
{%- endmacro -%}

{%- macro printReturnClientStreamingMethod(method) %}
* @returns {Stream} - A writable stream which accepts objects representing
* @returns {Stream} - A writable stream which accepts objects representing
* {{ typeLink(method.inputType) }}.
{%- endmacro -%}

{%- macro printReturnBidiStreamingMethod(method) %}
* @returns {Stream}
* @returns {Stream}
* An object stream which is both readable and writable. It accepts objects
* representing {{ typeLink(method.inputType) }} for write() method, and
* will emit objects representing {{ typeLink(method.outputType) }} on 'data' event asynchronously.
Expand Down
12 changes: 6 additions & 6 deletions templates/typescript_gapic/src/$version/$service_client.ts.njk
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ export class {{ service.name }}Client {
});
{%- endif %}
return this._innerApiCalls.{{ method.name.toCamelCase() }}(request, options, callback);
}
}
{%- endfor %}
{% for method in service.streaming %}
{%- if method.serverStreaming and method.clientStreaming %}
Expand All @@ -404,7 +404,7 @@ export class {{ service.name }}Client {
request?: {{ util.toInterface(method.inputInterface) }},
options?: gax.CallOptions):
gax.CancellableStream{
request = request || {};
request = request || {};
options = options || {};
return this._innerApiCalls.{{ method.name.toCamelCase() }}(request, options);
}
Expand Down Expand Up @@ -491,7 +491,7 @@ export class {{ service.name }}Client {
});
{%- endif %}
return this._innerApiCalls.{{ method.name.toCamelCase() }}(request, options, callback);
}
}
{%- endfor %}
{%- for method in service.paging %}
{{ method.name.toCamelCase() }}(
Expand Down Expand Up @@ -547,7 +547,7 @@ export class {{ service.name }}Client {
});
{%- endif %}
return this._innerApiCalls.{{ method.name.toCamelCase() }}(request, options, callback);
}
}

/**
{{- util.printCommentsPageStream(method) }}
Expand All @@ -556,7 +556,7 @@ export class {{ service.name }}Client {
request?: {{ util.toInterface(method.inputInterface) }},
options?: gax.CallOptions | {}):
Transform{
request = request || {};
request = request || {};
const callSettings = new gax.CallSettings(options);
return this._descriptors.page.{{ method.name.toCamelCase() }}.createStream(
this._innerApiCalls.{{ method.name.toCamelCase() }} as gax.GaxCall,
Expand Down Expand Up @@ -603,7 +603,7 @@ export class {{ service.name }}Client {
match{{ param.capitalize() }}From{{ template.name }}Name({{ template.name.toLowerCase() }}Name: string) {
return this._pathTemplates.{{ template.name.toLowerCase() }}PathTemplate.match({{ template.name.toLowerCase() }}Name).{{ param }};
}
{%- endfor %}
{%- endfor %}
{%- endfor %}
{%- endif %}

Expand Down
2 changes: 1 addition & 1 deletion typescript/test/protos/google/showcase/v1beta1/echo.proto
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ service Echo {
}

// The request message used for the Echo, Collect and Chat methods. If content
// is set in this message then the request will succeed. If status is set in
// is set in this message then the request will succeed. If status is set in
// this message then the status will be returned as an error.
message EchoRequest {
oneof response {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ const version = require('../../../package.json').version;

/**
* Google Cloud Key Management Service
*
*
* Manages cryptographic keys and operations using those keys. Implements a REST
* model with the following objects:
*
*
* * [KeyRing][google.cloud.kms.v1.KeyRing]
* * [CryptoKey][google.cloud.kms.v1.CryptoKey]
* * [CryptoKeyVersion][google.cloud.kms.v1.CryptoKeyVersion]
*
*
* If you are using manual gRPC libraries, see
* [Using gRPC with Cloud KMS](https://cloud.google.com/kms/docs/grpc).
* @class
Expand Down Expand Up @@ -800,7 +800,7 @@ export class KeyManagementServiceClient {
* Wrapped key material produced with
* [RSA_OAEP_3072_SHA1_AES_256][google.cloud.kms.v1.ImportJob.ImportMethod.RSA_OAEP_3072_SHA1_AES_256]
* or
* [RSA_OAEP_4096_SHA1_AES_256][google.cloud.kms.v1.ImportJob.ImportMethod.RSA_OAEP_4096_SHA1_AES_256].
* [RSA_OAEP_4096_SHA1_AES_256][google.cloud.kms.v1.ImportJob.ImportMethod.RSA_OAEP_4096_SHA1_AES_256].
*
* This field contains the concatenation of two wrapped keys:
* <ol>
Expand All @@ -811,7 +811,7 @@ export class KeyManagementServiceClient {
* <li>The key to be imported, wrapped with the ephemeral AES-256 key
* using AES-KWP (RFC 5649).
* </li>
* </ol>
* </ol>
*
* This format is the same as the format produced by PKCS#11 mechanism
* CKM_RSA_AES_KEY_WRAP.
Expand Down Expand Up @@ -1071,12 +1071,12 @@ export class KeyManagementServiceClient {
* The request object that will be sent.
* @param {string} request.name
* Required. The resource name of the [CryptoKey][google.cloud.kms.v1.CryptoKey] or [CryptoKeyVersion][google.cloud.kms.v1.CryptoKeyVersion]
* to use for encryption.
* to use for encryption.
*
* If a [CryptoKey][google.cloud.kms.v1.CryptoKey] is specified, the server will use its
* [primary version][google.cloud.kms.v1.CryptoKey.primary].
* @param {Buffer} request.plaintext
* Required. The data to encrypt. Must be no larger than 64KiB.
* Required. The data to encrypt. Must be no larger than 64KiB.
*
* The maximum size depends on the key version's
* [protection_level][google.cloud.kms.v1.CryptoKeyVersionTemplate.protection_level]. For
Expand All @@ -1086,7 +1086,7 @@ export class KeyManagementServiceClient {
* 8KiB.
* @param {Buffer} request.additionalAuthenticatedData
* Optional data that, if specified, must also be provided during decryption
* through [DecryptRequest.additional_authenticated_data][google.cloud.kms.v1.DecryptRequest.additional_authenticated_data].
* through [DecryptRequest.additional_authenticated_data][google.cloud.kms.v1.DecryptRequest.additional_authenticated_data].
*
* The maximum size depends on the key version's
* [protection_level][google.cloud.kms.v1.CryptoKeyVersionTemplate.protection_level]. For
Expand Down Expand Up @@ -1615,7 +1615,7 @@ export class KeyManagementServiceClient {
'parent': request.parent || '',
});
return this._innerApiCalls.listKeyRings(request, options, callback);
}
}

/**
* Equivalent to {@link listKeyRings}, but returns a NodeJS Stream object.
Expand Down Expand Up @@ -1657,7 +1657,7 @@ export class KeyManagementServiceClient {
request?: protosTypes.google.cloud.kms.v1.IListKeyRingsRequest,
options?: gax.CallOptions | {}):
Transform{
request = request || {};
request = request || {};
const callSettings = new gax.CallSettings(options);
return this._descriptors.page.listKeyRings.createStream(
this._innerApiCalls.listKeyRings as gax.GaxCall,
Expand Down Expand Up @@ -1754,7 +1754,7 @@ export class KeyManagementServiceClient {
'parent': request.parent || '',
});
return this._innerApiCalls.listCryptoKeys(request, options, callback);
}
}

/**
* Equivalent to {@link listCryptoKeys}, but returns a NodeJS Stream object.
Expand Down Expand Up @@ -1798,7 +1798,7 @@ export class KeyManagementServiceClient {
request?: protosTypes.google.cloud.kms.v1.IListCryptoKeysRequest,
options?: gax.CallOptions | {}):
Transform{
request = request || {};
request = request || {};
const callSettings = new gax.CallSettings(options);
return this._descriptors.page.listCryptoKeys.createStream(
this._innerApiCalls.listCryptoKeys as gax.GaxCall,
Expand Down Expand Up @@ -1896,7 +1896,7 @@ export class KeyManagementServiceClient {
'parent': request.parent || '',
});
return this._innerApiCalls.listCryptoKeyVersions(request, options, callback);
}
}

/**
* Equivalent to {@link listCryptoKeyVersions}, but returns a NodeJS Stream object.
Expand Down Expand Up @@ -1941,7 +1941,7 @@ export class KeyManagementServiceClient {
request?: protosTypes.google.cloud.kms.v1.IListCryptoKeyVersionsRequest,
options?: gax.CallOptions | {}):
Transform{
request = request || {};
request = request || {};
const callSettings = new gax.CallSettings(options);
return this._descriptors.page.listCryptoKeyVersions.createStream(
this._innerApiCalls.listCryptoKeyVersions as gax.GaxCall,
Expand Down Expand Up @@ -2036,7 +2036,7 @@ export class KeyManagementServiceClient {
'parent': request.parent || '',
});
return this._innerApiCalls.listImportJobs(request, options, callback);
}
}

/**
* Equivalent to {@link listImportJobs}, but returns a NodeJS Stream object.
Expand Down Expand Up @@ -2078,7 +2078,7 @@ export class KeyManagementServiceClient {
request?: protosTypes.google.cloud.kms.v1.IListImportJobsRequest,
options?: gax.CallOptions | {}):
Transform{
request = request || {};
request = request || {};
const callSettings = new gax.CallSettings(options);
return this._descriptors.page.listImportJobs.createStream(
this._innerApiCalls.listImportJobs as gax.GaxCall,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ const version = require('../../../package.json').version;

/**
* Configures and manages Cloud Memorystore for Redis instances
*
*
* Google Cloud Memorystore for Redis v1beta1
*
*
* The `redis.googleapis.com` service implements the Google Cloud Memorystore
* for Redis API and defines the following resource model for managing Redis
* instances:
Expand All @@ -39,7 +39,7 @@ const version = require('../../../package.json').version;
* * Each location has a collection of Redis instances, named: `/instances/*`
* * As such, Redis instances are resources of the form:
* `/projects/{project_id}/locations/{location_id}/instances/{instance_id}`
*
*
* Note that location_id must be refering to a GCP `region`; for example:
* * `projects/redpepper-1290/locations/us-central1/instances/my-redis`
* @class
Expand Down Expand Up @@ -428,7 +428,7 @@ export class CloudRedisClient {
* where `location_id` refers to a GCP region.
* @param {string} request.instanceId
* Required. The logical name of the Redis instance in the customer project
* with the following restrictions:
* with the following restrictions:
*
* * Must contain only lowercase letters, numbers, and hyphens.
* * Must start with a letter.
Expand Down Expand Up @@ -501,7 +501,7 @@ export class CloudRedisClient {
* @param {google.protobuf.FieldMask} request.updateMask
* Required. Mask of fields to update. At least one path must be supplied in
* this field. The elements of the repeated paths field may only include these
* fields from [Instance][google.cloud.redis.v1beta1.Instance]:
* fields from [Instance][google.cloud.redis.v1beta1.Instance]:
*
* * `displayName`
* * `labels`
Expand Down Expand Up @@ -845,7 +845,7 @@ export class CloudRedisClient {
* `projects/{project_id}/locations/{location_id}`
* where `location_id` refers to a GCP region.
* @param {number} request.pageSize
* The maximum number of items to return.
* The maximum number of items to return.
*
* If not specified, a default value of 1000 will be used by the service.
* Regardless of the page_size value, the response may include a partial list
Expand Down Expand Up @@ -906,7 +906,7 @@ export class CloudRedisClient {
'parent': request.parent || '',
});
return this._innerApiCalls.listInstances(request, options, callback);
}
}

/**
* Equivalent to {@link listInstances}, but returns a NodeJS Stream object.
Expand All @@ -928,7 +928,7 @@ export class CloudRedisClient {
* `projects/{project_id}/locations/{location_id}`
* where `location_id` refers to a GCP region.
* @param {number} request.pageSize
* The maximum number of items to return.
* The maximum number of items to return.
*
* If not specified, a default value of 1000 will be used by the service.
* Regardless of the page_size value, the response may include a partial list
Expand All @@ -947,7 +947,7 @@ export class CloudRedisClient {
request?: protosTypes.google.cloud.redis.v1beta1.IListInstancesRequest,
options?: gax.CallOptions | {}):
Transform{
request = request || {};
request = request || {};
const callSettings = new gax.CallSettings(options);
return this._descriptors.page.listInstances.createStream(
this._innerApiCalls.listInstances as gax.GaxCall,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ service Echo {
}

// The request message used for the Echo, Collect and Chat methods. If content
// is set in this message then the request will succeed. If status is set in
// is set in this message then the request will succeed. If status is set in
// this message then the status will be returned as an error.
message EchoRequest {
oneof response {
Expand Down
Loading

0 comments on commit 096630c

Please sign in to comment.