Skip to content

Commit 36e8a59

Browse files
committed
samples: fix linting and typelessing of samples
1 parent a51815c commit 36e8a59

13 files changed

+24
-26
lines changed

package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@
4545
"predocs-test": "npm run docs",
4646
"benchwrapper": "node bin/benchwrapper.js",
4747
"prelint": "cd samples; npm link ../; npm install",
48-
"precompile": "gts clean",
49-
"typeless": "npx typeless-sample-bot --outputpath samples --targets samples --recursive",
50-
"posttypeless": "npm run link-samples && npx eslint --ignore-pattern owl-bot-staging --fix samples"
48+
"precompile": "gts clean"
5149
},
5250
"dependencies": {
5351
"@google-cloud/paginator": "^6.0.0",
@@ -66,7 +64,6 @@
6664
"p-defer": "^3.0.0"
6765
},
6866
"devDependencies": {
69-
"@google-cloud/typeless-sample-bot": "^3.0.0",
7067
"@grpc/proto-loader": "^0.7.13",
7168
"@opentelemetry/core": "^1.17.0",
7269
"@opentelemetry/sdk-trace-base": "^1.17.0",

samples/createTopic.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ async function createTopic(topicNameOrId) {
4848
}
4949
// [END pubsub_create_topic]
5050

51-
async function main(topicNameOrId = 'YOUR_TOPIC_NAME_OR_ID') {
51+
function main(topicNameOrId = 'YOUR_TOPIC_NAME_OR_ID') {
5252
createTopic(topicNameOrId).catch(err => {
5353
console.error(err.message);
5454
process.exitCode = 1;

samples/listenWithCustomAttributes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ async function listenWithCustomAttributes(subscriptionNameOrId, timeout) {
6666
}
6767
// [END pubsub_subscriber_async_pull_custom_attributes]
6868

69-
async function main(
69+
function main(
7070
subscriptionNameOrId = 'YOUR_SUBSCRIPTION_NAME_OR_ID',
7171
timeout = 60,
7272
) {

samples/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@
1818
"sampletsc": "cd typescript && tsc -p . && cd ..",
1919
"compile": "npm run tsc && npm run sampletsc",
2020
"clean": "gts clean && rm -rf build/",
21-
"precompile": "npm run clean"
21+
"precompile": "npm run clean",
22+
"pretypeless": "npx eslint --fix typescript/*.ts",
23+
"typeless": "npx typeless-sample-bot --outputpath . --targets typescript --recursive",
24+
"posttypeless": "npx eslint --fix *.js"
2225
},
2326
"dependencies": {
2427
"@google-cloud/opentelemetry-cloud-trace-exporter": "^2.0.0",
@@ -35,6 +38,7 @@
3538
},
3639
"devDependencies": {
3740
"@google-cloud/bigquery": "^7.0.0",
41+
"@google-cloud/typeless-sample-bot": "^3.0.0",
3842
"@types/chai": "^4.2.16",
3943
"chai": "^4.2.0",
4044
"gts": "^5.0.0",

samples/publishOrderedMessage.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,12 @@ async function publishOrderedMessage(topicNameOrId, data, orderingKey) {
8080
}
8181
// [END pubsub_publish_with_ordering_keys]
8282

83-
async function main(
83+
function main(
8484
topicNameOrId = 'YOUR_TOPIC_NAME_OR_ID',
8585
data = JSON.stringify({foo: 'bar'}),
8686
orderingKey = 'key1',
8787
) {
88-
await publishOrderedMessage(topicNameOrId, data, orderingKey).catch(err => {
88+
publishOrderedMessage(topicNameOrId, data, orderingKey).catch(err => {
8989
console.error(err.message);
9090
process.exitCode = 1;
9191
});

samples/quickstart.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,11 @@ async function quickstart(
5555
});
5656

5757
// Send a message to the topic
58-
topic.publishMessage({data: Buffer.from('Test message!')});
58+
await topic.publishMessage({data: Buffer.from('Test message!')});
5959
}
6060
// [END pubsub_quickstart_create_topic]
6161

62-
process.on('unhandledRejection', err => {
62+
quickstart(...process.argv.slice(2)).catch(err => {
6363
console.error(err.message);
6464
process.exitCode = 1;
6565
});
66-
quickstart(...process.argv.slice(2));

samples/subscribeWithFlowControlSettings.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ async function subscribeWithFlowControlSettings(
7979
subscription.on('message', messageHandler);
8080

8181
// Wait a while for the subscription to run. (Part of the sample only.)
82-
setTimeout(() => {
83-
subscription.close();
82+
setTimeout(async () => {
83+
await subscription.close();
8484
}, timeout * 1000);
8585
}
8686
// [END pubsub_subscriber_flow_settings]

samples/typescript/createTopic.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ async function createTopic(topicNameOrId: string) {
4444
}
4545
// [END pubsub_create_topic]
4646

47-
async function main(topicNameOrId = 'YOUR_TOPIC_NAME_OR_ID') {
47+
function main(topicNameOrId = 'YOUR_TOPIC_NAME_OR_ID') {
4848
createTopic(topicNameOrId).catch(err => {
4949
console.error(err.message);
5050
process.exitCode = 1;

samples/typescript/listenWithCustomAttributes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ async function listenWithCustomAttributes(
6565
}
6666
// [END pubsub_subscriber_async_pull_custom_attributes]
6767

68-
async function main(
68+
function main(
6969
subscriptionNameOrId = 'YOUR_SUBSCRIPTION_NAME_OR_ID',
7070
timeout = 60,
7171
) {

samples/typescript/publishOrderedMessage.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,12 @@ async function publishOrderedMessage(
8080
}
8181
// [END pubsub_publish_with_ordering_keys]
8282

83-
async function main(
83+
function main(
8484
topicNameOrId = 'YOUR_TOPIC_NAME_OR_ID',
8585
data = JSON.stringify({foo: 'bar'}),
8686
orderingKey = 'key1',
8787
) {
88-
await publishOrderedMessage(topicNameOrId, data, orderingKey).catch(err => {
88+
publishOrderedMessage(topicNameOrId, data, orderingKey).catch(err => {
8989
console.error(err.message);
9090
process.exitCode = 1;
9191
});

0 commit comments

Comments
 (0)