Skip to content

Commit 6310a5f

Browse files
committed
Config eslint
1 parent 395ed22 commit 6310a5f

17 files changed

+98
-107
lines changed

.github/workflows/linux-build-and-test-compatibility.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,5 @@ jobs:
3535
run: |
3636
source /opt/ros/${{ matrix.ros_distribution }}/setup.bash
3737
npm i
38+
npm run lint
3839
npm test

eslint.config.mjs

Lines changed: 57 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,66 @@
1+
import typescriptEslint from "@typescript-eslint/eslint-plugin";
12
import prettier from "eslint-plugin-prettier";
23
import globals from "globals";
3-
import typescriptEslint from "@typescript-eslint/eslint-plugin";
44
import tsParser from "@typescript-eslint/parser";
5-
import path from "node:path";
6-
import { fileURLToPath } from "node:url";
5+
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended';
76
import js from "@eslint/js";
8-
import { FlatCompat } from "@eslint/eslintrc";
9-
10-
const __filename = fileURLToPath(import.meta.url);
11-
const __dirname = path.dirname(__filename);
12-
const compat = new FlatCompat({
13-
baseDirectory: __dirname,
14-
recommendedConfig: js.configs.recommended,
15-
allConfig: js.configs.all
16-
});
17-
18-
export default [{
19-
ignores: ["generated/", "eslint.config.mjs", "lib/", "types/", "scripts/", "benchmark/", "docs/", "electron_demo/"],
20-
}, ...compat.extends("prettier"), {
21-
plugins: {
22-
prettier,
23-
},
247

25-
languageOptions: {
26-
globals: {
27-
...globals.node,
28-
every: true,
29-
after: true,
30-
constantly: true,
31-
},
32-
33-
ecmaVersion: "latest",
34-
sourceType: "commonjs",
8+
export default [
9+
{
10+
ignores: [
11+
"eslint.config.mjs",
12+
"types/interfaces.d.ts",
13+
"test/types/index.test-d.ts",
14+
"**/generated/",
15+
"**/scripts/",
16+
"**/benchmark/",
17+
"**/docs/",
18+
"**/electron_demo/",
19+
"**/generated/",
20+
],
3521
},
36-
37-
rules: {
38-
"prettier/prettier": "error",
39-
},
40-
}, {
41-
files: ["types/*.d.ts"],
42-
43-
plugins: {
44-
"@typescript-eslint": typescriptEslint,
22+
{
23+
...js.configs.recommended,
24+
files: ["lib/**/*.js", "index.js"],
4525
},
46-
47-
languageOptions: {
48-
parser: tsParser,
49-
sourceType: "module",
26+
{
27+
rules: {
28+
'no-dupe-class-members': 'off',
29+
},
5030
},
51-
52-
rules: {
53-
strict: [0, "global"],
31+
{
32+
plugins: {
33+
"@typescript-eslint": typescriptEslint,
34+
},
35+
languageOptions: {
36+
globals: {
37+
...globals.node,
38+
},
39+
parser: tsParser,
40+
ecmaVersion: "latest",
41+
sourceType: "module",
42+
},
43+
files: ['types/*.d.ts'],
44+
rules: {
45+
...typescriptEslint.configs.recommended.rules,
46+
"@typescript-eslint/no-explicit-any": "off",
47+
},
5448
},
55-
}];
49+
{
50+
plugins: {
51+
prettier,
52+
},
53+
languageOptions: {
54+
globals: {
55+
...globals.node,
56+
},
57+
ecmaVersion: "latest",
58+
sourceType: "commonjs",
59+
},
60+
files: ["lib/**/*.js", "rosidl_parser/**/*.js", "rosidl_gen/**/*.js",
61+
"rostsd_gen/**/*.js", "test/**/*.js", "example/**/*.js", "index.js"],
62+
rules: {
63+
...eslintPluginPrettierRecommended.rules,
64+
},
65+
}
66+
];

lib/distro.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ const DistroUtils = {
6363
return process.env.ROS_DISTRO;
6464
}
6565

66-
return [...DistroNameIdMap].find(([key, val]) => val == distroId)[0];
66+
return [...DistroNameIdMap].find(([, val]) => val == distroId)[0];
6767
},
6868

6969
getKnownDistroNames: function () {

lib/lifecycle.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -588,8 +588,6 @@ class LifecycleNode extends Node {
588588
* @throws {Error} If transition is invalid for the current state.
589589
*/
590590
shutdown(callbackReturnValue) {
591-
let state = this.currentState;
592-
593591
return this._changeState(SHUTDOWN_TRANSITION_LABEL, callbackReturnValue);
594592
}
595593

lib/node.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1549,7 +1549,7 @@ class Node extends rclnodejs.ShadowNode {
15491549
// detect invalid parameter
15501550
try {
15511551
parameter.validate();
1552-
} catch (e) {
1552+
} catch {
15531553
return {
15541554
successful: false,
15551555
reason: `Invalid ${parameter.name}`,
@@ -1577,7 +1577,7 @@ class Node extends rclnodejs.ShadowNode {
15771577
if (parameter.type != ParameterType.PARAMETER_NOT_SET) {
15781578
try {
15791579
descriptor.validateParameter(parameter);
1580-
} catch (e) {
1580+
} catch {
15811581
return {
15821582
successful: false,
15831583
reason: `Parameter ${parameter.name} does not readonly`,

lib/parameter.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,6 @@ class ParameterDescriptor {
271271
static fromParameter(parameter) {
272272
const name = parameter.name;
273273
const type = parameter.type;
274-
const value = parameter.value;
275274
return new ParameterDescriptor(name, type, 'Created from parameter.');
276275
}
277276

@@ -384,7 +383,7 @@ class ParameterDescriptor {
384383
return;
385384
}
386385
if (!(range instanceof Range)) {
387-
throw TypeException('Expected instance of Range.');
386+
throw TypeError('Expected instance of Range.');
388387
}
389388
if (!range.isValidType(this.type)) {
390389
throw TypeError('Incompatible Range');
@@ -440,14 +439,14 @@ class ParameterDescriptor {
440439
// ensure parameter is valid
441440
try {
442441
parameter.validate();
443-
} catch (e) {
442+
} catch {
444443
throw new TypeError('Parameter is invalid');
445444
}
446445

447446
// ensure this descriptor is valid
448447
try {
449448
this.validate();
450-
} catch (e) {
449+
} catch {
451450
throw new Error('Descriptor is invalid.');
452451
}
453452

@@ -564,6 +563,7 @@ class Range {
564563
* @param {ParameterType} parameterType - The parameter type to test.
565564
* @return {boolean} - True if parameterType is compatible; otherwise return false.
566565
*/
566+
// eslint-disable-next-line no-unused-vars
567567
isValidType(parameterType) {
568568
return false;
569569
}
@@ -699,6 +699,7 @@ class IntegerRange extends Range {
699699
* @param {any} value - The value to infer it's ParameterType
700700
* @returns {ParameterType} - The ParameterType that best scribes the value.
701701
*/
702+
// eslint-disable-next-line no-unused-vars
702703
function parameterTypeFromValue(value) {
703704
if (!value) return ParameterType.PARAMETER_NOT_SET;
704705
if (typeof value === 'boolean') return ParameterType.PARAMETER_BOOL;
@@ -775,8 +776,7 @@ function validValue(value, type) {
775776
case ParameterType.PARAMETER_INTEGER_ARRAY:
776777
case ParameterType.PARAMETER_DOUBLE_ARRAY:
777778
case ParameterType.PARAMETER_STRING_ARRAY:
778-
const values = value;
779-
result = _validArray(values, type);
779+
result = _validArray(value, type);
780780
break;
781781
default:
782782
result = false;

lib/parameter_service.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
'use strict';
1616

17-
const rclnodejs = require('bindings')('rclnodejs');
1817
const { Parameter, PARAMETER_SEPARATOR } = require('./parameter.js');
1918

2019
/**

lib/time_source.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
const rclnodejs = require('bindings')('rclnodejs');
1818
const { Clock, ROSClock } = require('./clock.js');
1919
const { ClockType } = Clock;
20-
const Node = require('./node.js');
2120
const { Parameter, ParameterType } = require('./parameter.js');
2221
const Time = require('./time.js');
2322

package.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,14 @@
4343
"url": "git+https://github.com/RobotWebTools/rclnodejs.git"
4444
},
4545
"devDependencies": {
46-
"@babel/eslint-parser": "^7.25.9",
47-
"@eslint/eslintrc": "^3.3.0",
48-
"@eslint/js": "^9.21.0",
49-
"@types/node": "^22.13.5",
46+
"@eslint/js": "^10.0.0",
47+
"@types/node": "^22.13.9",
5048
"@typescript-eslint/eslint-plugin": "^8.18.0",
5149
"@typescript-eslint/parser": "^8.18.0",
52-
"babel-eslint": "^10.1.0",
5350
"clang-format": "^1.8.0",
5451
"commander": "^13.1.0",
5552
"deep-equal": "^2.2.3",
5653
"eslint": "^9.16.0",
57-
"eslint-config-prettier": "^10.0.1",
5854
"eslint-plugin-prettier": "^5.2.1",
5955
"globals": "^16.0.0",
6056
"husky": "^9.1.7",

types/action_client.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable camelcase */
21
declare module 'rclnodejs' {
32
type ActionGoal<T> = T extends ActionTypeClassName
43
? InstanceType<ActionsMap[T]['Goal']>

0 commit comments

Comments
 (0)