Skip to content

Commit d37cf8d

Browse files
authored
Upgrade strictness of typescript eslint (#1033)
1 parent b9fd7dd commit d37cf8d

31 files changed

+472
-233
lines changed

eslint.config.ts

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1-
// @ts-check
2-
1+
import { defineConfig } from "eslint/config";
32
import eslint from "@eslint/js";
43
import tseslint from "typescript-eslint";
54
import globals from "globals";
65
import jsdoc from "eslint-plugin-jsdoc";
76
import prettier from "eslint-plugin-prettier";
87

9-
export default tseslint.config(
8+
export default defineConfig(
109
eslint.configs.recommended,
1110
{
1211
// Linting rules for TS files, should be combined with the base config when migration is complete
1312
files: ["**/*.{js,jsx,ts,tsx,cjs}"],
14-
extends: [...tseslint.configs.recommended, ...tseslint.configs.stylistic],
13+
extends: [
14+
...tseslint.configs.strictTypeChecked,
15+
...tseslint.configs.stylisticTypeChecked,
16+
],
1517
languageOptions: {
1618
parser: tseslint.parser,
1719
parserOptions: {
@@ -22,21 +24,11 @@ export default tseslint.config(
2224
prettier,
2325
},
2426
rules: {
25-
eqeqeq: 2,
26-
"wrap-iife": [2, "any"],
27-
"no-use-before-define": 0,
28-
"no-caller": 2,
29-
"no-undef": 2,
30-
"no-cond-assign": 0,
31-
"no-eq-null": 0,
32-
strict: 0,
3327
"prettier/prettier": [2, { endOfLine: "auto" }],
34-
"no-proto": 2,
3528
// Disabled to allow namespaced ROS message types since that's how we think about message types in ROS
3629
"@typescript-eslint/no-namespace": 0,
3730
// Plenty of APIs (like mocking APIs in Vitest) require empty functions to be declared.
3831
"@typescript-eslint/no-empty-function": 0,
39-
"@typescript-eslint/no-unnecessary-condition": "error",
4032
},
4133
},
4234
{

examples/node_simple.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env node
22

33
// Connecting to ROS
4-
import ROSLIB from "roslib";
4+
import ROSLIB from "../src/index";
55

66
const ros = new ROSLIB.Ros({
77
url: "ws://localhost:9090",

package-lock.json

Lines changed: 51 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"devDependencies": {
2020
"@eslint/js": "^9.32.0",
2121
"@testing-library/react": "^16.0.0",
22+
"@types/dockerode": "^3.3.45",
2223
"@types/node": "^24.0.1",
2324
"@types/ws": "^8.5.10",
2425
"dockerode": "^4.0.9",

src/actionlib/ActionClient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export default class ActionClient<
2424
TFeedback = unknown,
2525
TResult = unknown,
2626
> extends EventEmitter<{
27-
timeout: void;
27+
timeout: undefined;
2828
}> {
2929
goals: Partial<Record<string, Goal<TGoal>>> = {};
3030
/** flag to check if a status has been received */

src/actionlib/Goal.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@ export default class Goal<
1818
TFeedback = unknown,
1919
TResult = unknown,
2020
> extends EventEmitter<{
21-
timeout: void;
22-
status: actionlib_msgs.GoalStatus;
21+
timeout: undefined;
22+
status: [actionlib_msgs.GoalStatus];
2323
feedback: [TFeedback];
2424
result: [TResult];
2525
}> {
2626
isFinished = false;
27-
status = undefined;
27+
status?: actionlib_msgs.GoalStatus = undefined;
2828
result?: TResult = undefined;
2929
feedback?: TFeedback = undefined;
3030
// Create a random ID
31-
goalID = "goal_" + Math.random() + "_" + new Date().getTime();
31+
goalID = `goal_${Math.random().toString()}_${new Date().getTime().toString()}`;
3232
actionClient: ActionClient<TGoal, TFeedback, TResult>;
3333
goalMessage: { goal: TGoal; goal_id: actionlib_msgs.GoalID };
3434
/**

src/actionlib/SimpleActionServer.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import Ros from "../core/Ros.js";
77
import Topic from "../core/Topic.js";
88
import { EventEmitter } from "eventemitter3";
99
import { actionlib_msgs } from "../types/actionlib_msgs.js";
10+
import { std_msgs } from "../types/std_msgs.js";
1011

1112
/**
1213
* An actionlib action server client.
@@ -21,7 +22,7 @@ export default class SimpleActionServer<
2122
TResult = unknown,
2223
> extends EventEmitter<{
2324
goal: [TGoal];
24-
cancel: void;
25+
cancel: undefined;
2526
}> {
2627
// needed for handling preemption prompted by a new goal being received
2728
currentGoal: { goal: TGoal; goal_id: actionlib_msgs.GoalID } | null = null; // currently tracked goal
@@ -125,7 +126,7 @@ export default class SimpleActionServer<
125126
* helper function to determine ordering of timestamps
126127
* returns t1 < t2
127128
*/
128-
const isEarlier = function (t1, t2) {
129+
const isEarlier = function (t1: std_msgs.time, t2: std_msgs.time) {
129130
if (t1.secs > t2.secs) {
130131
return false;
131132
} else if (t1.secs < t2.secs) {

src/core/Action.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import {
88
isRosbridgeActionFeedbackMessage,
99
isRosbridgeActionResultMessage,
1010
isRosbridgeCancelActionGoalMessage,
11+
isRosbridgeSendActionGoalMessage,
12+
RosbridgeSendActionGoalMessage,
1113
} from "../types/protocol.ts";
1214
import Ros from "./Ros.js";
1315

@@ -65,8 +67,7 @@ export default class Action<
6567
return;
6668
}
6769

68-
const actionGoalId =
69-
"send_action_goal:" + this.name + ":" + ++this.ros.idCounter;
70+
const actionGoalId = `send_action_goal:${this.name}:${(++this.ros.idCounter).toString()}`;
7071

7172
this.ros.on(actionGoalId, function (message) {
7273
if (isRosbridgeActionResultMessage<TResult>(message)) {
@@ -124,7 +125,15 @@ export default class Action<
124125

125126
this.#actionCallback = actionCallback;
126127
this.#cancelCallback = cancelCallback;
127-
this.ros.on(this.name, this.#executeAction.bind(this));
128+
this.ros.on(this.name, (msg) => {
129+
if (isRosbridgeSendActionGoalMessage(msg)) {
130+
this.#executeAction.bind(this);
131+
} else {
132+
throw new Error(
133+
"Received unrelated message on Action server event stream!",
134+
);
135+
}
136+
});
128137
this.ros.callOnConnection({
129138
op: "advertise_action",
130139
type: this.actionType,
@@ -156,7 +165,7 @@ export default class Action<
156165
* @param rosbridgeRequest.id - The ID of the action goal.
157166
* @param rosbridgeRequest.args - The arguments of the action goal.
158167
*/
159-
#executeAction(rosbridgeRequest: { id: string; args: TGoal }) {
168+
#executeAction(rosbridgeRequest: RosbridgeSendActionGoalMessage<TGoal>) {
160169
const id = rosbridgeRequest.id;
161170

162171
// If a cancellation callback exists, call it when a cancellation event is emitted.
@@ -173,7 +182,13 @@ export default class Action<
173182

174183
// Call the action goal execution function provided.
175184
if (this.#actionCallback) {
176-
this.#actionCallback(rosbridgeRequest.args, id);
185+
if (rosbridgeRequest.args) {
186+
this.#actionCallback(rosbridgeRequest.args, id);
187+
} else {
188+
throw new Error(
189+
"Received Action goal with no arguments! This should never happen, because rosbridge should fill in blanks!",
190+
);
191+
}
177192
}
178193
}
179194

src/core/Param.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,10 @@ export default class Param<T = unknown> {
4646
paramClient.callService(
4747
request,
4848
function (result) {
49-
if (result.successful === false) {
49+
if ("successful" in result && !result.successful) {
5050
failedCallback(result.reason);
5151
} else {
52-
const value = JSON.parse(result.value);
53-
callback(value);
52+
callback(JSON.parse(result.value) as T);
5453
}
5554
},
5655
failedCallback,
@@ -85,7 +84,7 @@ export default class Param<T = unknown> {
8584
paramClient.callService(
8685
request,
8786
function (result) {
88-
if (result.successful === false) {
87+
if ("successful" in result && !result.successful) {
8988
failedCallback(result.reason);
9089
} else if (callback) {
9190
callback(result);
@@ -120,7 +119,7 @@ export default class Param<T = unknown> {
120119
paramClient.callService(
121120
request,
122121
function (result) {
123-
if (result.successful === false) {
122+
if ("successful" in result && !result.successful) {
124123
failedCallback(result.reason);
125124
} else {
126125
callback(result);

0 commit comments

Comments
 (0)