From e38e2a289e3c357ca9406728631d7b6150ff4e15 Mon Sep 17 00:00:00 2001 From: Minggang Wang Date: Fri, 21 Feb 2020 22:58:15 +0800 Subject: [PATCH] Format the existing js files Fix #None --- .eslintrc | 2 +- example/action-client-example.js | 6 +-- example/action-server-example.js | 10 ++-- example/publisher-qos-example.js | 4 +- example/subscription-multiarray-example.js | 3 +- example/subscription-qos-example.js | 4 +- example/timer-example.js | 4 +- example/validator-example.js | 2 +- lib/client.js | 8 ++-- lib/clock.js | 2 +- lib/interface_loader.js | 12 ++--- lib/logging.js | 9 ++-- lib/node.js | 28 +++++------ lib/publisher.js | 6 +-- lib/qos.js | 27 ++++++----- lib/time_source.js | 4 +- lib/timer.js | 6 +-- lib/validator.js | 8 ++-- package.json | 2 +- rosidl_gen/action_generator.js | 24 +++++----- rosidl_gen/idl_generator.js | 4 +- rosidl_gen/index.js | 3 +- rosidl_gen/message_translator.js | 54 +++++++++++----------- rosidl_gen/packages.js | 18 ++++---- rosidl_gen/primitive_types.js | 4 +- rostsd_gen/index.js | 49 ++++++++++---------- 26 files changed, 157 insertions(+), 146 deletions(-) diff --git a/.eslintrc b/.eslintrc index e6b01c63..11800e3c 100644 --- a/.eslintrc +++ b/.eslintrc @@ -13,7 +13,7 @@ rules: comma-spacing: [2, {before: false, after: true}] comma-style: [2, "last"] handle-callback-err: [2, "^.*(e|E)rr" ] - indent: [2, 2] + indent: ["error", 2, {"SwitchCase": 1, "ArrayExpression": "off", "ObjectExpression": "off"}] key-spacing: [2, { beforeColon: false, afterColon: true }] max-depth: [1, 3] max-len: ["error", {"code": 120, "tabWidth": 2, "ignoreComments": true}] diff --git a/example/action-client-example.js b/example/action-client-example.js index a36889ed..0a19dc46 100644 --- a/example/action-client-example.js +++ b/example/action-client-example.js @@ -27,7 +27,7 @@ rclnodejs.init().then(() => { rclnodejs: rclnodejs }); - let goal = ac.sendGoal({ goal: {dishwasher_id: 1}}); + let goal = ac.sendGoal({ goal: { dishwasher_id: 1 } }); console.log(`The goal was sent, the goal id is ${goal.goal_id.id}`); ac.on('feedback', (feedback) => { @@ -35,9 +35,9 @@ rclnodejs.init().then(() => { }); ac.on('status', (status) => { - status.status_list.forEach((s) =>{ + status.status_list.forEach((s) => { if (s.goal_id.id === goal.goal_id.id && - s.status === GoalStatus.SUCCEEDED) { + s.status === GoalStatus.SUCCEEDED) { console.log(`The goal, whose id is ${s.goal_id.id}, has been executed successfully.`); } }); diff --git a/example/action-server-example.js b/example/action-server-example.js index ee1bfb5a..a971fbdb 100644 --- a/example/action-server-example.js +++ b/example/action-server-example.js @@ -46,21 +46,23 @@ rclnodejs.init().then(() => { header: { stamp: { sec: 11223, - nanosec: 44556}, + nanosec: 44556 + }, frame_id: 'f001', }, height: 240, - width: 320, encoding: 'rgba', + width: 320, + encoding: 'rgba', is_bigendian: false, step: 320 * 16, is_dense: false, - data: Uint8Array.from({length: 320 * 240}, (v, k) => k), + data: Uint8Array.from({ length: 320 * 240 }, (v, k) => k), } }; goal.publishFeedback(feedback); setTimeout(() => { - goal.setSucceeded({total_dishes_cleaned: 10}, 'done'); + goal.setSucceeded({ total_dishes_cleaned: 10 }, 'done'); }, 500); }); diff --git a/example/publisher-qos-example.js b/example/publisher-qos-example.js index 98cffb3f..76a8eb40 100644 --- a/example/publisher-qos-example.js +++ b/example/publisher-qos-example.js @@ -15,7 +15,7 @@ 'use strict'; const rclnodejs = require('../index.js'); -const {QoS} = rclnodejs; +const { QoS } = rclnodejs; rclnodejs.init().then(() => { const node = rclnodejs.createNode('publisher_qos_example_node'); @@ -27,7 +27,7 @@ rclnodejs.init().then(() => { qos.depth = 1; qos.avoidRosNameSpaceConventions = false; - const publisher = node.createPublisher('std_msgs/msg/String', 'topic', {qos}); + const publisher = node.createPublisher('std_msgs/msg/String', 'topic', { qos }); let counter = 0; setInterval(function() { diff --git a/example/subscription-multiarray-example.js b/example/subscription-multiarray-example.js index 0c149be8..4fbbda4a 100644 --- a/example/subscription-multiarray-example.js +++ b/example/subscription-multiarray-example.js @@ -37,7 +37,8 @@ rclnodejs.init().then(() => { for (let i = 0; i < height; i++) { for (let j = 0; j < weight; j++) { for (let k = 0; k < channel; k++) { - console.log(`multiArray(${i},${j},${k}) = ${multiArray.data[offset + weightStride*i + channelStride*j + k]}`); + console.log( + `multiArray(${i},${j},${k}) = ${multiArray.data[offset + weightStride*i + channelStride*j + k]}`); } } } diff --git a/example/subscription-qos-example.js b/example/subscription-qos-example.js index 65da1ba5..04f2e366 100644 --- a/example/subscription-qos-example.js +++ b/example/subscription-qos-example.js @@ -15,12 +15,12 @@ 'use strict'; const rclnodejs = require('../index.js'); -const {QoS} = rclnodejs; +const { QoS } = rclnodejs; rclnodejs.init().then(() => { const node = rclnodejs.createNode('subscription_qos_example_node'); - node.createSubscription('std_msgs/msg/String', 'topic', {qos: QoS.profileSystemDefault}, + node.createSubscription('std_msgs/msg/String', 'topic', { qos: QoS.profileSystemDefault }, (msg) => { console.log(`Received message: ${typeof msg}`, msg); }); diff --git a/example/timer-example.js b/example/timer-example.js index 4d49f11b..3075c8ab 100644 --- a/example/timer-example.js +++ b/example/timer-example.js @@ -32,8 +32,8 @@ rclnodejs.init().then(() => { console.log('Reset the timer.'); timer.reset(); console.log('The next call will be ' + - timer.timeUntilNextCall() + - 'ms later.'); + timer.timeUntilNextCall() + + 'ms later.'); console.log('Shuting down...'); rclnodejs.shutdown(); diff --git a/example/validator-example.js b/example/validator-example.js index 2798e330..2c132980 100644 --- a/example/validator-example.js +++ b/example/validator-example.js @@ -15,7 +15,7 @@ 'use strict'; const rclnodejs = require('../index.js'); -const {validator} = rclnodejs; +const { validator } = rclnodejs; console.log('validation of topic "/node_name/chatter" is ' + validator.validateFullTopicName('/node_name/chatter')); console.log('validation of node "my_node" is ' + validator.validateNodeName('my_node')); diff --git a/lib/client.js b/lib/client.js index 76394a3f..7e33cb3c 100644 --- a/lib/client.js +++ b/lib/client.js @@ -49,10 +49,10 @@ class Client extends Entity { * @see {@link ResponseCallback} */ sendRequest(request, callback) { - let requestToSend = (request instanceof this._typeClass.Request) - ? request - : new this._typeClass.Request(request); - if (typeof (callback) !== 'function') { + let requestToSend = (request instanceof this._typeClass.Request) ? + request : + new this._typeClass.Request(request); + if (typeof(callback) !== 'function') { throw new TypeError('Invalid argument'); } diff --git a/lib/clock.js b/lib/clock.js index d184f4ed..171dae5a 100644 --- a/lib/clock.js +++ b/lib/clock.js @@ -103,4 +103,4 @@ class ROSClock extends Clock { Clock.ClockType = ClockType; -module.exports = {Clock, ROSClock}; +module.exports = { Clock, ROSClock }; diff --git a/lib/interface_loader.js b/lib/interface_loader.js index f8c6bef4..75f65f7c 100644 --- a/lib/interface_loader.js +++ b/lib/interface_loader.js @@ -29,14 +29,14 @@ let interfaceLoader = { // name: 'String', // } // - if (typeof obj !== 'object' || !obj || !obj.package || !obj.type|| !obj.name) { + if (typeof obj !== 'object' || !obj || !obj.package || !obj.type || !obj.name) { throw new TypeError('Should provide an object argument to get ROS message class'); } return this.loadInterface(obj.package, obj.type, obj.name); }, loadInterfaceByString(name) { - if (typeof (name) !== 'string') { + if (typeof(name) !== 'string') { throw new TypeError('Should provide a string argument to get ROS message class'); } @@ -66,12 +66,12 @@ let interfaceLoader = { let type = results[1]; let name = results[2]; let filePath = path.join(packagePath, file).normalize(); - interfaceInfos.push({name, type, filePath}); + interfaceInfos.push({ name, type, filePath }); }); - let pkg = {srv: {}, msg: {}}; + let pkg = { srv: {}, msg: {} }; interfaceInfos.forEach((info) => { - Object.defineProperty(pkg[info.type], info.name, {value: require(info.filePath)}); + Object.defineProperty(pkg[info.type], info.name, { value: require(info.filePath) }); }); return pkg; @@ -90,7 +90,7 @@ let interfaceLoader = { if (packageName && type && messageName) { let filePath = path.join( - generator.generatedRoot, packageName, packageName + '__' + type + '__' + messageName +'.js'); + generator.generatedRoot, packageName, packageName + '__' + type + '__' + messageName + '.js'); // eslint-disable-next-line if (fs.existsSync(filePath)) { return require(filePath); diff --git a/lib/logging.js b/lib/logging.js index 71800d9d..87a1edee 100644 --- a/lib/logging.js +++ b/lib/logging.js @@ -34,7 +34,8 @@ let LoggingSeverity = { /** @member {number} */ ERROR: 40, /** @member {number} */ - FATAL: 50}; + FATAL: 50 +}; class Caller { constructor() { @@ -79,7 +80,7 @@ class Logging { * @return {undefined} */ setLoggerLevel(level) { - if (typeof (level) !== 'number') { + if (typeof(level) !== 'number') { throw new TypeError('Invalid argument'); } rclnodejs.setLoggerLevel(this._name, level); @@ -145,7 +146,7 @@ class Logging { } _log(message, severity) { - if (typeof (message) !== 'string') { + if (typeof(message) !== 'string') { throw new TypeError('Invalid argument'); } @@ -178,7 +179,7 @@ class Logging { * @return {Logging} Return the logger object. */ static getLogger(name) { - if (typeof (name) !== 'string') { + if (typeof(name) !== 'string') { throw new TypeError('Invalid argument'); } return new Logging(name); diff --git a/lib/node.js b/lib/node.js index a6a82e72..c0dd2b9d 100644 --- a/lib/node.js +++ b/lib/node.js @@ -126,21 +126,21 @@ class Node { _validateOptions(options) { if (options !== undefined && - (options === null || typeof options !== 'object')) { + (options === null || typeof options !== 'object')) { throw new TypeError('Invalid argument of options'); } if (options === undefined) { - options = {enableTypedArray: true, qos: QoS.profileDefault}; + options = { enableTypedArray: true, qos: QoS.profileDefault }; return options; } if (options.enableTypedArray === undefined) { - options = Object.assign(options, {enableTypedArray: true}); + options = Object.assign(options, { enableTypedArray: true }); } if (options.qos === undefined) { - options = Object.assign(options, {qos: QoS.profileDefault}); + options = Object.assign(options, { qos: QoS.profileDefault }); } return options; } @@ -153,7 +153,7 @@ class Node { * @return {Timer} - An instance of Timer. */ createTimer(period, callback, context = Context.defaultContext()) { - if (typeof (period) !== 'number' || typeof (callback) !== 'function') { + if (typeof(period) !== 'number' || typeof(callback) !== 'function') { throw new TypeError('Invalid argument'); } @@ -186,12 +186,12 @@ class Node { * @return {Publisher} - An instance of Publisher. */ createPublisher(typeClass, topic, options) { - if (typeof (typeClass) === 'string' || typeof (typeClass) === 'object') { + if (typeof(typeClass) === 'string' || typeof(typeClass) === 'object') { typeClass = loader.loadInterface(typeClass); } options = this._validateOptions(options); - if (typeof (typeClass) !== 'function' || typeof (topic) !== 'string') { + if (typeof(typeClass) !== 'function' || typeof(topic) !== 'string') { throw new TypeError('Invalid argument'); } @@ -225,7 +225,7 @@ class Node { * @see {@link SubscriptionCallback} */ createSubscription(typeClass, topic, options, callback) { - if (typeof (typeClass) === 'string' || typeof (typeClass) === 'object') { + if (typeof(typeClass) === 'string' || typeof(typeClass) === 'object') { typeClass = loader.loadInterface(typeClass); } @@ -235,7 +235,7 @@ class Node { } options = this._validateOptions(options); - if (typeof (typeClass) !== 'function' || typeof (topic) !== 'string' || typeof (callback) !== 'function') { + if (typeof(typeClass) !== 'function' || typeof(topic) !== 'string' || typeof(callback) !== 'function') { throw new TypeError('Invalid argument'); } @@ -259,12 +259,12 @@ class Node { * @return {Client} - An instance of Client. */ createClient(typeClass, serviceName, options) { - if (typeof (typeClass) === 'string' || typeof (typeClass) === 'object') { + if (typeof(typeClass) === 'string' || typeof(typeClass) === 'object') { typeClass = loader.loadInterface(typeClass); } options = this._validateOptions(options); - if (typeof (typeClass) !== 'function' || typeof (serviceName) !== 'string') { + if (typeof(typeClass) !== 'function' || typeof(serviceName) !== 'string') { throw new TypeError('Invalid argument'); } @@ -304,7 +304,7 @@ class Node { * @see {@link RequestCallback} */ createService(typeClass, serviceName, options, callback) { - if (typeof (typeClass) === 'string' || typeof (typeClass) === 'object') { + if (typeof(typeClass) === 'string' || typeof(typeClass) === 'object') { typeClass = loader.loadInterface(typeClass); } @@ -314,7 +314,7 @@ class Node { } options = this._validateOptions(options); - if (typeof (typeClass) !== 'function' || typeof (serviceName) !== 'string' || typeof (callback) !== 'function') { + if (typeof(typeClass) !== 'function' || typeof(serviceName) !== 'string' || typeof(callback) !== 'function') { throw new TypeError('Invalid argument'); } @@ -332,7 +332,7 @@ class Node { * @return {GuardCondition} - An instance of GuardCondition. */ createGuardCondition(callback) { - if (typeof (callback) !== 'function') { + if (typeof(callback) !== 'function') { throw new TypeError('Invalid argument'); } diff --git a/lib/publisher.js b/lib/publisher.js index 8f8b46f9..cfd5d975 100644 --- a/lib/publisher.js +++ b/lib/publisher.js @@ -46,9 +46,9 @@ class Publisher extends Entity { // e.g. publisher.publish(3.14); // publisher.publish('The quick brown fox...'); // publisher.publish({linear: {x: 0, y: 1, z: 2}, ...}); - let messageToSend = (message instanceof this._typeClass) - ? message - : new this._typeClass(message); + let messageToSend = (message instanceof this._typeClass) ? + message : + new this._typeClass(message); let rawMessage = messageToSend.serialize(); rclnodejs.publish(this._handle, rawMessage); diff --git a/lib/qos.js b/lib/qos.js index 4d41eed2..c395201b 100644 --- a/lib/qos.js +++ b/lib/qos.js @@ -27,7 +27,8 @@ let HistoryPolicy = { /** @member {number} */ RMW_QOS_POLICY_HISTORY_KEEP_LAST: 1, /** @member {number} */ - RMW_QOS_POLICY_HISTORY_KEEP_ALL: 2}; + RMW_QOS_POLICY_HISTORY_KEEP_ALL: 2 +}; /** * Enum for ReliabilityPolicy @@ -40,7 +41,8 @@ let ReliabilityPolicy = { /** @member {number} */ RMW_QOS_POLICY_RELIABILITY_RELIABLE: 1, /** @member {number} */ - RMW_QOS_POLICY_RELIABILITY_BEST_EFFORT: 2}; + RMW_QOS_POLICY_RELIABILITY_BEST_EFFORT: 2 +}; /** * Enum for DurabilityPolicy @@ -53,7 +55,8 @@ let DurabilityPolicy = { /** @member {number} */ RMW_QOS_POLICY_DURABILITY_TRANSIENT_LOCAL: 1, /** @member {number} */ - RMW_QOS_POLICY_DURABILITY_VOLATILE: 2}; + RMW_QOS_POLICY_DURABILITY_VOLATILE: 2 +}; /** Class representing middleware quality of service */ class QoS { @@ -66,10 +69,10 @@ class QoS { * @param {boolean} [avoidRosNameSpaceConventions=false] - The avoidRosNameSpaceConventions value. */ constructor(history = HistoryPolicy.RMW_QOS_POLICY_HISTORY_SYSTEM_DEFAULT, - depth = 0, - reliability = ReliabilityPolicy.RMW_QOS_POLICY_RELIABILITY_SYSTEM_DEFAULT, - durability = DurabilityPolicy.RMW_QOS_POLICY_DURABILITY_SYSTEM_DEFAULT, - avoidRosNameSpaceConventions = false) { + depth = 0, + reliability = ReliabilityPolicy.RMW_QOS_POLICY_RELIABILITY_SYSTEM_DEFAULT, + durability = DurabilityPolicy.RMW_QOS_POLICY_DURABILITY_SYSTEM_DEFAULT, + avoidRosNameSpaceConventions = false) { this._history = history; this._depth = depth; this._reliability = reliability; @@ -125,7 +128,7 @@ class QoS { * @return {undefined} */ set history(history) { - if (typeof (history) !== 'number') { + if (typeof(history) !== 'number') { throw new TypeError('Invalid argument'); } @@ -150,7 +153,7 @@ class QoS { * @return {undefined} */ set depth(depth) { - if (typeof (depth) !== 'number') { + if (typeof(depth) !== 'number') { throw new TypeError('Invalid argument'); } @@ -175,7 +178,7 @@ class QoS { * @return {undefined} */ set reliability(reliability) { - if (typeof (reliability) !== 'number') { + if (typeof(reliability) !== 'number') { throw new TypeError('Invalid argument'); } @@ -200,7 +203,7 @@ class QoS { * @return {undefined} */ set durability(durability) { - if (typeof (durability) !== 'number') { + if (typeof(durability) !== 'number') { throw new TypeError('Invalid argument'); } @@ -225,7 +228,7 @@ class QoS { * @return {undefined} */ set avoidRosNameSpaceConventions(avoidRosNameSpaceConventions) { - if (typeof (avoidRosNameSpaceConventions) !== 'boolean') { + if (typeof(avoidRosNameSpaceConventions) !== 'boolean') { throw new TypeError('Invalid argument'); } diff --git a/lib/time_source.js b/lib/time_source.js index a17d4e0c..1dd4c981 100644 --- a/lib/time_source.js +++ b/lib/time_source.js @@ -15,8 +15,8 @@ 'use strict'; const rclnodejs = require('bindings')('rclnodejs'); -const {Clock, ROSClock} = require('./clock.js'); -const {ClockType} = Clock; +const { Clock, ROSClock } = require('./clock.js'); +const { ClockType } = Clock; const Node = require('./node.js'); const Time = require('./time.js'); diff --git a/lib/timer.js b/lib/timer.js index 5bad4fdb..1e22a8b8 100644 --- a/lib/timer.js +++ b/lib/timer.js @@ -17,9 +17,9 @@ const rclnodejs = require('bindings')('rclnodejs'); /** - * @class - Class representing a Timer in ROS - * @hideconstructor - */ + * @class - Class representing a Timer in ROS + * @hideconstructor + */ class Timer { constructor(handle, period, callback) { diff --git a/lib/validator.js b/lib/validator.js index 0b0fa6dd..52ddf2c0 100644 --- a/lib/validator.js +++ b/lib/validator.js @@ -33,7 +33,7 @@ let validator = { * @return {boolean} - True if it is valid. */ validateFullTopicName(topic) { - if (typeof (topic) !== 'string') { + if (typeof(topic) !== 'string') { throw new TypeError('Invalid argument'); } @@ -50,7 +50,7 @@ let validator = { * @return {boolean} - True if it is valid. */ validateNodeName(name) { - if (typeof (name) !== 'string') { + if (typeof(name) !== 'string') { throw new TypeError('Invalid argument'); } @@ -67,7 +67,7 @@ let validator = { * @return {boolean} - True if it is valid. */ validateTopicName(topic) { - if (typeof (topic) !== 'string') { + if (typeof(topic) !== 'string') { throw new TypeError('Invalid argument'); } @@ -84,7 +84,7 @@ let validator = { * @return {boolean} - True if it is valid. */ validateNamespace(namespace) { - if (typeof (namespace) !== 'string') { + if (typeof(namespace) !== 'string') { throw new TypeError('Invalid argument'); } diff --git a/package.json b/package.json index 99487132..70c1289c 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "test": "node ./scripts/compile_tests.js && node ./scripts/run_test.js && dtslint test/types", "lint": "eslint --max-warnings=0 index.js types/*.d.ts scripts lib example rosidl_gen rosidl_parser test benchmark/rclnodejs && node ./scripts/cpplint.js", "postinstall": "node scripts/generate_messages.js", - "format": "js-beautify --config jsbeautifyrc -r lib/*.js rostsd_gen/*.js rosidl_gen/*.js rosidl_parser/*.js test/*.js example/*.js" + "format": "js-beautify --config jsbeautifyrc -r lib/*.js rostsd_gen/*.js rosidl_gen/*.js rosidl_parser/*.js" }, "authors": [ "Minggang Wang ", diff --git a/rosidl_gen/action_generator.js b/rosidl_gen/action_generator.js index 7be503db..8e11504b 100644 --- a/rosidl_gen/action_generator.js +++ b/rosidl_gen/action_generator.js @@ -20,7 +20,7 @@ const path = require('path'); dot.templateSettings.strip = false; dot.log = process.env.RCLNODEJS_LOG_VERBOSE || false; -const dots = dot.process({path: path.join(__dirname, '../rosidl_gen/templates')}); +const dots = dot.process({ path: path.join(__dirname, '../rosidl_gen/templates') }); async function generateIDLFromAction(action) { const header = '# This file is automatically generated by rosidl-generator\n'; @@ -57,7 +57,7 @@ async function generateIDLFromAction(action) { msgFiles: generatedInterfaces, dependencies: extractDependencies(data) }); - let packageFile = dots.package({projectName: action.pkgName}); + let packageFile = dots.package({ projectName: action.pkgName }); await fse.writeFile(path.join(path.parse(action.filePath).dir, 'CMakeLists.txt'), cmakeFile, @@ -65,7 +65,7 @@ async function generateIDLFromAction(action) { await fse.writeFile(path.join(path.parse(action.filePath).dir, 'package.xml'), packageFile, 'utf8'); - return {generatedInterfaces, dir}; + return { generatedInterfaces, dir }; } function extractDependencies(file) { @@ -82,31 +82,31 @@ function extractDependencies(file) { function extractMessageSectionsFromAction(file) { let [goal, result, feedback] = file.split('---').map((line) => line.trim()); - return {goal, result, feedback}; + return { goal, result, feedback }; } function generateActionMessage(action) { return `${action.interfaceName}ActionGoal action_goal\n` + - `${action.interfaceName}ActionResult action_result\n` + - `${action.interfaceName}ActionFeedback action_feedback`; + `${action.interfaceName}ActionResult action_result\n` + + `${action.interfaceName}ActionFeedback action_feedback`; } function generateActionFeedbackMessage(action) { return 'std_msgs/Header header\n' + - 'actionlib_msgs/GoalStatus status\n' + - `${action.interfaceName}Feedback feedback`; + 'actionlib_msgs/GoalStatus status\n' + + `${action.interfaceName}Feedback feedback`; } function generateActionGoalMessage(action) { return 'std_msgs/Header header\n' + - 'actionlib_msgs/GoalID goal_id\n' + - `${action.interfaceName}Goal goal`; + 'actionlib_msgs/GoalID goal_id\n' + + `${action.interfaceName}Goal goal`; } function generateActionResultMessage(action) { return 'std_msgs/Header header\n' + - 'actionlib_msgs/GoalStatus status\n' + - `${action.interfaceName}Result result`; + 'actionlib_msgs/GoalStatus status\n' + + `${action.interfaceName}Result result`; } module.exports = generateIDLFromAction; diff --git a/rosidl_gen/idl_generator.js b/rosidl_gen/idl_generator.js index 2a78d25d..128a5453 100644 --- a/rosidl_gen/idl_generator.js +++ b/rosidl_gen/idl_generator.js @@ -21,7 +21,7 @@ const parser = require('../rosidl_parser/rosidl_parser.js'); dot.templateSettings.strip = false; dot.log = process.env.RCLNODEJS_LOG_VERBOSE || false; -const dots = dot.process({path: path.join(__dirname, '../rosidl_gen/templates')}); +const dots = dot.process({ path: path.join(__dirname, '../rosidl_gen/templates') }); function removeExtraSpaceLines(str) { return str.replace(/^\s*\n/gm, ''); @@ -35,7 +35,7 @@ async function writeGeneratedCode(dir, fileName, code) { function generateServiceJSStruct(serviceInfo, dir) { dir = path.join(dir, `${serviceInfo.pkgName}`); const fileName = serviceInfo.pkgName + '__' + serviceInfo.subFolder + '__' + serviceInfo.interfaceName + '.js'; - const generatedCode = removeExtraSpaceLines(dots.service({serviceInfo: serviceInfo})); + const generatedCode = removeExtraSpaceLines(dots.service({ serviceInfo: serviceInfo })); return writeGeneratedCode(dir, fileName, generatedCode); } diff --git a/rosidl_gen/index.js b/rosidl_gen/index.js index d30883c1..129121bf 100644 --- a/rosidl_gen/index.js +++ b/rosidl_gen/index.js @@ -38,7 +38,8 @@ async function generateJSStructFromAction(pkg) { pkgName: pkg.pkgName, interfaceName, subFolder: 'msg', - filePath: path.join(idl.dir, interfaceName + '.msg')}); + filePath: path.join(idl.dir, interfaceName + '.msg') + }); }); }); diff --git a/rosidl_gen/message_translator.js b/rosidl_gen/message_translator.js index 9831a984..0112ea07 100644 --- a/rosidl_gen/message_translator.js +++ b/rosidl_gen/message_translator.js @@ -77,30 +77,30 @@ function verifyMessage(message, obj) { if (def.fields[i].type.isPrimitiveType) { // check type/existence switch (def.fields[i].type) { - case 'char': - case 'int16': - case 'int32': - case 'int64': - case 'byte': - case 'uint16': - case 'uint32': - case 'uint64': - case 'float32': - case 'float64': - if (typeof obj[name] != 'number') { - return false; - } - break; - case 'bool': - if (typeof obj[name] != 'boolean') { - return false; - } - break; - case 'string': - if (typeof obj[name] != 'string') { - return false; - } - break; + case 'char': + case 'int16': + case 'int32': + case 'int64': + case 'byte': + case 'uint16': + case 'uint32': + case 'uint64': + case 'float32': + case 'float64': + if (typeof obj[name] != 'number') { + return false; + } + break; + case 'bool': + if (typeof obj[name] != 'boolean') { + return false; + } + break; + case 'string': + if (typeof obj[name] != 'string') { + return false; + } + break; } } else if (!verifyMessage(message[name], obj[name])) { // Proceed further on this member @@ -126,7 +126,7 @@ function toPlainObject(message, enableTypedArray = true) { // Note: there won't be any JavaScript array in message let array = []; message.data.forEach((e) => { - array.push(toPlainObject(e, enableTypedArray)); // Translate every elements + array.push(toPlainObject(e, enableTypedArray)); // Translate every elements }); return array; // eslint-disable-next-line no-else-return @@ -138,8 +138,8 @@ function toPlainObject(message, enableTypedArray = true) { const name = def.fields[i].name; if (def.fields[i].type.isPrimitiveType) { if (def.fields[i].type.isArray && - message._wrapperFields[name].constructor.useTypedArray && - !enableTypedArray) { + message._wrapperFields[name].constructor.useTypedArray && + !enableTypedArray) { obj[name] = Array.from(message[name]); } else { // Direct assignment diff --git a/rosidl_gen/packages.js b/rosidl_gen/packages.js index c32abd4d..e3f59020 100644 --- a/rosidl_gen/packages.js +++ b/rosidl_gen/packages.js @@ -36,9 +36,9 @@ function getPackageName(filePath, amentExecuted) { // If |packageName| equals to the file's extension, e.g. msg/srv, one level // up directory will be used as the package name. - return packageName === path.parse(filePath).ext.substr(1) - ? folders.pop() - : packageName; + return packageName === path.parse(filePath).ext.substr(1) ? + folders.pop() : + packageName; }; function getSubFolder(filePath, amentExecuted) { @@ -58,13 +58,13 @@ function grabInterfaceInfo(filePath, amentExecuted) { let pkgName = getPackageName(filePath, amentExecuted); let interfaceName = path.parse(filePath).name; let subFolder = getSubFolder(filePath, amentExecuted); - return {pkgName, interfaceName, subFolder, filePath}; + return { pkgName, interfaceName, subFolder, filePath }; } function addInterfaceInfo(info, type, pkgMap) { let pkgName = info.pkgName; if (!pkgMap.has(pkgName)) { - pkgMap.set(pkgName, {messages: [], services: [], actions: [], pkgName}); + pkgMap.set(pkgName, { messages: [], services: [], actions: [], pkgName }); } let pkg = pkgMap.get(pkgName); pkg[type].push(info); @@ -82,17 +82,19 @@ function findPackagesInDirectory(dir) { } dir = amentExecuted ? path.join(dir, 'share') : dir; - let walker = walk.walk(dir, {followLinks: true}); + let walker = walk.walk(dir, { followLinks: true }); let pkgMap = new Map(); walker.on('file', (root, file, next) => { if (path.extname(file.name) === '.msg') { // Some .msg files were generated prior to 0.3.2 for .action files, // which has been disabled. So these files should be ignored here. if (path.dirname(root).split(path.sep).pop() !== 'action') { - addInterfaceInfo(grabInterfaceInfo(path.join(root, file.name), amentExecuted), 'messages', pkgMap); + addInterfaceInfo(grabInterfaceInfo(path.join(root, file.name), amentExecuted), 'messages', + pkgMap); } } else if (path.extname(file.name) === '.srv') { - addInterfaceInfo(grabInterfaceInfo(path.join(root, file.name), amentExecuted), 'services', pkgMap); + addInterfaceInfo(grabInterfaceInfo(path.join(root, file.name), amentExecuted), 'services', + pkgMap); } next(); }); diff --git a/rosidl_gen/primitive_types.js b/rosidl_gen/primitive_types.js index b3874c6e..a7f8c6cf 100644 --- a/rosidl_gen/primitive_types.js +++ b/rosidl_gen/primitive_types.js @@ -28,12 +28,12 @@ const StringRefStruct = StructType({ function initString(str, own = false) { if (own) { - if (! str instanceof Buffer) { + if (!str instanceof Buffer) { throw new TypeError('Invalid argument: should provide a Node Buffer to bindingsStringInit()'); } rclnodejs.initString(str); } else { - if (! str instanceof StringRefStruct) { + if (!str instanceof StringRefStruct) { throw new TypeError('Invalid argument: should provide a type of StringRefStruct'); } diff --git a/rostsd_gen/index.js b/rostsd_gen/index.js index 8f9c7e5a..120b61f7 100644 --- a/rostsd_gen/index.js +++ b/rostsd_gen/index.js @@ -169,7 +169,8 @@ function savePkgInfoAsTSD(pkgInfos, fd) { fs.writeSync(fd, ` '${key}': ${messagesMap[key]}_WrapperType,\n`); } fs.writeSync(fd, ' };\n'); - fs.writeSync(fd, ' type MessageWrapperType = T extends MessageTypeClassName ? MessageTypeClassWrappersMap[T] : object;\n\n'); + fs.writeSync(fd, + ' type MessageWrapperType = T extends MessageTypeClassName ? MessageTypeClassWrappersMap[T] : object;\n\n'); // write service type class string const services = []; @@ -225,7 +226,7 @@ function saveMsgWrapperAsTSD(msgInfo, fd) { * non-primitive types * @returns {undefined} */ -function saveMsgFieldsAsTSD(msgInfo, fd, indent=0, lineEnd=',', typePrefix='') { +function saveMsgFieldsAsTSD(msgInfo, fd, indent = 0, lineEnd = ',', typePrefix = '') { const indentStr = ' '.repeat(indent); for (let i = 0; i < msgInfo.def.fields.length; i++) { const field = msgInfo.def.fields[i]; @@ -272,28 +273,28 @@ function primitiveType2JSName(type) { let jsName; switch (type) { - case 'char': - case 'byte': - case 'uint8': - case 'int8': - case 'int16': - case 'uint16': - case 'int32': - case 'uint32': - case 'int64': - case 'uint64': - case 'float32': - case 'float64': - case 'double': - jsName = 'number'; - break; - case 'bool': - jsName = 'boolean'; - break; - case 'string': - case 'wstring': - jsName = 'string'; - break; + case 'char': + case 'byte': + case 'uint8': + case 'int8': + case 'int16': + case 'uint16': + case 'int32': + case 'uint32': + case 'int64': + case 'uint64': + case 'float32': + case 'float64': + case 'double': + jsName = 'number'; + break; + case 'bool': + jsName = 'boolean'; + break; + case 'string': + case 'wstring': + jsName = 'string'; + break; } return jsName;