From bce90f0796850259ec1eefe7e43ada8003838d64 Mon Sep 17 00:00:00 2001 From: Ezra Brooks Date: Tue, 20 Feb 2024 08:22:31 -0700 Subject: [PATCH 1/7] extend eslint config to tests/misc. JS files --- eslint.config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eslint.config.js b/eslint.config.js index 9f6fbf88a..ba6cdfff8 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -30,6 +30,6 @@ module.exports = [ 'no-proto': 2, 'linebreak-style': 2 }, - files: ['Gruntfile.js', 'src/**/*.js'] + files: ['**/*.{js,jsx,cjs}'] } ]; From 10a6949c9c50327463afe6f315c1c735ce4bfede Mon Sep 17 00:00:00 2001 From: Ezra Brooks Date: Tue, 20 Feb 2024 08:23:40 -0700 Subject: [PATCH 2/7] run eslint --fix --- eslint.config.js | 6 +++--- examples/node_simple.js | 2 +- test/examples/check-topics.example.js | 4 ++-- test/examples/fibonacci.example.js | 2 +- test/examples/params.examples.js | 2 +- test/examples/pubsub.example.js | 12 ++++++------ test/examples/tf.example.js | 2 +- test/examples/tf_service.example.js | 2 +- test/math-examples.test.js | 2 +- test/quaternion.test.js | 2 +- test/tfclient.test.js | 2 +- test/transform.test.js | 2 +- vitest.config.js | 2 +- 13 files changed, 21 insertions(+), 21 deletions(-) diff --git a/eslint.config.js b/eslint.config.js index ba6cdfff8..035cdb05e 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -1,12 +1,12 @@ -const globals = require("globals"); +const globals = require('globals'); module.exports = [ { languageOptions: { - "globals": { + 'globals': { ...globals.browser, ...globals.node, - "bson": true + 'bson': true }, } }, diff --git a/examples/node_simple.js b/examples/node_simple.js index 8a9ea80e7..340216dc6 100644 --- a/examples/node_simple.js +++ b/examples/node_simple.js @@ -41,5 +41,5 @@ angular : { } }); -console.log("Publishing cmd_vel"); +console.log('Publishing cmd_vel'); cmdVel.publish(twist); diff --git a/test/examples/check-topics.example.js b/test/examples/check-topics.example.js index a84ccb8de..2164d9cd1 100644 --- a/test/examples/check-topics.example.js +++ b/test/examples/check-topics.example.js @@ -1,4 +1,4 @@ -import { describe, it, expect } from "vitest"; +import { describe, it, expect } from 'vitest'; var ROSLIB = require('../..'); var expectedTopics = [ @@ -45,7 +45,7 @@ describe('Example topics are live', function() { })); it('unadvertise will end the topic (if it\s the last around)', () => new Promise((done) => { - console.log("Unadvertisement test. Wait for 15 seconds.."); + console.log('Unadvertisement test. Wait for 15 seconds..'); setTimeout(function() { ros.getTopics(function(result) { expect(result.topics).not.to.contain('/some_test_topic'); diff --git a/test/examples/fibonacci.example.js b/test/examples/fibonacci.example.js index 2d2109d56..a247813bd 100644 --- a/test/examples/fibonacci.example.js +++ b/test/examples/fibonacci.example.js @@ -1,4 +1,4 @@ -import { describe, it, expect } from "vitest"; +import { describe, it, expect } from 'vitest'; var ROSLIB = require('../..'); describe('Fibonacci Example', function() { diff --git a/test/examples/params.examples.js b/test/examples/params.examples.js index a150429af..561dea889 100644 --- a/test/examples/params.examples.js +++ b/test/examples/params.examples.js @@ -1,4 +1,4 @@ -import { describe, it, expect } from "vitest"; +import { describe, it, expect } from 'vitest'; var ROSLIB = require('../..'); describe('Param setting', function() { diff --git a/test/examples/pubsub.example.js b/test/examples/pubsub.example.js index 35b806e68..58960a029 100644 --- a/test/examples/pubsub.example.js +++ b/test/examples/pubsub.example.js @@ -28,18 +28,18 @@ describe('Topics Example', function() { var topic1msg = messages1[0], topic2msg = {}; example.subscribe(function(message) { - if (message.data === topic1msg.data) return; + if (message.data === topic1msg.data) {return;} topic1msg = messages1[0]; expect(message).to.be.eql(messages2.shift()); - if (messages1.length) example.publish(topic1msg); - else done(); + if (messages1.length) {example.publish(topic1msg);} + else {done();} }); example2.subscribe(function(message) { - if (message.data === topic2msg.data) return; + if (message.data === topic2msg.data) {return;} topic2msg = messages2[0]; expect(message).to.be.eql(messages1.shift()); - if (messages2.length) example2.publish(topic2msg); - else done(); + if (messages2.length) {example2.publish(topic2msg);} + else {done();} }); example.publish(topic1msg); })); diff --git a/test/examples/tf.example.js b/test/examples/tf.example.js index 9c6f0a88f..8353f3013 100644 --- a/test/examples/tf.example.js +++ b/test/examples/tf.example.js @@ -1,4 +1,4 @@ -import { describe, it, expect } from "vitest"; +import { describe, it, expect } from 'vitest'; var ROSLIB = require('../..'); describe('TF2 Republisher Example', function() { diff --git a/test/examples/tf_service.example.js b/test/examples/tf_service.example.js index e5555fbd0..98cd04410 100644 --- a/test/examples/tf_service.example.js +++ b/test/examples/tf_service.example.js @@ -1,4 +1,4 @@ -import { describe, it, expect } from "vitest"; +import { describe, it, expect } from 'vitest'; var ROSLIB = require('../..'); describe('TF2 Republisher Service Example', function() { diff --git a/test/math-examples.test.js b/test/math-examples.test.js index 639729648..6c3ed8326 100644 --- a/test/math-examples.test.js +++ b/test/math-examples.test.js @@ -5,7 +5,7 @@ function clone(x) { var y = {}; for (var prop in x) { if (x.hasOwnProperty(prop)) { - y[prop] = typeof x[prop] === "object" ? clone(x[prop]) : x[prop]; + y[prop] = typeof x[prop] === 'object' ? clone(x[prop]) : x[prop]; } } return y; diff --git a/test/quaternion.test.js b/test/quaternion.test.js index 90f38e8f7..d06aa06be 100644 --- a/test/quaternion.test.js +++ b/test/quaternion.test.js @@ -1,4 +1,4 @@ -import { describe, it, expect } from "vitest"; +import { describe, it, expect } from 'vitest'; var ROSLIB = require('..'); diff --git a/test/tfclient.test.js b/test/tfclient.test.js index 6456feff2..322fccba1 100644 --- a/test/tfclient.test.js +++ b/test/tfclient.test.js @@ -1,4 +1,4 @@ -import { describe, it, expect } from "vitest"; +import { describe, it, expect } from 'vitest'; var ROSLIB = require('..'); describe('TFClient', function() { diff --git a/test/transform.test.js b/test/transform.test.js index ccb8b71d3..975d8f799 100644 --- a/test/transform.test.js +++ b/test/transform.test.js @@ -1,4 +1,4 @@ -import { describe, it, expect } from "vitest"; +import { describe, it, expect } from 'vitest'; var ROSLIB = require('..'); describe('Transform', function() { diff --git a/vitest.config.js b/vitest.config.js index 64e146e07..7e6dad78d 100644 --- a/vitest.config.js +++ b/vitest.config.js @@ -1,4 +1,4 @@ -import {defineConfig} from "vitest/config"; +import {defineConfig} from 'vitest/config'; export default defineConfig({ test: { From 97ac1f1ade402d7a24622a13d39b729bea7b19e7 Mon Sep 17 00:00:00 2001 From: Ezra Brooks Date: Tue, 20 Feb 2024 08:25:45 -0700 Subject: [PATCH 3/7] Add jsx support --- eslint.config.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/eslint.config.js b/eslint.config.js index 035cdb05e..4bc395f3e 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -8,6 +8,11 @@ module.exports = [ ...globals.node, 'bson': true }, + 'parserOptions': { + 'ecmaFeatures': { + 'jsx': true + } + } } }, { From 5147de83292cb295233f568afa29b07ff3c2bd03 Mon Sep 17 00:00:00 2001 From: Ezra Brooks Date: Tue, 20 Feb 2024 08:25:53 -0700 Subject: [PATCH 4/7] eslint --fix again --- examples/react-example/src/App.jsx | 4 +-- examples/react-example/src/App.test.jsx | 4 +-- .../component_examples/example_functions.jsx | 26 +++++++++---------- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/examples/react-example/src/App.jsx b/examples/react-example/src/App.jsx index 09e3a5619..add819341 100644 --- a/examples/react-example/src/App.jsx +++ b/examples/react-example/src/App.jsx @@ -1,7 +1,7 @@ import logo from './logo.svg' import './App.css' -import SendMessage from "./component_examples/example_functions" -import React from "react"; +import SendMessage from './component_examples/example_functions' +import React from 'react'; function App() { return ( diff --git a/examples/react-example/src/App.test.jsx b/examples/react-example/src/App.test.jsx index ee495b31e..0bf2466a8 100644 --- a/examples/react-example/src/App.test.jsx +++ b/examples/react-example/src/App.test.jsx @@ -1,7 +1,7 @@ import { render, screen } from '@testing-library/react' import App from './App' -import React from "react"; -import { expect, test } from "vitest"; +import React from 'react'; +import { expect, test } from 'vitest'; test('renders learn react link', () => { render() diff --git a/examples/react-example/src/component_examples/example_functions.jsx b/examples/react-example/src/component_examples/example_functions.jsx index 5c52edac8..99576b5cc 100644 --- a/examples/react-example/src/component_examples/example_functions.jsx +++ b/examples/react-example/src/component_examples/example_functions.jsx @@ -2,13 +2,13 @@ import React, { useState } from 'react' import ROSLIB from '../../../..' function SendMessage() { - const [status, setStatus] = useState("Not connected") + const [status, setStatus] = useState('Not connected') const [linear, setLinear] = useState({ x: 0, y: 0, z: 0 }) const [angular, setAngular] = useState({ x: 0, y: 0, z: 0 }) const ros = new ROSLIB.Ros({encoding: 'ascii'}) function convert(input){ - if (input.charAt(0) === "-") { + if (input.charAt(0) === '-') { let x = input.slice(0) return parseInt(x) } else { @@ -17,7 +17,7 @@ function SendMessage() { } function connect() { - ros.connect("ws://localhost:9090") + ros.connect('ws://localhost:9090') // won't let the user connect more than once ros.on('error', function (error) { console.log(error) @@ -27,12 +27,12 @@ function SendMessage() { // Find out exactly when we made a connection. ros.on('connection', function () { console.log('Connected!') - setStatus("Connected!") + setStatus('Connected!') }) ros.on('close', function () { console.log('Connection closed') - setStatus("Connection closed") + setStatus('Connection closed') }) } @@ -42,8 +42,8 @@ function SendMessage() { } const cmdVel = new ROSLIB.Topic({ ros: ros, - name: "pose_topic", - messageType: "geometry_msgs/Pose2D" + name: 'pose_topic', + messageType: 'geometry_msgs/Pose2D' }) const data = new ROSLIB.Message({ @@ -65,18 +65,18 @@ function SendMessage() {

Send a message to turtle

Linear:

- setLinear({...linear, x: convert(ev.target.value)})}/> + setLinear({...linear, x: convert(ev.target.value)})}/> - setLinear({...linear, y: convert(ev.target.value)})}/> + setLinear({...linear, y: convert(ev.target.value)})}/> - setLinear({...linear, z: convert(ev.target.value)})}/> + setLinear({...linear, z: convert(ev.target.value)})}/>

Angular:

- setAngular({...angular, x: convert(ev.target.value)})}/> + setAngular({...angular, x: convert(ev.target.value)})}/> - setAngular({...angular, y: convert(ev.target.value)})}/> + setAngular({...angular, y: convert(ev.target.value)})}/> - setAngular({...angular, z: convert(ev.target.value)})}/> + setAngular({...angular, z: convert(ev.target.value)})}/>

From bf3c0942d0fc958c5c402e5e1862e0880befec6d Mon Sep 17 00:00:00 2001 From: Ezra Brooks Date: Tue, 20 Feb 2024 08:27:06 -0700 Subject: [PATCH 5/7] Fix missing `new`s --- test/examples/check-topics.example.js | 2 +- test/examples/params.examples.js | 2 +- test/examples/pubsub.example.js | 4 ++-- test/examples/tf.example.js | 2 +- test/examples/tf_service.example.js | 2 +- test/examples/topic-listener.example.js | 9 ++------- 6 files changed, 8 insertions(+), 13 deletions(-) diff --git a/test/examples/check-topics.example.js b/test/examples/check-topics.example.js index 2164d9cd1..499bf3d6f 100644 --- a/test/examples/check-topics.example.js +++ b/test/examples/check-topics.example.js @@ -23,7 +23,7 @@ describe('Example topics are live', function() { }); })); - var example = ros.Topic({ + var example = new ros.Topic({ name: '/some_test_topic', messageType: 'std_msgs/String' }); diff --git a/test/examples/params.examples.js b/test/examples/params.examples.js index 561dea889..cc19f022e 100644 --- a/test/examples/params.examples.js +++ b/test/examples/params.examples.js @@ -5,7 +5,7 @@ describe('Param setting', function() { var ros = new ROSLIB.Ros({ url: 'ws://localhost:9090' }); - var param = ros.Param({ + var param = new ros.Param({ name: '/test/foo' }); diff --git a/test/examples/pubsub.example.js b/test/examples/pubsub.example.js index 58960a029..1f70a562a 100644 --- a/test/examples/pubsub.example.js +++ b/test/examples/pubsub.example.js @@ -7,7 +7,7 @@ describe('Topics Example', function() { url: 'ws://localhost:9090' }); - var example = ros.Topic({ + var example = new ros.Topic({ name: '/example_topic', messageType: 'std_msgs/String' }); @@ -18,7 +18,7 @@ describe('Topics Example', function() { var messages1 = ['Hello Example2!', 'Whats good?'].map(format); var messages2 = ['Hi there', 'this example working'].map(format); - var example2 = ros.Topic({ + var example2 = new ros.Topic({ name: '/example_topic', messageType: 'std_msgs/String' }); diff --git a/test/examples/tf.example.js b/test/examples/tf.example.js index 8353f3013..213227b14 100644 --- a/test/examples/tf.example.js +++ b/test/examples/tf.example.js @@ -26,7 +26,7 @@ describe('TF2 Republisher Example', function() { url: 'ws://localhost:9090' }); - var tfClient = ros.TFClient({ + var tfClient = new ros.TFClient({ fixedFrame: 'world', angularThres: 0.01, transThres: 0.01 diff --git a/test/examples/tf_service.example.js b/test/examples/tf_service.example.js index 98cd04410..4c58c1d70 100644 --- a/test/examples/tf_service.example.js +++ b/test/examples/tf_service.example.js @@ -29,7 +29,7 @@ describe('TF2 Republisher Service Example', function() { url: 'ws://localhost:9090' }); - var tfClient = ros.TFClient({ + var tfClient = new ros.TFClient({ fixedFrame: 'world', angularThres: 0.01, transThres: 0.01 diff --git a/test/examples/topic-listener.example.js b/test/examples/topic-listener.example.js index 6d900008f..d00a057b5 100644 --- a/test/examples/topic-listener.example.js +++ b/test/examples/topic-listener.example.js @@ -5,11 +5,6 @@ var ros = new ROSLIB.Ros({ url: 'ws://localhost:9090' }); -var example = ros.Topic({ - name: '/test_topic', - messageType: 'std_msgs/String' -}); - function format(msg) { return {data: msg}; } @@ -18,7 +13,7 @@ var messages = ['1', '2', '3', '4'].map(format); describe('Topics Example', function() { function createAndStreamTopic(topicName) { - var topic = ros.Topic({ + var topic = new ros.Topic({ name: topicName, messageType: 'std_msgs/String' }); @@ -62,7 +57,7 @@ if (ROSLIB.Topic.prototype.toStream) { function createAndStreamTopic(topicName) { var stream = new TransformStream({ objectMode: true }); - var topic = ros.Topic({ + var topic = new ros.Topic({ name: topicName, messageType: 'std_msgs/String' }); From 14807129728b32c4348ad52c5100d717a86b8afa Mon Sep 17 00:00:00 2001 From: Ezra Brooks Date: Tue, 20 Feb 2024 08:32:18 -0700 Subject: [PATCH 6/7] Revert "Fix missing `new`s" This reverts commit bf3c0942d0fc958c5c402e5e1862e0880befec6d. --- test/examples/check-topics.example.js | 2 +- test/examples/params.examples.js | 2 +- test/examples/pubsub.example.js | 4 ++-- test/examples/tf.example.js | 2 +- test/examples/tf_service.example.js | 2 +- test/examples/topic-listener.example.js | 9 +++++++-- 6 files changed, 13 insertions(+), 8 deletions(-) diff --git a/test/examples/check-topics.example.js b/test/examples/check-topics.example.js index 499bf3d6f..2164d9cd1 100644 --- a/test/examples/check-topics.example.js +++ b/test/examples/check-topics.example.js @@ -23,7 +23,7 @@ describe('Example topics are live', function() { }); })); - var example = new ros.Topic({ + var example = ros.Topic({ name: '/some_test_topic', messageType: 'std_msgs/String' }); diff --git a/test/examples/params.examples.js b/test/examples/params.examples.js index cc19f022e..561dea889 100644 --- a/test/examples/params.examples.js +++ b/test/examples/params.examples.js @@ -5,7 +5,7 @@ describe('Param setting', function() { var ros = new ROSLIB.Ros({ url: 'ws://localhost:9090' }); - var param = new ros.Param({ + var param = ros.Param({ name: '/test/foo' }); diff --git a/test/examples/pubsub.example.js b/test/examples/pubsub.example.js index 1f70a562a..58960a029 100644 --- a/test/examples/pubsub.example.js +++ b/test/examples/pubsub.example.js @@ -7,7 +7,7 @@ describe('Topics Example', function() { url: 'ws://localhost:9090' }); - var example = new ros.Topic({ + var example = ros.Topic({ name: '/example_topic', messageType: 'std_msgs/String' }); @@ -18,7 +18,7 @@ describe('Topics Example', function() { var messages1 = ['Hello Example2!', 'Whats good?'].map(format); var messages2 = ['Hi there', 'this example working'].map(format); - var example2 = new ros.Topic({ + var example2 = ros.Topic({ name: '/example_topic', messageType: 'std_msgs/String' }); diff --git a/test/examples/tf.example.js b/test/examples/tf.example.js index 213227b14..8353f3013 100644 --- a/test/examples/tf.example.js +++ b/test/examples/tf.example.js @@ -26,7 +26,7 @@ describe('TF2 Republisher Example', function() { url: 'ws://localhost:9090' }); - var tfClient = new ros.TFClient({ + var tfClient = ros.TFClient({ fixedFrame: 'world', angularThres: 0.01, transThres: 0.01 diff --git a/test/examples/tf_service.example.js b/test/examples/tf_service.example.js index 4c58c1d70..98cd04410 100644 --- a/test/examples/tf_service.example.js +++ b/test/examples/tf_service.example.js @@ -29,7 +29,7 @@ describe('TF2 Republisher Service Example', function() { url: 'ws://localhost:9090' }); - var tfClient = new ros.TFClient({ + var tfClient = ros.TFClient({ fixedFrame: 'world', angularThres: 0.01, transThres: 0.01 diff --git a/test/examples/topic-listener.example.js b/test/examples/topic-listener.example.js index d00a057b5..6d900008f 100644 --- a/test/examples/topic-listener.example.js +++ b/test/examples/topic-listener.example.js @@ -5,6 +5,11 @@ var ros = new ROSLIB.Ros({ url: 'ws://localhost:9090' }); +var example = ros.Topic({ + name: '/test_topic', + messageType: 'std_msgs/String' +}); + function format(msg) { return {data: msg}; } @@ -13,7 +18,7 @@ var messages = ['1', '2', '3', '4'].map(format); describe('Topics Example', function() { function createAndStreamTopic(topicName) { - var topic = new ros.Topic({ + var topic = ros.Topic({ name: topicName, messageType: 'std_msgs/String' }); @@ -57,7 +62,7 @@ if (ROSLIB.Topic.prototype.toStream) { function createAndStreamTopic(topicName) { var stream = new TransformStream({ objectMode: true }); - var topic = new ros.Topic({ + var topic = ros.Topic({ name: topicName, messageType: 'std_msgs/String' }); From 30acdbd9a1ce9cb26cf12f1ae1e39b3d90d7459a Mon Sep 17 00:00:00 2001 From: Ezra Brooks Date: Tue, 20 Feb 2024 08:32:50 -0700 Subject: [PATCH 7/7] remove `new-cap` rule as it conflicts with our own library structure --- eslint.config.js | 1 - 1 file changed, 1 deletion(-) diff --git a/eslint.config.js b/eslint.config.js index 4bc395f3e..bc7319569 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -24,7 +24,6 @@ module.exports = [ eqeqeq: 2, 'wrap-iife': [2, 'any'], 'no-use-before-define': 0, - 'new-cap': 2, 'no-caller': 2, 'dot-notation': 0, 'no-undef': 2,