Skip to content

Commit ba3b019

Browse files
author
Teo Koon Peng
authored
Add prettierrc (#744)
This adds a .prettierrc.yml file so that prettierrc config file outside the project will not get mistakenly loaded when it goes through husky/lint-staged. I also did a run of prettier and clang-format on the current files, feel free to revert the formatting commits if they are undesired. Most of the changes are just formatting, only .prettierrc.yml and package.json changes are relevalent. Fix #738
1 parent 1f06987 commit ba3b019

File tree

114 files changed

+1733
-1475
lines changed

Some content is hidden

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

114 files changed

+1733
-1475
lines changed

.eslintrc.yml

Lines changed: 14 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,24 @@
11
env:
22
node: true
33
es6: true
4-
54
globals:
65
every: true
76
after: true
87
constantly: true
9-
10-
ignorePatterns: ["generated/"]
11-
8+
ignorePatterns: ['generated/', 'types/interfaces.d.ts']
129
rules:
13-
camelcase: [2, {properties: "always"}]
14-
comma-dangle: 0
15-
comma-spacing: [2, {before: false, after: true}]
16-
comma-style: [2, "last"]
17-
handle-callback-err: [2, "^.*(e|E)rr" ]
18-
indent: ["error", 2, {"SwitchCase": 1}]
19-
key-spacing: [2, { beforeColon: false, afterColon: true }]
20-
max-depth: [1, 3]
21-
max-len: ["error", {"code": 120, "tabWidth": 2, "ignoreComments": true}]
22-
max-nested-callbacks: [1, 7]
23-
no-cond-assign: 2
24-
no-constant-condition: 2
25-
no-dupe-args: 2
26-
no-dupe-keys: 2
27-
no-else-return: 2
28-
no-empty: 2
29-
no-lonely-if: 2
30-
no-multiple-empty-lines: 2
31-
no-nested-ternary: 2
32-
no-self-compare: 2
33-
no-sync: 1
34-
no-throw-literal: 2
35-
no-underscore-dangle: 0
36-
quote-props: [2, "as-needed"]
37-
quotes: [2, "single", {"avoidEscape": true}]
38-
radix: 2
39-
semi-spacing: [2, {before: false, after: true}]
40-
semi: [2, "always"]
41-
keyword-spacing: [2, {before: true, after: true}]
42-
space-before-blocks: [2, "always"]
43-
space-before-function-paren: [0, "always"]
44-
space-in-parens: [2, "never"]
45-
spaced-comment: [1, "always"]
46-
strict: [2, "global"]
47-
valid-jsdoc: 2
48-
yoda: [2, "never"]
49-
50-
extends: [prettier]
51-
10+
prettier/prettier: 'error'
11+
extends: ['prettier']
12+
plugins: ['prettier']
5213
parserOptions:
5314
ecmaVersion: 2018
15+
overrides:
16+
- files: ['*.ts']
17+
parser: '@typescript-eslint/parser'
18+
plugins: ['@typescript-eslint']
19+
parserOptions: {
20+
sourceType: 'module'
21+
}
22+
rules: {
23+
strict: [0, 'global']
24+
}

.prettierrc.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
singleQuote: true,
3+
trailingComma: es5,
4+
}

benchmark/README.md

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ This folder contains code used to measure the performance between different ROS
88

99
You can download the latest binary package of ROS2 from [here](http://ci.ros2.org/view/packaging/) and follow the instructions to setup the environment.
1010

11-
* [Linux](https://github.com/ros2/ros2/wiki/Linux-Install-Binary)
12-
* [macOS](https://github.com/ros2/ros2/wiki/OSX-Install-Binary)
13-
* [Windows](https://github.com/ros2/ros2/wiki/Windows-Install-Binary)
11+
- [Linux](https://github.com/ros2/ros2/wiki/Linux-Install-Binary)
12+
- [macOS](https://github.com/ros2/ros2/wiki/OSX-Install-Binary)
13+
- [Windows](https://github.com/ros2/ros2/wiki/Windows-Install-Binary)
1414

15-
2.Install Node.js
15+
2.Install Node.js
1616

1717
Download the latest LTS edition from https://nodejs.org/en/
1818

@@ -22,23 +22,26 @@ Download the latest LTS edition from https://nodejs.org/en/
2222

2323
The table lists the directories for each kind of the ROS 2.0 clients.
2424

25-
Directory | Purpose |
26-
:----------:| ------------- |
27-
topic | Benchmarks for `publisher` and `subscription` features
28-
service | Benchmarks for `client` and `service` features
29-
startup | Benchamrks for measuring the startup time consumption
25+
| Directory | Purpose |
26+
| :-------: | ------------------------------------------------------ |
27+
| topic | Benchmarks for `publisher` and `subscription` features |
28+
| service | Benchmarks for `client` and `service` features |
29+
| startup | Benchamrks for measuring the startup time consumption |
3030

3131
## Run tests
3232

3333
1.Benchmark for [rclcpp](https://github.com/ros2/rclcpp)
34+
3435
- Compile the source files, `cd benchmark/rclcpp/` and run `colcon build`
3536
- The executable files locate at `build/rclcpp_benchmark/`
3637
- `your_benchamrk -h` for help.
3738

38-
2.Benchmark for [rclpy](https://github.com/ros2/rclpy)
39+
2.Benchmark for [rclpy](https://github.com/ros2/rclpy)
40+
3941
- Enter the Python scripts folder `benchmark/rclpy/`
4042
- `python3 your_benchamrk -h` for help.
4143

42-
3.Benchmark for rclnodejs
44+
3.Benchmark for rclnodejs
45+
4346
- Enter the Node.js scripts folder `benchmark/rclnodejs/`
4447
- `node your_benchamrk -h` for help.

benchmark/rclnodejs/service/client-stress-test.js

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -18,32 +18,39 @@
1818
const app = require('commander');
1919
const rclnodejs = require('../../../index.js');
2020

21-
app
22-
.option('-r, --run <n>', 'How many times to run')
23-
.parse(process.argv);
21+
app.option('-r, --run <n>', 'How many times to run').parse(process.argv);
2422

25-
rclnodejs.init().then(() => {
26-
const time = process.hrtime();
27-
const node = rclnodejs.createNode('stress_client_rclnodejs');
28-
const client = node.createClient('nav_msgs/srv/GetMap', 'get_map');
29-
let receivedTimes = 0;
30-
let totalTimes = app.run || 1;
31-
console.log('The client will send a GetMap request continuously' +
32-
` until receiving response ${totalTimes} times.`);
33-
let sendRequest = function() {
34-
client.sendRequest({}, (response) => {
35-
if (++receivedTimes > totalTimes) {
36-
rclnodejs.shutdown();
37-
const diff = process.hrtime(time);
38-
console.log(`Benchmark took ${diff[0]} seconds and ${Math.ceil(diff[1] / 1000000)} milliseconds.`);
39-
} else {
40-
setImmediate(sendRequest);
41-
}
42-
});
43-
};
23+
rclnodejs
24+
.init()
25+
.then(() => {
26+
const time = process.hrtime();
27+
const node = rclnodejs.createNode('stress_client_rclnodejs');
28+
const client = node.createClient('nav_msgs/srv/GetMap', 'get_map');
29+
let receivedTimes = 0;
30+
let totalTimes = app.run || 1;
31+
console.log(
32+
'The client will send a GetMap request continuously' +
33+
` until receiving response ${totalTimes} times.`
34+
);
35+
let sendRequest = function () {
36+
client.sendRequest({}, (response) => {
37+
if (++receivedTimes > totalTimes) {
38+
rclnodejs.shutdown();
39+
const diff = process.hrtime(time);
40+
console.log(
41+
`Benchmark took ${diff[0]} seconds and ${Math.ceil(
42+
diff[1] / 1000000
43+
)} milliseconds.`
44+
);
45+
} else {
46+
setImmediate(sendRequest);
47+
}
48+
});
49+
};
4450

45-
sendRequest();
46-
rclnodejs.spin(node);
47-
}).catch((e) => {
48-
console.log(`Error: ${e}`);
49-
});
51+
sendRequest();
52+
rclnodejs.spin(node);
53+
})
54+
.catch((e) => {
55+
console.log(`Error: ${e}`);
56+
});

benchmark/rclnodejs/service/service-stress-test.js

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@
1818
const app = require('commander');
1919
const rclnodejs = require('../../../index.js');
2020

21-
app
22-
.option('-s, --size [size_kb]', 'The block size')
23-
.parse(process.argv);
21+
app.option('-s, --size [size_kb]', 'The block size').parse(process.argv);
2422

2523
let size = app.size || 1;
2624
const mapData = {
@@ -30,7 +28,7 @@ const mapData = {
3028
sec: 123456,
3129
nanosec: 789,
3230
},
33-
frame_id: 'main_frame'
31+
frame_id: 'main_frame',
3432
},
3533
info: {
3634
map_load_time: {
@@ -44,26 +42,33 @@ const mapData = {
4442
position: {
4543
x: 0.0,
4644
y: 0.0,
47-
z: 0.0
45+
z: 0.0,
4846
},
4947
orientation: {
5048
x: 0.0,
5149
y: 0.0,
5250
z: 0.0,
53-
w: 0.0
54-
}
55-
}
51+
w: 0.0,
52+
},
53+
},
5654
},
57-
data: Int8Array.from({length: 1024 * size}, (v, k) => k)
58-
}
55+
data: Int8Array.from({ length: 1024 * size }, (v, k) => k),
56+
},
5957
};
6058

61-
rclnodejs.init().then(() => {
62-
let node = rclnodejs.createNode('stress_service_rclnodejs');
63-
node.createService('nav_msgs/srv/GetMap', 'get_map', (request, response) => {
64-
return mapData;
59+
rclnodejs
60+
.init()
61+
.then(() => {
62+
let node = rclnodejs.createNode('stress_service_rclnodejs');
63+
node.createService(
64+
'nav_msgs/srv/GetMap',
65+
'get_map',
66+
(request, response) => {
67+
return mapData;
68+
}
69+
);
70+
rclnodejs.spin(node);
71+
})
72+
.catch((e) => {
73+
console.log(`Error: ${e}`);
6574
});
66-
rclnodejs.spin(node);
67-
}).catch((e) => {
68-
console.log(`Error: ${e}`);
69-
});

benchmark/rclnodejs/topic/publisher-stress-test.js

Lines changed: 44 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -23,37 +23,49 @@ app
2323
.option('-r, --run <n>', 'How many times to run')
2424
.parse(process.argv);
2525

26-
rclnodejs.init().then(() => {
27-
const time = process.hrtime();
28-
let node = rclnodejs.createNode('stress_publisher_rclnodejs');
29-
const publisher = node.createPublisher('std_msgs/msg/UInt8MultiArray', 'stress_topic');
30-
let sentTimes = 0;
31-
let totalTimes = app.run || 1;
32-
let size = app.size || 1;
33-
const message = {
34-
layout: {
35-
dim: [
36-
{label: 'height', size: 10, stride: 600},
37-
{label: 'width', size: 20, stride: 60},
38-
{label: 'channel', size: 3, stride: 4},
39-
],
40-
data_offset: 0,
41-
},
42-
data: Uint8Array.from({length: 1024 * size}, (v, k) => k)
43-
};
44-
console.log(`The publisher will publish a UInt8MultiArray topic(contains a size of ${size}KB array)` +
45-
` ${totalTimes} times.`);
26+
rclnodejs
27+
.init()
28+
.then(() => {
29+
const time = process.hrtime();
30+
let node = rclnodejs.createNode('stress_publisher_rclnodejs');
31+
const publisher = node.createPublisher(
32+
'std_msgs/msg/UInt8MultiArray',
33+
'stress_topic'
34+
);
35+
let sentTimes = 0;
36+
let totalTimes = app.run || 1;
37+
let size = app.size || 1;
38+
const message = {
39+
layout: {
40+
dim: [
41+
{ label: 'height', size: 10, stride: 600 },
42+
{ label: 'width', size: 20, stride: 60 },
43+
{ label: 'channel', size: 3, stride: 4 },
44+
],
45+
data_offset: 0,
46+
},
47+
data: Uint8Array.from({ length: 1024 * size }, (v, k) => k),
48+
};
49+
console.log(
50+
`The publisher will publish a UInt8MultiArray topic(contains a size of ${size}KB array)` +
51+
` ${totalTimes} times.`
52+
);
4653

47-
setImmediate(() => {
48-
while (sentTimes++ < totalTimes) {
49-
publisher.publish(message);
50-
}
51-
rclnodejs.shutdown();
52-
const diff = process.hrtime(time);
53-
console.log(`Benchmark took ${diff[0]} seconds and ${Math.ceil(diff[1] / 1000000)} milliseconds.`);
54-
});
54+
setImmediate(() => {
55+
while (sentTimes++ < totalTimes) {
56+
publisher.publish(message);
57+
}
58+
rclnodejs.shutdown();
59+
const diff = process.hrtime(time);
60+
console.log(
61+
`Benchmark took ${diff[0]} seconds and ${Math.ceil(
62+
diff[1] / 1000000
63+
)} milliseconds.`
64+
);
65+
});
5566

56-
rclnodejs.spin(node);
57-
}).catch((err) => {
58-
console.log(err);
59-
});
67+
rclnodejs.spin(node);
68+
})
69+
.catch((err) => {
70+
console.log(err);
71+
});

benchmark/rclnodejs/topic/subscription-stress-test.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,17 @@
1616

1717
const rclnodejs = require('../../../index.js');
1818

19-
rclnodejs.init().then(() => {
20-
const node = rclnodejs.createNode('stress_subscription_rclnodejs');
21-
node.createSubscription('std_msgs/msg/UInt8MultiArray', 'stress_topic', (array) => {
19+
rclnodejs
20+
.init()
21+
.then(() => {
22+
const node = rclnodejs.createNode('stress_subscription_rclnodejs');
23+
node.createSubscription(
24+
'std_msgs/msg/UInt8MultiArray',
25+
'stress_topic',
26+
(array) => {}
27+
);
28+
rclnodejs.spin(node);
29+
})
30+
.catch((e) => {
31+
console.log(e);
2232
});
23-
rclnodejs.spin(node);
24-
}).catch(e => {
25-
console.log(e);
26-
});

example/action-client-cancel-example.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class FibonacciActionClient {
3737

3838
this._node.getLogger().info('Sending goal request...');
3939

40-
const goalHandle = await this._actionClient.sendGoal(goal, feedback =>
40+
const goalHandle = await this._actionClient.sendGoal(goal, (feedback) =>
4141
this.feedbackCallback(feedback)
4242
);
4343

@@ -87,6 +87,6 @@ rclnodejs
8787

8888
rclnodejs.spin(node);
8989
})
90-
.catch(err => {
90+
.catch((err) => {
9191
console.error(err);
9292
});

example/action-client-example.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class FibonacciActionClient {
3838

3939
this._node.getLogger().info('Sending goal request...');
4040

41-
const goalHandle = await this._actionClient.sendGoal(goal, feedback =>
41+
const goalHandle = await this._actionClient.sendGoal(goal, (feedback) =>
4242
this.feedbackCallback(feedback)
4343
);
4444

@@ -80,6 +80,6 @@ rclnodejs
8080

8181
rclnodejs.spin(node);
8282
})
83-
.catch(err => {
83+
.catch((err) => {
8484
console.error(err);
8585
});

0 commit comments

Comments
 (0)