Skip to content

Commit 0787a14

Browse files
committed
Prefer template string for formatting
1 parent a5337a9 commit 0787a14

File tree

9 files changed

+36
-37
lines changed

9 files changed

+36
-37
lines changed

eslint.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export default defineConfig(
2929
"@typescript-eslint/no-namespace": 0,
3030
// Plenty of APIs (like mocking APIs in Vitest) require empty functions to be declared.
3131
"@typescript-eslint/no-empty-function": 0,
32+
"prefer-template": 2,
3233
},
3334
},
3435
{

src/actionlib/ActionClient.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,31 +86,31 @@ export default class ActionClient<
8686
// create the topics associated with actionlib
8787
this.feedbackListener = new Topic({
8888
ros: this.ros,
89-
name: this.serverName + "/feedback",
90-
messageType: this.actionName + "Feedback",
89+
name: `${this.serverName}/feedback`,
90+
messageType: `${this.actionName}Feedback`,
9191
});
9292

9393
this.statusListener = new Topic({
9494
ros: this.ros,
95-
name: this.serverName + "/status",
95+
name: `${this.serverName}/status`,
9696
messageType: "actionlib_msgs/GoalStatusArray",
9797
});
9898

9999
this.resultListener = new Topic({
100100
ros: this.ros,
101-
name: this.serverName + "/result",
102-
messageType: this.actionName + "Result",
101+
name: `${this.serverName}/result`,
102+
messageType: `${this.actionName}Result`,
103103
});
104104

105105
this.goalTopic = new Topic({
106106
ros: this.ros,
107-
name: this.serverName + "/goal",
108-
messageType: this.actionName + "Goal",
107+
name: `${this.serverName}/goal`,
108+
messageType: `${this.actionName}Goal`,
109109
});
110110

111111
this.cancelTopic = new Topic({
112112
ros: this.ros,
113-
name: this.serverName + "/cancel",
113+
name: `${this.serverName}/cancel`,
114114
messageType: "actionlib_msgs/GoalID",
115115
});
116116

src/actionlib/ActionListener.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,22 +55,22 @@ export default class ActionListener<
5555
// create the topics associated with actionlib
5656
const goalListener = new Topic<TGoal>({
5757
ros: this.ros,
58-
name: this.serverName + "/goal",
59-
messageType: this.actionName + "Goal",
58+
name: `${this.serverName}/goal`,
59+
messageType: `${this.actionName}Goal`,
6060
});
6161

6262
const feedbackListener = new Topic<{
6363
status: actionlib_msgs.GoalStatus;
6464
feedback: TFeedback;
6565
}>({
6666
ros: this.ros,
67-
name: this.serverName + "/feedback",
68-
messageType: this.actionName + "Feedback",
67+
name: `${this.serverName}/feedback`,
68+
messageType: `${this.actionName}Feedback`,
6969
});
7070

7171
const statusListener = new Topic<actionlib_msgs.GoalStatusArray>({
7272
ros: this.ros,
73-
name: this.serverName + "/status",
73+
name: `${this.serverName}/status`,
7474
messageType: "actionlib_msgs/GoalStatusArray",
7575
});
7676

@@ -79,8 +79,8 @@ export default class ActionListener<
7979
result: TResult;
8080
}>({
8181
ros: this.ros,
82-
name: this.serverName + "/result",
83-
messageType: this.actionName + "Result",
82+
name: `${this.serverName}/result`,
83+
messageType: `${this.actionName}Result`,
8484
});
8585

8686
goalListener.subscribe((goalMessage) => {

src/actionlib/SimpleActionServer.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,22 +63,22 @@ export default class SimpleActionServer<
6363
// create and advertise publishers
6464
this.feedbackPublisher = new Topic({
6565
ros: this.ros,
66-
name: this.serverName + "/feedback",
67-
messageType: this.actionName + "Feedback",
66+
name: `${this.serverName}/feedback`,
67+
messageType: `${this.actionName}Feedback`,
6868
});
6969
this.feedbackPublisher.advertise();
7070

7171
const statusPublisher = new Topic({
7272
ros: this.ros,
73-
name: this.serverName + "/status",
73+
name: `${this.serverName}/status`,
7474
messageType: "actionlib_msgs/GoalStatusArray",
7575
});
7676
statusPublisher.advertise();
7777

7878
this.resultPublisher = new Topic({
7979
ros: this.ros,
80-
name: this.serverName + "/result",
81-
messageType: this.actionName + "Result",
80+
name: `${this.serverName}/result`,
81+
messageType: `${this.actionName}Result`,
8282
});
8383
this.resultPublisher.advertise();
8484

@@ -88,13 +88,13 @@ export default class SimpleActionServer<
8888
goal_id: actionlib_msgs.GoalID;
8989
}>({
9090
ros: this.ros,
91-
name: this.serverName + "/goal",
92-
messageType: this.actionName + "Goal",
91+
name: `${this.serverName}/goal`,
92+
messageType: `${this.actionName}Goal`,
9393
});
9494

9595
const cancelListener = new Topic<actionlib_msgs.GoalID>({
9696
ros: this.ros,
97-
name: this.serverName + "/cancel",
97+
name: `${this.serverName}/cancel`,
9898
messageType: "actionlib_msgs/GoalID",
9999
});
100100

src/core/Ros.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ export default class Ros extends EventEmitter<
174174
this.emit(message.id, message);
175175
} else if (isRosbridgeStatusMessage(message)) {
176176
if (message.id) {
177-
this.emit("status:" + message.id, message);
177+
this.emit(`status:${message.id}`, message);
178178
} else {
179179
this.emit("status", message);
180180
}
@@ -716,10 +716,7 @@ export default class Ros extends EventEmitter<
716716
typeDefDict[fieldName] = [subResult];
717717
}
718718
} else {
719-
this.emit(
720-
"error",
721-
"Cannot find " + fieldType + " in decodeTypeDefs",
722-
);
719+
this.emit("error", `Cannot find ${fieldType} in decodeTypeDefs`);
723720
}
724721
}
725722
}

src/core/Service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export default class Service<TRequest, TResponse> extends EventEmitter {
7474
return;
7575
}
7676

77-
const serviceCallId = "call_service:" + this.name + ":" + uuidv4();
77+
const serviceCallId = `call_service:${this.name}:${uuidv4()}`;
7878

7979
this.ros.once(serviceCallId, function (message) {
8080
if (isRosbridgeServiceResponseMessage<TResponse>(message)) {

src/core/SocketAdapter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ export default class SocketAdapter {
120120

121121
if (!entry) {
122122
// Should not happen, signal error
123-
throw new Error("Fragment buffer entry missing for id: " + id);
123+
throw new Error(`Fragment buffer entry missing for id: ${id}`);
124124
}
125125
// Only accept fragments within the integer part of total
126126
if (num < totalInt) {

src/core/Topic.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,9 @@ export default class Topic<T> extends EventEmitter<{
9999
) {
100100
this.emit(
101101
"warning",
102-
this.compression +
103-
" compression is not supported. No compression will be used.",
102+
`${
103+
this.compression
104+
} compression is not supported. No compression will be used.`,
104105
);
105106
this.compression = "none";
106107
}
@@ -109,7 +110,7 @@ export default class Topic<T> extends EventEmitter<{
109110
if (this.throttle_rate < 0) {
110111
this.emit(
111112
"warning",
112-
this.throttle_rate.toString() + " is not allowed. Set to 0",
113+
`${this.throttle_rate.toString()} is not allowed. Set to 0`,
113114
);
114115
this.throttle_rate = 0;
115116
}
@@ -153,7 +154,7 @@ export default class Topic<T> extends EventEmitter<{
153154
return;
154155
}
155156
this.ros.on(this.name, this.#messageCallback);
156-
this.subscribeId = "subscribe:" + this.name + ":" + uuidv4();
157+
this.subscribeId = `subscribe:${this.name}:${uuidv4()}`;
157158

158159
this.callForSubscribeAndAdvertise({
159160
op: "subscribe",
@@ -205,7 +206,7 @@ export default class Topic<T> extends EventEmitter<{
205206
if (this.isAdvertised) {
206207
return;
207208
}
208-
this.advertiseId = "advertise:" + this.name + ":" + uuidv4();
209+
this.advertiseId = `advertise:${this.name}:${uuidv4()}`;
209210
this.callForSubscribeAndAdvertise({
210211
op: "advertise",
211212
id: this.advertiseId,
@@ -252,7 +253,7 @@ export default class Topic<T> extends EventEmitter<{
252253

253254
const call = {
254255
op: "publish",
255-
id: "publish:" + this.name + ":" + uuidv4(),
256+
id: `publish:${this.name}:${uuidv4()}`,
256257
topic: this.name,
257258
msg: message,
258259
latch: this.latch,

src/util/shim/decompressPng.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,5 @@ export default function decompressPng(
5757
callback(JSON.parse(jsonData));
5858
};
5959
// Sends the image data to load.
60-
image.src = "data:image/png;base64," + data;
60+
image.src = `data:image/png;base64,${data}`;
6161
}

0 commit comments

Comments
 (0)