From d57e3562e2fa74c7e3e63918313fe40209c87a43 Mon Sep 17 00:00:00 2001 From: Stephen Dade Date: Sun, 10 Nov 2024 15:41:16 +1100 Subject: [PATCH] Linting fixes --- mavlink/mavManager.js | 13 ++-- mavlink/mavManager.test.js | 23 ++++--- package-lock.json | 1 + package.json | 1 + server/aboutInfo.js | 8 +-- server/adhocManager.js | 2 +- server/flightController.js | 26 +++++--- server/flightController.test.js | 2 +- server/flightLogger.test.js | 4 +- server/index.js | 10 +-- server/networkClients.test.js | 2 +- server/networkManager.js | 4 +- server/networkManager.test.js | 4 +- server/ntrip.js | 1 + server/videostream.js | 4 +- server/videostream.test.js | 4 +- server/vpn.js | 4 +- src/App.test.js | 112 ++++++++++++++++---------------- src/AppRouter.js | 15 ++--- src/about.js | 8 +-- src/adhocwifi.js | 11 ++-- src/basePage.js | 6 +- src/cloud.js | 9 ++- src/flightcontroller.js | 19 +++--- src/footerSocketIO.js | 9 ++- src/home.js | 2 - src/index.js | 1 - src/logBrowser.js | 9 ++- src/networkClients.js | 1 - src/networkconfig.js | 47 +++++++------- src/ntripcontroller.js | 6 +- src/video.js | 23 ++++--- src/vpnconfig.js | 13 ++-- 33 files changed, 200 insertions(+), 204 deletions(-) diff --git a/mavlink/mavManager.js b/mavlink/mavManager.js index 22ba5e21..bafa6681 100644 --- a/mavlink/mavManager.js +++ b/mavlink/mavManager.js @@ -359,18 +359,19 @@ class mavManager { let buf = Buffer.from(gpmessage) const msgset = [] const maxBytes = 180 - while (true) { - if (buf.length > maxBytes) { + while (buf.length > maxBytes) { + //if (buf.length > maxBytes) { // slice msgset.push(buf.slice(0, maxBytes)) buf = buf.slice(maxBytes) - } else { + //} else { // need to pad to 180 chars? No, message packing // will do this for us - msgset.push(buf) - break - } + // msgset.push(buf) + // break + //} } + msgset.push(buf) for (let i = 0, len = msgset.length; i < len; i++) { const msg = new common.GpsRtcmData() diff --git a/mavlink/mavManager.test.js b/mavlink/mavManager.test.js index 55b2a1cc..4bdcc94d 100644 --- a/mavlink/mavManager.test.js +++ b/mavlink/mavManager.test.js @@ -1,5 +1,4 @@ const assert = require('assert') -const should = require('should') const mavManager = require('./mavManager') const udp = require('dgram') @@ -15,7 +14,7 @@ describe('MAVLink Functions', function () { const m = new mavManager(2, '127.0.0.1', 15000) const packets = [] - m.eventEmitter.on('gotMessage', (packet, data) => { + m.eventEmitter.on('gotMessage', (packet,) => { packets.push(packet.buffer) }) @@ -50,11 +49,11 @@ describe('MAVLink Functions', function () { assert.equal(m.statusBytesPerSec.avgBytesSec, 0) - m.eventEmitter.on('linkready', (info) => { + m.eventEmitter.on('linkready', () => { m.sendVersionRequest() }) - udpStream.on('message', (msg, rinfo) => { + udpStream.on('message', (msg) => { msg.should.eql(Buffer.from([0xfd, 0x21, 0x00, 0x00, 0x00, 0x00, 0xBF, 0x4c, 0x00, 0x00, 0x00, 0x00, 0x14, 0x43, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x01, 0xbf, 0x5b])) @@ -75,11 +74,11 @@ describe('MAVLink Functions', function () { const m = new mavManager(2, '127.0.0.1', 15000) const udpStream = udp.createSocket('udp4') - m.eventEmitter.on('linkready', (info) => { + m.eventEmitter.on('linkready', () => { m.sendDSRequest() }) - udpStream.on('message', (msg, rinfo) => { + udpStream.on('message', (msg) => { msg.should.eql(Buffer.from([253, 6, 0, 0, 0, 0, 191, 66, 0, 0, 4, 0, 0, 0, 0, 1, 171, 220])) m.close() udpStream.close() @@ -97,11 +96,11 @@ describe('MAVLink Functions', function () { const m = new mavManager(2, '127.0.0.1', 15000) const udpStream = udp.createSocket('udp4') - m.eventEmitter.on('linkready', (info) => { + m.eventEmitter.on('linkready', () => { m.sendReboot() }) - udpStream.on('message', (msg, rinfo) => { + udpStream.on('message', (msg) => { msg.should.eql(Buffer.from([253, 33, 0, 0, 0, 0, 191, 76, 0, 0, 0, 0, 128, 63, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 246, 0, 0, 0, 1, 187, 227])) m.close() udpStream.close() @@ -119,11 +118,11 @@ describe('MAVLink Functions', function () { const m = new mavManager(2, '127.0.0.1', 15000) const udpStream = udp.createSocket('udp4') - m.eventEmitter.on('linkready', (info) => { + m.eventEmitter.on('linkready', () => { m.sendHeartbeat() }) - udpStream.on('message', (msg, rinfo) => { + udpStream.on('message', (msg) => { msg.should.eql(Buffer.from([253, 9, 0, 0, 0, 0, 191, 0, 0, 0, 0, 0, 0, 0, 18, 8, 0, 0, 2, 61, 244 ])) m.close() udpStream.close() @@ -141,11 +140,11 @@ describe('MAVLink Functions', function () { const m = new mavManager(2, '127.0.0.1', 15000) const udpStream = udp.createSocket('udp4') - m.eventEmitter.on('linkready', (info) => { + m.eventEmitter.on('linkready', () => { m.sendCommandAck() }) - udpStream.on('message', (msg, rinfo) => { + udpStream.on('message', (msg) => { msg.should.eql(Buffer.from([253, 9, 0, 0, 0, 0, 191, 77, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 197, 27])) m.close() udpStream.close() diff --git a/package-lock.json b/package-lock.json index 9471633b..061d1d81 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19,6 +19,7 @@ "npm": "^10.5.2", "ntrip-client": "^1.1.1", "nyc": "^17.1.0", + "prop-types": "^15.8.1", "react": "^18.2.0", "react-bootstrap": "^2.8.0", "react-dom": "^18.2.0", diff --git a/package.json b/package.json index 5699e550..cc5d29cc 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "npm": "^10.5.2", "ntrip-client": "^1.1.1", "nyc": "^17.1.0", + "prop-types": "^15.8.1", "react": "^18.2.0", "react-bootstrap": "^2.8.0", "react-dom": "^18.2.0", diff --git a/server/aboutInfo.js b/server/aboutInfo.js index b7487197..c6409636 100644 --- a/server/aboutInfo.js +++ b/server/aboutInfo.js @@ -23,7 +23,7 @@ function getDiskInfo (callback) { }) } -function rebootCC () { +/*function rebootCC () { // reboot the companion computer console.log('Reboot now') winston.info('Reboot now') @@ -35,13 +35,13 @@ function rebootCC () { console.log(stdout) winston.info(stdout) }) -} +}*/ function shutdownCC () { // shutdown the companion computer console.log('Shutting down') winston.info('Shutting down') - exec('sudo shutdown now', function (error, stdout, stderr) { + exec('sudo shutdown now', function (error, stdout) { if (error) { console.log(error) winston.info(error) @@ -103,7 +103,7 @@ function getHardwareInfo (callback) { sysData = execSync('cat /proc/cpuinfo | awk \'/Model/ {print substr($0, index($0,$3))}\'').toString() } // get Pi HAT data, if it exists - exec('cat /proc/device-tree/hat/product && printf "\n" && cat /proc/device-tree/hat/vendor && printf "\n" && cat /proc/device-tree/hat/product_ver', (error, stdout, stderr) => { + exec('cat /proc/device-tree/hat/product && printf "\n" && cat /proc/device-tree/hat/vendor && printf "\n" && cat /proc/device-tree/hat/product_ver', (error, stdout) => { if (!error && stdout.split('\n').length === 3) { const items = stdout.split('\n') hatData.product = items[0] diff --git a/server/adhocManager.js b/server/adhocManager.js index dc41bd2a..27d976e2 100644 --- a/server/adhocManager.js +++ b/server/adhocManager.js @@ -17,7 +17,7 @@ class adhocManager { // if Ahoc mode is supposed to be active, then activate it. As OS won't save settings between reboots if (this.device !== null) { // this.setAdapter(true, this.device, this.devicesettings, null) - this.setAdapter(true, this.device, this.devicesettings, (err, netDeviceList, netDeviceSelected, settings) => { + this.setAdapter(true, this.device, this.devicesettings, (err) => { if (!err) { console.log('Adhoc Init ' + this.device.toString()) this.winston.info('Adhoc Init ' + this.device.toString()) diff --git a/server/flightController.js b/server/flightController.js index 3cb23cf2..697a79f1 100644 --- a/server/flightController.js +++ b/server/flightController.js @@ -1,10 +1,9 @@ -const SerialPort = require('serialport') const { autoDetect } = require('@serialport/bindings-cpp') const fs = require('fs') const events = require('events') const path = require('path') const appRoot = require('app-root-path') -const { spawn, spawnSync, exec } = require('child_process') +const { spawn, spawnSync } = require('child_process') const si = require('systeminformation') const mavManager = require('../mavlink/mavManager.js') @@ -104,11 +103,11 @@ class FCDetails { if (this.activeDevice !== null) { // restart link if saved serial device is found let found = false - this.getSerialDevices((err, devices, bauds, seldevice, selbaud, mavers, selmav, active, enableHeartbeat, enableTCP) => { + this.getSerialDevices((err, devices) => { for (let i = 0, len = devices.length; i < len; i++) { if (this.activeDevice.serial.value === devices[i].value) { found = true - this.startLink((err, active) => { + this.startLink((err) => { if (err) { console.log("Can't open found FC " + this.activeDevice.serial.value + ', resetting link') this.winston.info("Can't open found FC " + this.activeDevice.serial.value + ', resetting link') @@ -180,9 +179,10 @@ class FCDetails { // restart mavlink-router, if link active if (this.m) { - this.closeLink((err) => { + this.closeLink(() => { this.startLink((err) => { if (err) { + console.log(err) } }) }) @@ -192,6 +192,7 @@ class FCDetails { try { this.saveSerialSettings() } catch (e) { + console.log(e) } return this.getUDPOutputs() @@ -215,9 +216,10 @@ class FCDetails { // restart mavlink-router, if link active if (this.m) { - this.closeLink((err) => { + this.closeLink(() => { this.startLink((err) => { if (err) { + console.log(err) } }) }) @@ -227,6 +229,7 @@ class FCDetails { try { this.saveSerialSettings() } catch (e) { + console.log(e) } return this.getUDPOutputs() @@ -340,7 +343,9 @@ class FCDetails { fs.unlinkSync(this.binlog) } } - } catch (err) {} + } catch (err) { + console.log(err) + } const res = data.toString().split(' ') const curLog = (res[res.length - 1]).trim() this.binlog = path.join(appRoot.toString(), 'flightlogs', 'binlogs', curLog) @@ -493,9 +498,10 @@ class FCDetails { if (this.m && this.m.conStatusInt() === -1) { console.log('Trying to reconnect FC...') this.winston.info('Trying to reconnect FC...') - this.closeLink((err) => { + this.closeLink(() => { this.startLink((err) => { if (err) { + console.log(err) } else { // DS request is in this.m.restart() this.m.restart() @@ -564,7 +570,7 @@ class FCDetails { } else { // close link this.activeDevice = null - this.closeLink((err) => { + this.closeLink(() => { this.saveSerialSettings() clearInterval(this.intervalObj) this.previousConnection = false @@ -589,7 +595,7 @@ class FCDetails { console.log('Saved FC settings') this.winston.info('Saved FC settings') } catch (e) { - + console.log(e) } } } diff --git a/server/flightController.test.js b/server/flightController.test.js index 4c83a1db..422bccd7 100644 --- a/server/flightController.test.js +++ b/server/flightController.test.js @@ -13,7 +13,7 @@ describe('Flight Controller Functions', function () { assert.equal(FC.previousConnection, false) }) - it('#fcGetSerialDevices()', async () => { + it('#fcGetSerialDevices()', async function () { settings.clear() const FC = new FCManagerClass(settings, winston) diff --git a/server/flightLogger.test.js b/server/flightLogger.test.js index 81d34af0..06c422e0 100644 --- a/server/flightLogger.test.js +++ b/server/flightLogger.test.js @@ -13,7 +13,7 @@ describe('Logging Functions', function () { // Recursively delete folder and files const deleteFolderRecursive = function (path, ext) { if (fs.existsSync(path)) { - fs.readdirSync(path).forEach((file, index) => { + fs.readdirSync(path).forEach((file) => { const curPath = Path.join(path, file) if (fs.lstatSync(curPath).isDirectory()) { // recurse deleteFolderRecursive(curPath) @@ -53,7 +53,7 @@ describe('Logging Functions', function () { // create a fake log fs.writeFileSync(Path.join(appRoot.toString(), 'flightlogs', 'flight.tlog'), Buffer.from('tést')) - Lgr.getLogs(function (err, tlogs, binlogs, kmzlogs, activeLogging) { + Lgr.getLogs(function (err, tlogs, binlogs, kmzlogs) { assert.equal(tlogs.length, 1) assert.equal(binlogs.length, 0) assert.equal(kmzlogs.length, 0) diff --git a/server/index.js b/server/index.js index adb9146d..42d5bc3e 100644 --- a/server/index.js +++ b/server/index.js @@ -40,7 +40,7 @@ app.use(limiter) app.use(fileUpload({ limits: { fileSize: 500 }, abortOnLimit: true, useTempFiles: true, tempFileDir: '/tmp/', safeFileNames: true, preserveExtension: 4 })) const io = require('socket.io')(http, { cookie: false }) -const { check, validationResult, oneOf } = require('express-validator') +const { check, validationResult } = require('express-validator') // Init settings before running the other classes settings.init({ @@ -536,12 +536,12 @@ app.get('/api/FCDetails', (req, res) => { }) }) -app.post('/api/shutdowncc', function (req, res) { +app.post('/api/shutdowncc', function () { // User wants to shutdown the computer aboutPage.shutdownCC() }) -app.post('/api/updatemaster', function (req, res) { +app.post('/api/updatemaster', function () { // User wants to update Rpanion to latest master aboutPage.updateRS(io) }) @@ -567,7 +567,7 @@ app.post('/api/FCModify', [check('device').isJSON(), check('baud').isJSON(), che }) }) -app.post('/api/FCReboot', function (req, res) { +app.post('/api/FCReboot', function () { fcManager.rebootFC() }) @@ -597,7 +597,7 @@ app.post('/api/removeudpoutput', [check('removeoutputIP').isIP(), check('removeo res.send(JSON.stringify({ UDPoutputs: newOutput })) }) -io.on('connection', function (socket) { +io.on('connection', function () { // only set interval if not already set if (FCStatusLoop !== null) { return diff --git a/server/networkClients.test.js b/server/networkClients.test.js index dbe02db6..52684132 100644 --- a/server/networkClients.test.js +++ b/server/networkClients.test.js @@ -4,7 +4,7 @@ const networkClients = require('./networkClients') describe('Network Client Functions', function () { it('#networkclientgetClients()', function (done) { // Getting a list of clients - networkClients.getClients((err, apnamev, apclientsv) => { + networkClients.getClients((err) => { assert.equal(err, null) done() }) diff --git a/server/networkManager.js b/server/networkManager.js index 101bb91c..f74ce019 100644 --- a/server/networkManager.js +++ b/server/networkManager.js @@ -138,8 +138,8 @@ function addConnection (conNameStr, conType, conAdapter, conSettings, callback) if (conType === 'wifi') { exec('nmcli connection add type ' + conType + ' ifname ' + conAdapter + ' con-name ' + conNameStr + ' ssid \'' + conSettings.ssid.value + '\' 802-11-wireless.mode ' + - conSettings.mode.value + (conSettings.band === {} ? (' 802-11-wireless.band ' + conSettings.band.value) : '') + - (conSettings.channel === {} ? (' 802-11-wireless.channel ' + (conSettings.channel.value === '0' ? '\'\'' : conSettings.channel.value)) : '') + + conSettings.mode.value + (Object.keys(conSettings.band).length ? (' 802-11-wireless.band ' + conSettings.band.value) : '') + + (Object.keys(conSettings.channel).length ? (' 802-11-wireless.channel ' + (conSettings.channel.value === '0' ? '\'\'' : conSettings.channel.value)) : '') + ' ipv4.method ' + conSettings.ipaddresstype.value + ' connection.autoconnect no ' + ' && ' + 'nmcli -g connection.uuid con show ' + conNameStr, (error, stdout, stderr) => { if (stderr) { diff --git a/server/networkManager.test.js b/server/networkManager.test.js index 047315bf..3913091c 100644 --- a/server/networkManager.test.js +++ b/server/networkManager.test.js @@ -4,7 +4,7 @@ const networkManager = require('./networkManager') describe('Network Functions', function () { it('#networkmanagergetAdapters()', function (done) { // Getting a list of adapters - networkManager.getAdapters(function (err, netDeviceList) { + networkManager.getAdapters(function (err) { assert.equal(err, null) done() }) @@ -12,7 +12,7 @@ describe('Network Functions', function () { it('#networkmanagergetConnections()', function (done) { // Getting a list of adapters - networkManager.getConnections(function (err, netConnectionList) { + networkManager.getConnections(function (err) { assert.equal(err, null) done() }) diff --git a/server/ntrip.js b/server/ntrip.js index b708ef45..4d0d3efd 100644 --- a/server/ntrip.js +++ b/server/ntrip.js @@ -72,6 +72,7 @@ class ntrip { this.eventEmitter.emit('rtcmpacket', data, this.seq) this.seq = this.seq + 1 } catch (e) { + console.log('Bad ntrip data') } } }) diff --git a/server/videostream.js b/server/videostream.js index 076dd847..569fbdce 100644 --- a/server/videostream.js +++ b/server/videostream.js @@ -29,13 +29,13 @@ class videoStream { // need to scan for video devices first though if (this.active) { this.active = false - this.getVideoDevices((error, devices, active, seldevice, selRes, selRot, selbitrate, selfps, selUDP, selUDPIP, selUDPPort, useTimestamp, useCameraHeartbeat, selMavURI) => { + this.getVideoDevices((error) => { if (!error) { this.startStopStreaming(true, this.savedDevice.device, this.savedDevice.height, this.savedDevice.width, this.savedDevice.format, this.savedDevice.rotation, this.savedDevice.bitrate, this.savedDevice.fps, this.savedDevice.useUDP, this.savedDevice.useUDPIP, this.savedDevice.useUDPPort, this.savedDevice.useTimestamp, this.savedDevice.useCameraHeartbeat, this.savedDevice.mavStreamSelected, - (err, status, addresses) => { + (err) => { if (err) { // failed setup, reset settings console.log('Reset video4') diff --git a/server/videostream.test.js b/server/videostream.test.js index a5776838..3bcc99d5 100644 --- a/server/videostream.test.js +++ b/server/videostream.test.js @@ -63,11 +63,11 @@ describe('Video Functions', function () { settings.clear() const vManager = new VideoStream(settings, winston) - vManager.startStopStreaming(true, 'testsrc', '1080', '1920', 'video/x-h264', '0', '1000', '5', false, false, false, true, false, '0', function (err, status, addresses) { + vManager.startStopStreaming(true, 'testsrc', '1080', '1920', 'video/x-h264', '0', '1000', '5', false, false, false, true, false, '0', function (err, status) { assert.equal(err, null) assert.equal(status, true) assert.notEqual(vManager.deviceStream.pid, null) - vManager.startStopStreaming(false, 'testsrc', '1080', '1920', 'video/x-h264', '0', '1000', '5', false, false, false, true, false, '0', function (err, status, addresses) { + vManager.startStopStreaming(false, 'testsrc', '1080', '1920', 'video/x-h264', '0', '1000', '5', false, false, false, true, false, '0', function (err, status) { assert.equal(err, null) assert.equal(status, false) done() diff --git a/server/vpn.js b/server/vpn.js index 1d7b75ce..f64c2737 100644 --- a/server/vpn.js +++ b/server/vpn.js @@ -84,7 +84,7 @@ function addWireguardProfile (filename, tmpfilepath, callback) { function activateWireguardProfile (filename, callback) { // activate a wireguard profile const profile = path.parse(filename).name - exec('sudo wg-quick up ' + profile + ' && sudo systemctl enable wg-quick@' + profile, (error, stdout, stderr) => { + exec('sudo wg-quick up ' + profile + ' && sudo systemctl enable wg-quick@' + profile, (error, stdout) => { if (error !== null) { console.error(`exec error: ${error}`) winston.error('Error in activateWireguardProfile() ', { message: error }) @@ -109,7 +109,7 @@ function deactivateWireguardProfile (filename, callback) { // deactivate a wireguard profile const profile = path.parse(filename).name - exec('sudo systemctl disable wg-quick@' + profile + '&& sudo wg-quick down ' + profile, (error, stdout, stderr) => { + exec('sudo systemctl disable wg-quick@' + profile + '&& sudo wg-quick down ' + profile, (error, stdout) => { if (error !== null) { console.error(`exec error: ${error}`) winston.error('Error in deactivateWireguardProfile() ', { message: error }) diff --git a/src/App.test.js b/src/App.test.js index 48ededdc..7d1e2b16 100644 --- a/src/App.test.js +++ b/src/App.test.js @@ -1,5 +1,3 @@ -import React from 'react' -import ReactDOM from 'react-dom' import { createRoot } from 'react-dom/client' import About from './about.js' @@ -12,65 +10,67 @@ import NTRIPPage from './ntripcontroller.js' import AdhocConfig from './adhocwifi.js' import CloudConfig from './cloud.js' -it('homepage renders without crashing', () => { - const div = document.createElement('div') - const root = createRoot(div) - root.render() - root.unmount() -}) +describe('#apptest()', function () { + it('homepage renders without crashing', function () { + const div = document.createElement('div') + const root = createRoot(div) + root.render() + root.unmount() + }) -it('about page renders without crashing', () => { - const div = document.createElement('div') - const root = createRoot(div) - root.render() - root.unmount() -}) + it('about page renders without crashing', function () { + const div = document.createElement('div') + const root = createRoot(div) + root.render() + root.unmount() + }) -it('networkconfig page renders without crashing', () => { - const div = document.createElement('div') - const root = createRoot(div) - root.render() - root.unmount() -}) + it('networkconfig page renders without crashing', function () { + const div = document.createElement('div') + const root = createRoot(div) + root.render() + root.unmount() + }) -it('video page renders without crashing', () => { - const div = document.createElement('div') - const root = createRoot(div) - root.render(