diff --git a/package.json b/package.json index b9621c07..b300bf5c 100644 --- a/package.json +++ b/package.json @@ -38,11 +38,11 @@ "system-test": "mocha build/system-test --timeout 600000", "samples-test": "cd samples/ && npm test && cd ../", "generate-scaffolding": "repo-tools generate all && repo-tools generate lib_samples_readme -l samples/ --config ../.cloud-repo-tools.json", - "lint": "gts check && eslint samples/", + "lint": "gts check && eslint '**/*.js'", "check": "gts check", "clean": "gts clean", "compile": "tsc -p . && cp -r src/v2 build/src/v2 && cp -r protos build && cp test/*.js build/test", - "fix": "gts fix && eslint --fix 'samples/*.js' 'samples/**/*.js'", + "fix": "gts fix && eslint --fix '**/*.js'", "prepare": "npm run compile", "pretest": "npm run compile", "posttest": "npm run check", diff --git a/smoke-test/.eslintrc.yml b/smoke-test/.eslintrc.yml new file mode 100644 index 00000000..fb2657e4 --- /dev/null +++ b/smoke-test/.eslintrc.yml @@ -0,0 +1,5 @@ +--- +env: + mocha: true +rules: + node/no-missing-require: off diff --git a/smoke-test/logging_service_v2_smoke_test.js b/smoke-test/logging_service_v2_smoke_test.js index f1ca8de3..67adbee5 100644 --- a/smoke-test/logging_service_v2_smoke_test.js +++ b/smoke-test/logging_service_v2_smoke_test.js @@ -42,10 +42,6 @@ describe('LoggingServiceV2SmokeTest', () => { }; client .writeLogEntries(request) - .then(responses => { - const response = responses[0]; - console.log(response); - }) .then(done) .catch(done); }); diff --git a/src/v2/.eslintrc.yml b/src/v2/.eslintrc.yml new file mode 100644 index 00000000..46afd952 --- /dev/null +++ b/src/v2/.eslintrc.yml @@ -0,0 +1,3 @@ +--- +rules: + node/no-missing-require: off diff --git a/src/v2/config_service_v2_client.js b/src/v2/config_service_v2_client.js index a81e9d1f..2de4d4d2 100644 --- a/src/v2/config_service_v2_client.js +++ b/src/v2/config_service_v2_client.js @@ -101,12 +101,8 @@ class ConfigServiceV2Client { // identifiers to uniquely identify resources within the API. // Create useful helper objects for these. this._pathTemplates = { - projectPathTemplate: new gax.PathTemplate( - 'projects/{project}' - ), - sinkPathTemplate: new gax.PathTemplate( - 'projects/{project}/sinks/{sink}' - ), + projectPathTemplate: new gax.PathTemplate('projects/{project}'), + sinkPathTemplate: new gax.PathTemplate('projects/{project}/sinks/{sink}'), exclusionPathTemplate: new gax.PathTemplate( 'projects/{project}/exclusions/{exclusion}' ), @@ -116,11 +112,7 @@ class ConfigServiceV2Client { // (e.g. 50 results at a time, with tokens to get subsequent // pages). Denote the keys used for pagination and results. this._descriptors.page = { - listSinks: new gax.PageDescriptor( - 'pageToken', - 'nextPageToken', - 'sinks' - ), + listSinks: new gax.PageDescriptor('pageToken', 'nextPageToken', 'sinks'), listExclusions: new gax.PageDescriptor( 'pageToken', 'nextPageToken', @@ -261,7 +253,7 @@ class ConfigServiceV2Client { * * @example * - const logging = require('@google-cloud/logging'); + * const logging = require('@google-cloud/logging'); * * const client = new logging.v2.ConfigServiceV2Client({ * // optional auth parameters. @@ -353,7 +345,7 @@ class ConfigServiceV2Client { * * @example * - const logging = require('@google-cloud/logging'); + * const logging = require('@google-cloud/logging'); * * const client = new logging.v2.ConfigServiceV2Client({ * // optional auth parameters. @@ -375,7 +367,7 @@ class ConfigServiceV2Client { request, options ); - }; + } /** * Gets a sink. @@ -404,7 +396,7 @@ class ConfigServiceV2Client { * * @example * - const logging = require('@google-cloud/logging'); + * const logging = require('@google-cloud/logging'); * * const client = new logging.v2.ConfigServiceV2Client({ * // optional auth parameters. @@ -477,7 +469,7 @@ class ConfigServiceV2Client { * * @example * - const logging = require('@google-cloud/logging'); + * const logging = require('@google-cloud/logging'); * * const client = new logging.v2.ConfigServiceV2Client({ * // optional auth parameters. @@ -574,7 +566,7 @@ class ConfigServiceV2Client { * * @example * - const logging = require('@google-cloud/logging'); + * const logging = require('@google-cloud/logging'); * * const client = new logging.v2.ConfigServiceV2Client({ * // optional auth parameters. @@ -631,7 +623,7 @@ class ConfigServiceV2Client { * * @example * - const logging = require('@google-cloud/logging'); + * const logging = require('@google-cloud/logging'); * * const client = new logging.v2.ConfigServiceV2Client({ * // optional auth parameters. @@ -695,7 +687,7 @@ class ConfigServiceV2Client { * * @example * - const logging = require('@google-cloud/logging'); + * const logging = require('@google-cloud/logging'); * * const client = new logging.v2.ConfigServiceV2Client({ * // optional auth parameters. @@ -787,7 +779,7 @@ class ConfigServiceV2Client { * * @example * - const logging = require('@google-cloud/logging'); + * const logging = require('@google-cloud/logging'); * * const client = new logging.v2.ConfigServiceV2Client({ * // optional auth parameters. @@ -809,7 +801,7 @@ class ConfigServiceV2Client { request, options ); - }; + } /** * Gets the description of an exclusion. @@ -838,7 +830,7 @@ class ConfigServiceV2Client { * * @example * - const logging = require('@google-cloud/logging'); + * const logging = require('@google-cloud/logging'); * * const client = new logging.v2.ConfigServiceV2Client({ * // optional auth parameters. @@ -898,7 +890,7 @@ class ConfigServiceV2Client { * * @example * - const logging = require('@google-cloud/logging'); + * const logging = require('@google-cloud/logging'); * * const client = new logging.v2.ConfigServiceV2Client({ * // optional auth parameters. @@ -971,7 +963,7 @@ class ConfigServiceV2Client { * * @example * - const logging = require('@google-cloud/logging'); + * const logging = require('@google-cloud/logging'); * * const client = new logging.v2.ConfigServiceV2Client({ * // optional auth parameters. @@ -1028,7 +1020,7 @@ class ConfigServiceV2Client { * * @example * - const logging = require('@google-cloud/logging'); + * const logging = require('@google-cloud/logging'); * * const client = new logging.v2.ConfigServiceV2Client({ * // optional auth parameters. @@ -1101,9 +1093,7 @@ class ConfigServiceV2Client { * @returns {String} - A string representing the project. */ matchProjectFromProjectName(projectName) { - return this._pathTemplates.projectPathTemplate - .match(projectName) - .project; + return this._pathTemplates.projectPathTemplate.match(projectName).project; } /** @@ -1114,9 +1104,7 @@ class ConfigServiceV2Client { * @returns {String} - A string representing the project. */ matchProjectFromSinkName(sinkName) { - return this._pathTemplates.sinkPathTemplate - .match(sinkName) - .project; + return this._pathTemplates.sinkPathTemplate.match(sinkName).project; } /** @@ -1127,9 +1115,7 @@ class ConfigServiceV2Client { * @returns {String} - A string representing the sink. */ matchSinkFromSinkName(sinkName) { - return this._pathTemplates.sinkPathTemplate - .match(sinkName) - .sink; + return this._pathTemplates.sinkPathTemplate.match(sinkName).sink; } /** @@ -1140,8 +1126,7 @@ class ConfigServiceV2Client { * @returns {String} - A string representing the project. */ matchProjectFromExclusionName(exclusionName) { - return this._pathTemplates.exclusionPathTemplate - .match(exclusionName) + return this._pathTemplates.exclusionPathTemplate.match(exclusionName) .project; } @@ -1153,11 +1138,9 @@ class ConfigServiceV2Client { * @returns {String} - A string representing the exclusion. */ matchExclusionFromExclusionName(exclusionName) { - return this._pathTemplates.exclusionPathTemplate - .match(exclusionName) + return this._pathTemplates.exclusionPathTemplate.match(exclusionName) .exclusion; } } - module.exports = ConfigServiceV2Client; diff --git a/src/v2/logging_service_v2_client.js b/src/v2/logging_service_v2_client.js index 50a1084e..7941f95b 100644 --- a/src/v2/logging_service_v2_client.js +++ b/src/v2/logging_service_v2_client.js @@ -101,12 +101,8 @@ class LoggingServiceV2Client { // identifiers to uniquely identify resources within the API. // Create useful helper objects for these. this._pathTemplates = { - logPathTemplate: new gax.PathTemplate( - 'projects/{project}/logs/{log}' - ), - projectPathTemplate: new gax.PathTemplate( - 'projects/{project}' - ), + logPathTemplate: new gax.PathTemplate('projects/{project}/logs/{log}'), + projectPathTemplate: new gax.PathTemplate('projects/{project}'), }; // Some of the methods on this service return "paged" results, @@ -131,23 +127,26 @@ class LoggingServiceV2Client { }; let protoFilesRoot = new gax.GoogleProtoFilesRoot(); protoFilesRoot = protobuf.loadSync( - path.join(__dirname, '..', '..', 'protos', 'google/logging/v2/logging.proto'), + path.join( + __dirname, + '..', + '..', + 'protos', + 'google/logging/v2/logging.proto' + ), protoFilesRoot ); - // Some methods on this API support automatically batching // requests; denote this. this._descriptors.batching = { writeLogEntries: new gax.BundleDescriptor( 'entries', - [ - 'logName', - 'resource', - 'labels', - ], + ['logName', 'resource', 'labels'], null, - gax.createByteLengthFunction(protoFilesRoot.lookup('google.logging.v2.LogEntry')) + gax.createByteLengthFunction( + protoFilesRoot.lookup('google.logging.v2.LogEntry') + ) ), }; @@ -190,7 +189,8 @@ class LoggingServiceV2Client { } ), defaults[methodName], - this._descriptors.page[methodName] || this._descriptors.batching[methodName] + this._descriptors.page[methodName] || + this._descriptors.batching[methodName] ); } } @@ -267,7 +267,7 @@ class LoggingServiceV2Client { * * @example * - const logging = require('@google-cloud/logging'); + * const logging = require('@google-cloud/logging'); * * const client = new logging.v2.LoggingServiceV2Client({ * // optional auth parameters. @@ -382,7 +382,7 @@ class LoggingServiceV2Client { * * @example * - const logging = require('@google-cloud/logging'); + * const logging = require('@google-cloud/logging'); * * const client = new logging.v2.LoggingServiceV2Client({ * // optional auth parameters. @@ -477,7 +477,7 @@ class LoggingServiceV2Client { * * @example * - const logging = require('@google-cloud/logging'); + * const logging = require('@google-cloud/logging'); * * const client = new logging.v2.LoggingServiceV2Client({ * // optional auth parameters. @@ -593,7 +593,7 @@ class LoggingServiceV2Client { * * @example * - const logging = require('@google-cloud/logging'); + * const logging = require('@google-cloud/logging'); * * const client = new logging.v2.LoggingServiceV2Client({ * // optional auth parameters. @@ -615,7 +615,7 @@ class LoggingServiceV2Client { request, options ); - }; + } /** * Lists the descriptors for monitored resource types used by Logging. @@ -653,7 +653,7 @@ class LoggingServiceV2Client { * * @example * - const logging = require('@google-cloud/logging'); + * const logging = require('@google-cloud/logging'); * * const client = new logging.v2.LoggingServiceV2Client({ * // optional auth parameters. @@ -702,7 +702,11 @@ class LoggingServiceV2Client { } options = options || {}; - return this._innerApiCalls.listMonitoredResourceDescriptors(request, options, callback); + return this._innerApiCalls.listMonitoredResourceDescriptors( + request, + options, + callback + ); } /** @@ -734,7 +738,7 @@ class LoggingServiceV2Client { * * @example * - const logging = require('@google-cloud/logging'); + * const logging = require('@google-cloud/logging'); * * const client = new logging.v2.LoggingServiceV2Client({ * // optional auth parameters. @@ -756,7 +760,7 @@ class LoggingServiceV2Client { request, options ); - }; + } /** * Lists the logs in projects, organizations, folders, or billing accounts. @@ -802,7 +806,7 @@ class LoggingServiceV2Client { * * @example * - const logging = require('@google-cloud/logging'); + * const logging = require('@google-cloud/logging'); * * const client = new logging.v2.LoggingServiceV2Client({ * // optional auth parameters. @@ -894,7 +898,7 @@ class LoggingServiceV2Client { * * @example * - const logging = require('@google-cloud/logging'); + * const logging = require('@google-cloud/logging'); * * const client = new logging.v2.LoggingServiceV2Client({ * // optional auth parameters. @@ -916,7 +920,7 @@ class LoggingServiceV2Client { request, options ); - }; + } // -------------------- // -- Path templates -- @@ -956,9 +960,7 @@ class LoggingServiceV2Client { * @returns {String} - A string representing the project. */ matchProjectFromLogName(logName) { - return this._pathTemplates.logPathTemplate - .match(logName) - .project; + return this._pathTemplates.logPathTemplate.match(logName).project; } /** @@ -969,9 +971,7 @@ class LoggingServiceV2Client { * @returns {String} - A string representing the log. */ matchLogFromLogName(logName) { - return this._pathTemplates.logPathTemplate - .match(logName) - .log; + return this._pathTemplates.logPathTemplate.match(logName).log; } /** @@ -982,11 +982,8 @@ class LoggingServiceV2Client { * @returns {String} - A string representing the project. */ matchProjectFromProjectName(projectName) { - return this._pathTemplates.projectPathTemplate - .match(projectName) - .project; + return this._pathTemplates.projectPathTemplate.match(projectName).project; } } - module.exports = LoggingServiceV2Client; diff --git a/src/v2/metrics_service_v2_client.js b/src/v2/metrics_service_v2_client.js index f5396681..c6fe9c87 100644 --- a/src/v2/metrics_service_v2_client.js +++ b/src/v2/metrics_service_v2_client.js @@ -100,9 +100,7 @@ class MetricsServiceV2Client { // identifiers to uniquely identify resources within the API. // Create useful helper objects for these. this._pathTemplates = { - projectPathTemplate: new gax.PathTemplate( - 'projects/{project}' - ), + projectPathTemplate: new gax.PathTemplate('projects/{project}'), metricPathTemplate: new gax.PathTemplate( 'projects/{project}/metrics/{metric}' ), @@ -244,7 +242,7 @@ class MetricsServiceV2Client { * * @example * - const logging = require('@google-cloud/logging'); + * const logging = require('@google-cloud/logging'); * * const client = new logging.v2.MetricsServiceV2Client({ * // optional auth parameters. @@ -333,7 +331,7 @@ class MetricsServiceV2Client { * * @example * - const logging = require('@google-cloud/logging'); + * const logging = require('@google-cloud/logging'); * * const client = new logging.v2.MetricsServiceV2Client({ * // optional auth parameters. @@ -355,7 +353,7 @@ class MetricsServiceV2Client { request, options ); - }; + } /** * Gets a logs-based metric. @@ -379,7 +377,7 @@ class MetricsServiceV2Client { * * @example * - const logging = require('@google-cloud/logging'); + * const logging = require('@google-cloud/logging'); * * const client = new logging.v2.MetricsServiceV2Client({ * // optional auth parameters. @@ -434,7 +432,7 @@ class MetricsServiceV2Client { * * @example * - const logging = require('@google-cloud/logging'); + * const logging = require('@google-cloud/logging'); * * const client = new logging.v2.MetricsServiceV2Client({ * // optional auth parameters. @@ -495,7 +493,7 @@ class MetricsServiceV2Client { * * @example * - const logging = require('@google-cloud/logging'); + * const logging = require('@google-cloud/logging'); * * const client = new logging.v2.MetricsServiceV2Client({ * // optional auth parameters. @@ -545,7 +543,7 @@ class MetricsServiceV2Client { * * @example * - const logging = require('@google-cloud/logging'); + * const logging = require('@google-cloud/logging'); * * const client = new logging.v2.MetricsServiceV2Client({ * // optional auth parameters. @@ -604,9 +602,7 @@ class MetricsServiceV2Client { * @returns {String} - A string representing the project. */ matchProjectFromProjectName(projectName) { - return this._pathTemplates.projectPathTemplate - .match(projectName) - .project; + return this._pathTemplates.projectPathTemplate.match(projectName).project; } /** @@ -617,9 +613,7 @@ class MetricsServiceV2Client { * @returns {String} - A string representing the project. */ matchProjectFromMetricName(metricName) { - return this._pathTemplates.metricPathTemplate - .match(metricName) - .project; + return this._pathTemplates.metricPathTemplate.match(metricName).project; } /** @@ -630,11 +624,8 @@ class MetricsServiceV2Client { * @returns {String} - A string representing the metric. */ matchMetricFromMetricName(metricName) { - return this._pathTemplates.metricPathTemplate - .match(metricName) - .metric; + return this._pathTemplates.metricPathTemplate.match(metricName).metric; } } - module.exports = MetricsServiceV2Client; diff --git a/synth.py b/synth.py index e705b204..d61abaeb 100644 --- a/synth.py +++ b/synth.py @@ -39,15 +39,6 @@ "../../package.json", "../../../package.json", ) -s.replace( - [ - "src/v2/config_service_v2_client.js", - "src/v2/logging_service_v2_client.js", - "src/v2/metrics_service_v2_client.js", - ], - "(\*\s*)const logging = require\('@google-cloud/logging'\);", - "\1const logging = require('@google-cloud/logging');", -) # Copy in templated files common_templates = gcp.CommonTemplates() diff --git a/test/.eslintrc.yml b/test/.eslintrc.yml index 73f7bbc9..32007e3d 100644 --- a/test/.eslintrc.yml +++ b/test/.eslintrc.yml @@ -2,4 +2,5 @@ env: mocha: true rules: + node/no-missing-require: off node/no-unpublished-require: off diff --git a/test/gapic-v2.js b/test/gapic-v2.js index b5319a6a..74342e23 100644 --- a/test/gapic-v2.js +++ b/test/gapic-v2.js @@ -152,7 +152,11 @@ describe('LoggingServiceV2Client', () => { }; // Mock Grpc layer - client._innerApiCalls.listLogEntries = (actualRequest, options, callback) => { + client._innerApiCalls.listLogEntries = ( + actualRequest, + options, + callback + ) => { assert.deepStrictEqual(actualRequest, request); callback(null, expectedResponse.entries); }; @@ -212,7 +216,11 @@ describe('LoggingServiceV2Client', () => { }; // Mock Grpc layer - client._innerApiCalls.listMonitoredResourceDescriptors = (actualRequest, options, callback) => { + client._innerApiCalls.listMonitoredResourceDescriptors = ( + actualRequest, + options, + callback + ) => { assert.deepStrictEqual(actualRequest, request); callback(null, expectedResponse.resourceDescriptors); }; @@ -311,7 +319,6 @@ describe('LoggingServiceV2Client', () => { }); }); }); - }); describe('ConfigServiceV2Client', () => { describe('listSinks', () => { @@ -661,7 +668,11 @@ describe('ConfigServiceV2Client', () => { }; // Mock Grpc layer - client._innerApiCalls.listExclusions = (actualRequest, options, callback) => { + client._innerApiCalls.listExclusions = ( + actualRequest, + options, + callback + ) => { assert.deepStrictEqual(actualRequest, request); callback(null, expectedResponse.exclusions); }; @@ -959,7 +970,6 @@ describe('ConfigServiceV2Client', () => { }); }); }); - }); describe('MetricsServiceV2Client', () => { describe('listLogMetrics', () => { @@ -985,7 +995,11 @@ describe('MetricsServiceV2Client', () => { }; // Mock Grpc layer - client._innerApiCalls.listLogMetrics = (actualRequest, options, callback) => { + client._innerApiCalls.listLogMetrics = ( + actualRequest, + options, + callback + ) => { assert.deepStrictEqual(actualRequest, request); callback(null, expectedResponse.metrics); }; @@ -1279,7 +1293,6 @@ describe('MetricsServiceV2Client', () => { }); }); }); - }); function mockSimpleGrpcMethod(expectedRequest, response, error) {