Skip to content

Conversation

@minggangw
Copy link
Member

@minggangw minggangw commented Dec 27, 2024

rclnodejs leverages dot to generate the JavaScript classes, representing the ROS messages and wrapping the ref objects that can read/write from C++ pointer. For a long time, we changed the implementation along with new features introduced into ROS2, so it makes the template itself messy and hard to understand.

This patch tries to refactor the template to make it more readable and maintainable, including:

  1. Add proper indents for for/if used by the template to make it easy to understand.
  2. Abstract some functionalities into separate functions, like _setDefaults().
  3. Add more meaningful comments by {{/* */}}.
  4. Remove the consistency checking.

Besides, the following changes are made accordingly:

  1. Remove the willCheckConsistency usage from current JS files.
  2. Remove tests related to consistency checking in test-compound-msg-type-check.js and test-security-related.js.
  3. Use prettier to format the generated JavaScript files.
  4. Pump the generator version to 0.4.0.

Fix: #1015

@minggangw minggangw changed the title Refactor the message template [rosidl_gen] Refactor the dot used to generate the JavaScript messages Jan 13, 2025
@minggangw minggangw merged commit b70fb2c into RobotWebTools:develop Jan 14, 2025
5 checks passed
minggangw added a commit that referenced this pull request Jan 15, 2025
#1014)

`rclnodejs` leverages [`dot`](https://www.npmjs.com/package/dot) to generate the JavaScript classes, representing the ROS messages and wrapping the [`ref`](https://www.npmjs.com/package/@rclnodejs/ref-napi) objects that can read/write from C++ pointer. For a long time, we changed the implementation along with new features introduced into ROS2, so it makes the template itself messy and hard to understand.

This patch tries to refactor the template to make it more readable and maintainable, including:
1. Add proper indents for `for`/`if` used by the template to make it easy to understand.
2. Abstract some functionalities into separate functions, like `_setDefaults()`.
3. Add more meaningful comments by ```{{/*  */}}```.
4. Remove the consistency checking.

Besides, the following changes are made accordingly:
1. Remove the `willCheckConsistency` usage from current JS files.
2. Remove tests related to consistency checking in `test-compound-msg-type-check.js` and `test-security-related.js`.
3. Use `prettier` to format the generated JavaScript files.
4. Pump the generator version to `0.4.0`.

Fix: #1015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor the dot template

1 participant