Skip to content

Commit 1d8b40c

Browse files
authored
Re-enable cpplint & eslint for Linux platform actions (#1057)
This patch migrates `ESLint` configuration, `.eslintrc.yml` to [the new flat config format](https://eslint.org/docs/latest/use/configure/migration-guide) by creating `eslint.config.mjs`, meanwhile, re-enables [cpplint](https://github.com/cpplint/cpplint) for Linux platform actions, including: 1. Config `eslint` using recommended configs for `*.js` files in`eslint.config.mjs`. 2. Config `eslint-plugin-prettier` using recommended configs for `*.js` files in `eslint.config.mjs`. 3. Config `@typescript-eslint/eslint-plugin` using recommended configs for `*.d.ts` files in `eslint.config.mjs`. 4. Re-enable [`cpplint.py`](https://github.com/cpplint/cpplint/blob/develop/cpplint.py) for `*.{hpp,cpp}` files. 5. Fix errors/warnings reported by linters above. 6. Add `npm run lint` as addition step for actions, `.github/workflows/linux-build-and-test-compatibility.yml` and `.github/workflows/linux-build-and-test.yml`. 7. Remove original `.eslintrc.yml`. Fix: #1056
1 parent 120fcd0 commit 1d8b40c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+152
-242
lines changed

.eslintrc.yml

Lines changed: 0 additions & 25 deletions
This file was deleted.

.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

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,5 @@ jobs:
5050
run: |
5151
source /opt/ros/${{ needs.identify-ros-distro.outputs.distro }}/setup.bash
5252
npm i
53+
npm run lint
5354
npm test

eslint.config.mjs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import typescriptEslint from "@typescript-eslint/eslint-plugin";
2+
import prettier from "eslint-plugin-prettier";
3+
import globals from "globals";
4+
import tsParser from "@typescript-eslint/parser";
5+
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended';
6+
import js from "@eslint/js";
7+
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+
],
20+
},
21+
{
22+
...js.configs.recommended,
23+
files: ["lib/**/*.js", "index.js"],
24+
},
25+
{
26+
rules: {
27+
'no-dupe-class-members': 'off',
28+
},
29+
},
30+
{
31+
plugins: {
32+
"@typescript-eslint": typescriptEslint,
33+
},
34+
languageOptions: {
35+
globals: {
36+
...globals.node,
37+
},
38+
parser: tsParser,
39+
ecmaVersion: "latest",
40+
sourceType: "module",
41+
},
42+
files: ['types/*.d.ts'],
43+
rules: {
44+
...typescriptEslint.configs.recommended.rules,
45+
"@typescript-eslint/no-explicit-any": "off",
46+
},
47+
},
48+
{
49+
plugins: {
50+
prettier,
51+
},
52+
languageOptions: {
53+
globals: {
54+
...globals.node,
55+
},
56+
ecmaVersion: "latest",
57+
sourceType: "commonjs",
58+
},
59+
files: ["lib/**/*.js", "rosidl_parser/**/*.js", "rosidl_gen/**/*.js",
60+
"rostsd_gen/**/*.js", "test/**/*.js", "example/**/*.js", "index.js"],
61+
rules: {
62+
...eslintPluginPrettierRecommended.rules,
63+
},
64+
}
65+
];

example/publisher-content-filter-example.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414

1515
'use strict';
1616

17-
/* eslint-disable camelcase */
18-
1917
const rclnodejs = require('../index.js');
2018

2119
async function main() {

example/publisher-message-example.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414

1515
'use strict';
1616

17-
/* eslint-disable camelcase */
18-
1917
const rclnodejs = require('../index.js');
2018

2119
rclnodejs

example/publisher-multiarray-example.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414

1515
'use strict';
1616

17-
/* eslint-disable camelcase */
18-
1917
const rclnodejs = require('../index.js');
2018

2119
rclnodejs

example/publisher-raw-message.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414

1515
'use strict';
1616

17-
/* eslint-disable camelcase */
18-
1917
const rclnodejs = require('../index.js');
2018

2119
rclnodejs

example/subscription-multiarray-example.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ rclnodejs
3636
const weightStride = dim[1].stride;
3737
const channel = dim[2].size;
3838
const channelStride = dim[2].stride;
39-
// eslint-disable-next-line
39+
4040
const offset = multiArray.layout.data_offset;
4141

4242
for (let i = 0; i < height; i++) {

example/subscription-raw-message.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414

1515
'use strict';
1616

17-
/* eslint-disable camelcase */
18-
1917
const rclnodejs = require('../index.js');
2018

2119
rclnodejs.init().then(() => {

lib/action/client.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ class ActionClient extends Entity {
172172
goalHandle.status = status;
173173

174174
// Remove done handles from the list
175-
// eslint-disable-next-line max-depth
175+
176176
if (
177177
status === ActionInterfaces.GoalStatus.STATUS_SUCCEEDED ||
178178
status === ActionInterfaces.GoalStatus.STATUS_CANCELED ||

lib/clock_type.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414

1515
'use strict';
1616

17-
/* eslint-disable camelcase */
18-
1917
/**
2018
* Enum for ClockType
2119
* @readonly

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/interface_loader.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ let interfaceLoader = {
5959
// Suppose the name is a package, and traverse the path to collect the IDL files.
6060
let packagePath = path.join(generator.generatedRoot, name);
6161

62-
// eslint-disable-next-line
6362
let interfaces = fs.readdirSync(packagePath);
6463
if (interfaces.length > 0) {
6564
return this.loadInterfaceByPath(packagePath, interfaces);
@@ -108,7 +107,7 @@ let interfaceLoader = {
108107
packageName,
109108
packageName + '__' + type + '__' + messageName + '.js'
110109
);
111-
// eslint-disable-next-line
110+
112111
if (fs.existsSync(filePath)) {
113112
return require(filePath);
114113
}

lib/lifecycle.js

Lines changed: 0 additions & 5 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

@@ -603,7 +601,6 @@ class LifecycleNode extends Node {
603601
_onGetState(request, response) {
604602
let result = response.template;
605603

606-
// eslint-disable-next-line camelcase
607604
result.current_state = this.currentState;
608605

609606
response.send(result);
@@ -619,7 +616,6 @@ class LifecycleNode extends Node {
619616
_onGetAvailableStates(request, response) {
620617
let result = response.template;
621618

622-
// eslint-disable-next-line camelcase
623619
result.available_states = this.availableStates;
624620

625621
response.send(result);
@@ -634,7 +630,6 @@ class LifecycleNode extends Node {
634630
_onGetAvailableTransitions(request, response) {
635631
let result = response.template;
636632

637-
// eslint-disable-next-line camelcase
638633
result.available_transitions = this.availableTransitions;
639634

640635
response.send(result);

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 & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919

2020
'use strict';
2121

22-
/* eslint-disable camelcase */
23-
2422
const IsClose = require('is-close');
2523

2624
/**
@@ -273,7 +271,6 @@ class ParameterDescriptor {
273271
static fromParameter(parameter) {
274272
const name = parameter.name;
275273
const type = parameter.type;
276-
const value = parameter.value;
277274
return new ParameterDescriptor(name, type, 'Created from parameter.');
278275
}
279276

@@ -386,7 +383,7 @@ class ParameterDescriptor {
386383
return;
387384
}
388385
if (!(range instanceof Range)) {
389-
throw TypeException('Expected instance of Range.');
386+
throw TypeError('Expected instance of Range.');
390387
}
391388
if (!range.isValidType(this.type)) {
392389
throw TypeError('Incompatible Range');
@@ -442,14 +439,14 @@ class ParameterDescriptor {
442439
// ensure parameter is valid
443440
try {
444441
parameter.validate();
445-
} catch (e) {
442+
} catch {
446443
throw new TypeError('Parameter is invalid');
447444
}
448445

449446
// ensure this descriptor is valid
450447
try {
451448
this.validate();
452-
} catch (e) {
449+
} catch {
453450
throw new Error('Descriptor is invalid.');
454451
}
455452

@@ -566,6 +563,7 @@ class Range {
566563
* @param {ParameterType} parameterType - The parameter type to test.
567564
* @return {boolean} - True if parameterType is compatible; otherwise return false.
568565
*/
566+
// eslint-disable-next-line no-unused-vars
569567
isValidType(parameterType) {
570568
return false;
571569
}
@@ -701,6 +699,7 @@ class IntegerRange extends Range {
701699
* @param {any} value - The value to infer it's ParameterType
702700
* @returns {ParameterType} - The ParameterType that best scribes the value.
703701
*/
702+
// eslint-disable-next-line no-unused-vars
704703
function parameterTypeFromValue(value) {
705704
if (!value) return ParameterType.PARAMETER_NOT_SET;
706705
if (typeof value === 'boolean') return ParameterType.PARAMETER_BOOL;
@@ -777,8 +776,7 @@ function validValue(value, type) {
777776
case ParameterType.PARAMETER_INTEGER_ARRAY:
778777
case ParameterType.PARAMETER_DOUBLE_ARRAY:
779778
case ParameterType.PARAMETER_STRING_ARRAY:
780-
const values = value;
781-
result = _validArray(values, type);
779+
result = _validArray(value, type);
782780
break;
783781
default:
784782
result = false;

lib/parameter_service.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable max-depth */
21
// Copyright (c) 2020 Wayne Parrott. All rights reserved.
32
//
43
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -15,7 +14,6 @@
1514

1615
'use strict';
1716

18-
const rclnodejs = require('bindings')('rclnodejs');
1917
const { Parameter, PARAMETER_SEPARATOR } = require('./parameter.js');
2018

2119
/**

lib/qos.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414

1515
'use strict';
1616

17-
/* eslint-disable */
18-
1917
/**
2018
* Enum for HistoryPolicy
2119
* @readonly

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: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"postinstall": "npm run generate-messages",
2525
"docs": "cd docs && make",
2626
"test": "node --expose-gc ./scripts/run_test.js && npx tsd",
27-
"lint": "eslint --max-warnings=0 --ext js,ts index.js types scripts lib example rosidl_gen rosidl_parser test benchmark/rclnodejs && node ./scripts/cpplint.js",
27+
"lint": "eslint && node ./scripts/cpplint.js",
2828
"format": "clang-format -i -style=file ./src/*.cpp ./src/*.hpp && prettier --write \"{lib,rosidl_gen,rostsd_gen,rosidl_parser,types,example,test,scripts,benchmark}/**/*.{js,md,ts}\" ./*.{js,md,ts}",
2929
"prepare": "husky"
3030
},
@@ -43,17 +43,17 @@
4343
"url": "git+https://github.com/RobotWebTools/rclnodejs.git"
4444
},
4545
"devDependencies": {
46-
"@babel/eslint-parser": "^7.25.9",
47-
"@types/node": "^22.13.5",
46+
"@eslint/js": "^10.0.0",
47+
"@types/node": "^22.13.9",
4848
"@typescript-eslint/eslint-plugin": "^8.18.0",
4949
"@typescript-eslint/parser": "^8.18.0",
50-
"babel-eslint": "^10.1.0",
5150
"clang-format": "^1.8.0",
5251
"commander": "^13.1.0",
5352
"deep-equal": "^2.2.3",
5453
"eslint": "^9.16.0",
55-
"eslint-config-prettier": "^10.0.1",
54+
"eslint-config-prettier": "^10.0.2",
5655
"eslint-plugin-prettier": "^5.2.1",
56+
"globals": "^16.0.0",
5757
"husky": "^9.1.7",
5858
"jsdoc": "^4.0.4",
5959
"lint-staged": "^15.2.10",

rosidl_gen/action_msgs.js

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

1313
'use strict';
1414

15-
/* eslint-disable camelcase */
1615
const GOAL_ID_FIELD = {
1716
name: 'goal_id',
1817
type: {

rosidl_gen/filter.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ const RosPackageFilters = {
8787

8888
if (!fs.existsSync(blocklistPath)) return;
8989

90-
// eslint-disable-next-line
9190
let blocklistData = JSON.parse(fs.readFileSync(blocklistPath, 'utf8'));
9291

9392
let filters = blocklistData.map((pkgFilterData) => {

0 commit comments

Comments
 (0)