Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
PrimeGoose committed Jun 12, 2022
1 parent fd3a6fe commit dd29503
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 44 deletions.
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
build/
bin/
dev/
8 changes: 8 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "./node_modules/gts/"



}


4 changes: 4 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
...require('gts/.prettierrc.json'),
printWidth: 120
}
60 changes: 21 additions & 39 deletions bin/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#!/usr/bin/env node



/**
* It checks if a string is a valid IP address and port number
* @param str - The string to be tested.
Expand All @@ -13,7 +11,6 @@ function isValid_IP_and_Port(str) {
return cong.test(str);
}


/**
* It extracts the port number from a string of the form `"xxx.xxx.xxx.xxx:yyyyy"` where `xxx` is an IP
* address and `yyyyy` is a port number
Expand All @@ -25,14 +22,13 @@ function extractPort(str) {
/^(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9]):([0-9]|[1-9]\d{1,3}|[1-5]\d{4}|6[0-4]\d{3}|65[0-4]\d{2}|655[0-2]\d|6553[0-5])$/;
const port = cong.exec(str);
if (port) {
return parseInt(port[ 5 ]);
return parseInt(port[5]);
}
console.log('function extractPort: invalid port, using default port 20777');

return 20777;
}


/**
* It takes a string and returns the IP address if it's valid, otherwise it returns an empty string
* @param str - The string to be parsed.
Expand All @@ -43,7 +39,7 @@ function extractIP(str) {
/^(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9]):([0-9]|[1-9]\d{1,3}|[1-5]\d{4}|6[0-4]\d{3}|65[0-4]\d{2}|655[0-2]\d|6553[0-5])$/;
const result = cong.exec(str);
if (result) {
return result[ 1 ] + '.' + result[ 2 ] + '.' + result[ 3 ] + '.' + result[ 4 ];
return result[1] + '.' + result[2] + '.' + result[3] + '.' + result[4];
}
return '';
}
Expand All @@ -53,7 +49,7 @@ const validArgs = [];
/* It's importing the dgram module. */
const dgram = require('dgram');
/* It's a variable that will hold the socket. */
let socket // created on --forward command because
let socket; // created on --forward command because
/* It's an array that will hold the valid IP addresses and port numbers. */
const args = process.argv.slice(2);
/* It's slicing the array of arguments from the third element. */
Expand All @@ -67,7 +63,7 @@ const ValidLogArgs = [];
* @param args2 - The arguments passed to the command
*/
function validateLogArgs(args2) {
args2.map((x) => {
args2.map(x => {
if (x.length >= 0 && x.length <= 11) {
ValidLogArgs.push(x);
}
Expand Down Expand Up @@ -114,7 +110,7 @@ if (args.length === 0) {
}

/* It's checking if the user has entered the `-f` or `--forward` flag. */
if (args[ 0 ] === '-f' || args[ 0 ] === '--forward') {
if (args[0] === '-f' || args[0] === '--forward') {
/* It's creating a socket. */
socket = dgram.createSocket('udp4');
/* It's binding the socket to the port 20777 and the IP address 127.0.0.1. */
Expand All @@ -139,7 +135,7 @@ if (args[ 0 ] === '-f' || args[ 0 ] === '--forward') {

const port = extractPort(arg);

validArgs.push({ ip: ip, port: port });
validArgs.push({ip: ip, port: port});
} else {
console.error(`
"${arg}"'is not valid!
Expand All @@ -159,7 +155,7 @@ if (args[ 0 ] === '-f' || args[ 0 ] === '--forward') {
}

/* It's checking if the user has entered the `--log` or `-l` flag. */
if (args[ 0 ] === '--log' || args[ 0 ] === '-l') {
if (args[0] === '--log' || args[0] === '-l') {
/* It's checking if the user has entered any arguments. */
if (setOfLogArgs.size === 0) {
console.log(`
Expand Down Expand Up @@ -190,7 +186,6 @@ if (args[ 0 ] === '--log' || args[ 0 ] === '-l') {
}
}


/**
* The function `forward()` listens for incoming UDP packets on the port specified by the user, and
* then forwards those packets to the IP addresses and ports specified by the user
Expand All @@ -209,8 +204,8 @@ function forward() {
by the user. */
validArgs.map(valid => {
const s2 = dgram.createSocket('udp4');
socket.on('message', (m) => {
s2.send(m, 0, m.length, valid.port, valid.ip, (err) => {
socket.on('message', m => {
s2.send(m, 0, m.length, valid.port, valid.ip, err => {
/* It's checking if there is an error. */
if (err) {
console.log(err);
Expand All @@ -223,7 +218,6 @@ function forward() {
});
}


/**
* It logs the data from the F1 2021 game to the console.
*/
Expand All @@ -234,102 +228,90 @@ function log() {
/* It's creating a new instance of the `F1TelemetryClient` class. */
const client = new parser();



/* It's checking if the user has entered the `0` argument. */
if (setOfLogArgs.has('0')) {
client.on('motion', (data) => {
client.on('motion', data => {
console.log(data);
});
}

/* It's checking if the user has entered the `1` argument. */
if (setOfLogArgs.has('1')) {
client.on('session', (data) => {
client.on('session', data => {
console.log(data);
});
}

/* It's checking if the user has entered the `2` argument. */
if (setOfLogArgs.has('2')) {
client.on('lapData', (data) => {
client.on('lapData', data => {
console.log(data);
});
}


/* It's checking if the user has entered the `3` argument. */
if (setOfLogArgs.has('3')) {
client.on('event', (data) => {
client.on('event', data => {
console.log(data);
});
}


/* It's checking if the user has entered the `4` argument. */
if (setOfLogArgs.has('4')) {
client.on('participants', (data) => {
client.on('participants', data => {
console.log(data);
});
}


/* It's checking if the user has entered the `5` argument. */
if (setOfLogArgs.has('5')) {
client.on('carSetups', (data) => {
client.on('carSetups', data => {
console.log(data);
});
}


/* It's checking if the user has entered the `6` argument. */
if (setOfLogArgs.has('6')) {
client.on('carTelemetry', (data) => {
client.on('carTelemetry', data => {
console.log(data);
});
}


/* It's checking if the user has entered the `7` argument. */
if (setOfLogArgs.has('7')) {
client.on('carStatus', (data) => {
client.on('carStatus', data => {
console.log(data);
});
}


/* It's checking if the user has entered the `8` argument. */
if (setOfLogArgs.has('8')) {
client.on('finalClassification', (data) => {
client.on('finalClassification', data => {
console.log(data);
});
}


/* It's checking if the user has entered the `9` argument. */
if (setOfLogArgs.has('9')) {
client.on('lobbyInfo', (data) => {
client.on('lobbyInfo', data => {
console.log(data);
});
}


/* It's checking if the user has entered the `10` argument. */
if (setOfLogArgs.has('10')) {
client.on('carDamage', (data) => {
client.on('carDamage', data => {
console.log(data);
});
}


/* It's checking if the user has entered the `11` argument. */
if (setOfLogArgs.has('11')) {
client.on('sessionHistory', (data) => {
client.on('sessionHistory', data => {
console.log(data);
});
}


/* It's starting the client. */
client.start();
}
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@
"devDependencies": {
"@types/binary-parser": "1.5.1",
"@types/fs-extra": "^9.0.13",
"@types/node": "^17.0.42",
"@types/node": "^14.11.2",
"@typescript-eslint/eslint-plugin": "^4.32.0",
"eslint": "7.32.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^4.0.0",
"fs-extra": "^10.0.0",
"gts": "^3.1.0",
"husky": "^7.0.2",
"husky": "^7.0.4",
"lint-staged": "11.2.6",
"typescript": "^4.7.3",
"typescript": "^4.0.3",
"uglify-js": "^3.16.0"
},
"bin": {
Expand All @@ -48,7 +48,7 @@
"clean": "gts clean",
"compile": "tsc",
"fix": "gts fix",
"prepare": "npm run compile && husky install",
"prepare": "husky install",
"pretest": "npm run compile",
"posttest": "npm run lint",
"lint": "gts lint",
Expand Down Expand Up @@ -79,4 +79,4 @@
"engines": {
"node": ">=12"
}
}
}

0 comments on commit dd29503

Please sign in to comment.