Skip to content

Commit

Permalink
Format the existing js files
Browse files Browse the repository at this point in the history
Fix #None
  • Loading branch information
Minggang Wang committed Feb 22, 2020
1 parent e009304 commit e38e2a2
Show file tree
Hide file tree
Showing 26 changed files with 157 additions and 146 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -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}]
Expand Down
6 changes: 3 additions & 3 deletions example/action-client-example.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ 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) => {
console.log(`${feedback.percent_complete}% of the task has been completed.`);
});

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.`);
}
});
Expand Down
10 changes: 6 additions & 4 deletions example/action-server-example.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand Down
4 changes: 2 additions & 2 deletions example/publisher-qos-example.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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() {
Expand Down
3 changes: 2 additions & 1 deletion example/subscription-multiarray-example.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]}`);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions example/subscription-qos-example.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
4 changes: 2 additions & 2 deletions example/timer-example.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion example/validator-example.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
8 changes: 4 additions & 4 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand Down
2 changes: 1 addition & 1 deletion lib/clock.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,4 @@ class ROSClock extends Clock {

Clock.ClockType = ClockType;

module.exports = {Clock, ROSClock};
module.exports = { Clock, ROSClock };
12 changes: 6 additions & 6 deletions lib/interface_loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down
9 changes: 5 additions & 4 deletions lib/logging.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ let LoggingSeverity = {
/** @member {number} */
ERROR: 40,
/** @member {number} */
FATAL: 50};
FATAL: 50
};

class Caller {
constructor() {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -145,7 +146,7 @@ class Logging {
}

_log(message, severity) {
if (typeof (message) !== 'string') {
if (typeof(message) !== 'string') {
throw new TypeError('Invalid argument');
}

Expand Down Expand Up @@ -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);
Expand Down
28 changes: 14 additions & 14 deletions lib/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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');
}

Expand Down Expand Up @@ -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');
}

Expand Down Expand Up @@ -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);
}

Expand All @@ -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');
}

Expand All @@ -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');
}

Expand Down Expand Up @@ -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);
}

Expand All @@ -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');
}

Expand All @@ -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');
}

Expand Down
6 changes: 3 additions & 3 deletions lib/publisher.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading

0 comments on commit e38e2a2

Please sign in to comment.