From 0beb8e569ea3ad38bae86d7f1f82b121ecbfab5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sampo=20Kivist=C3=B6?= Date: Wed, 25 May 2022 20:50:30 +0300 Subject: [PATCH] Updated all dependencies and fixed linting errors, removed unused packages (#29) --- .eslintrc.js | 10 +++++----- .gitignore | 1 + package.json | 28 +++++++++++++--------------- src/dnsDomainLevels.ts | 4 ++-- src/index.ts | 4 +++- src/myIpAddress.ts | 8 ++++---- src/shExpMatch.ts | 4 ++-- src/timeRange.ts | 29 ++++++++++++++--------------- src/util.ts | 2 +- src/weekdayRange.ts | 17 ++++++++--------- 10 files changed, 53 insertions(+), 54 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index fd53128..849b540 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -33,6 +33,7 @@ module.exports = { 'import/no-extraneous-dependencies': 0, 'import/prefer-default-export': 0, 'lines-between-class-members': 0, + 'import/extensions': 0, 'no-await-in-loop': 0, 'no-bitwise': 0, 'no-console': 0, @@ -57,17 +58,16 @@ module.exports = { // '@typescript-eslint/indent': ['error', 2] // this might conflict with a lot ongoing changes '@typescript-eslint/no-array-constructor': 'error', '@typescript-eslint/adjacent-overload-signatures': 'error', - '@typescript-eslint/class-name-casing': 'error', - '@typescript-eslint/interface-name-prefix': 'error', - '@typescript-eslint/no-empty-interface': 'error', + '@typescript-eslint/naming-convention': 'error', + '@typescript-eslint/no-empty-interface': 0, '@typescript-eslint/no-inferrable-types': 'error', '@typescript-eslint/no-misused-new': 'error', '@typescript-eslint/no-namespace': 'error', '@typescript-eslint/no-non-null-assertion': 'error', '@typescript-eslint/no-parameter-properties': 'error', - '@typescript-eslint/no-triple-slash-reference': 'error', + '@typescript-eslint/triple-slash-reference': 'error', '@typescript-eslint/prefer-namespace-keyword': 'error', - '@typescript-eslint/type-annotation-spacing': 'error' + '@typescript-eslint/type-annotation-spacing': 'error', // '@typescript-eslint/array-type': 'error', // '@typescript-eslint/ban-types': 'error', // '@typescript-eslint/explicit-function-return-type': 'warn', diff --git a/.gitignore b/.gitignore index 24238f0..e265e48 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ /node_modules /?.?s /*.pac +.idea diff --git a/package.json b/package.json index 5aa0bc7..f08287d 100644 --- a/package.json +++ b/package.json @@ -8,27 +8,25 @@ "dist" ], "dependencies": { - "degenerator": "^3.0.1", + "degenerator": "^3.0.2", "ip": "^1.1.5", - "netmask": "^2.0.1" + "netmask": "^2.0.2" }, "devDependencies": { "@types/debug": "4", "@types/ip": "^1.1.0", "@types/netmask": "^1.0.30", - "@types/node": "^12.12.11", - "@typescript-eslint/eslint-plugin": "1.6.0", - "@typescript-eslint/parser": "1.1.0", - "eslint": "5.16.0", - "eslint-config-airbnb": "17.1.0", - "eslint-config-prettier": "4.1.0", - "eslint-import-resolver-typescript": "1.1.1", - "eslint-plugin-import": "2.16.0", - "eslint-plugin-jsx-a11y": "6.2.1", - "eslint-plugin-react": "7.12.4", - "mocha": "^6.2.2", - "rimraf": "^3.0.0", - "typescript": "^4.3.5" + "@types/node": "^17.0.19", + "@typescript-eslint/eslint-plugin": "5.12.0", + "@typescript-eslint/parser": "5.12.0", + "eslint": "^8.9.0", + "eslint-config-airbnb": "19.0.4", + "eslint-config-prettier": "8.4.0", + "eslint-import-resolver-typescript": "2.5.0", + "eslint-plugin-import": "2.25.4", + "mocha": "^9.2.1", + "rimraf": "^3.0.2", + "typescript": "^4.5.5" }, "scripts": { "prebuild": "rimraf dist", diff --git a/src/dnsDomainLevels.ts b/src/dnsDomainLevels.ts index b739c54..7bc953f 100644 --- a/src/dnsDomainLevels.ts +++ b/src/dnsDomainLevels.ts @@ -15,8 +15,8 @@ * @return {Number} number of domain levels */ export default function dnsDomainLevels(host: string): number { - var match = String(host).match(/\./g); - var levels = 0; + const match = String(host).match(/\./g); + let levels = 0; if (match) { levels = match.length; } diff --git a/src/index.ts b/src/index.ts index a0f3056..894e7c4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -57,6 +57,7 @@ function createPacResolver( opts ); + /* eslint-disable @typescript-eslint/naming-convention, no-redeclare */ function FindProxyForURL(url: string, host?: string): Promise; function FindProxyForURL( url: string, @@ -110,6 +111,7 @@ function createPacResolver( return FindProxyForURL; } +// eslint-disable-next-line @typescript-eslint/no-namespace namespace createPacResolver { export type GMT = 'GMT'; export type Hour = @@ -189,7 +191,7 @@ namespace createPacResolver { } export type FindProxyForURL = ReturnType; export const sandbox: Readonly = Object.freeze({ - alert: (message: string = '') => console.log('%s', message), + alert: (message = '') => console.log('%s', message), dateRange, dnsDomainIs, dnsDomainLevels, diff --git a/src/myIpAddress.ts b/src/myIpAddress.ts index fdb6550..d358d8e 100644 --- a/src/myIpAddress.ts +++ b/src/myIpAddress.ts @@ -1,5 +1,5 @@ import ip from 'ip'; -import net from 'net'; +import net, {AddressInfo} from 'net'; /** * Returns the IP address of the host that the Navigator is running on, as @@ -20,7 +20,7 @@ export default async function myIpAddress(): Promise { // 8.8.8.8:53 is "Google Public DNS": // https://developers.google.com/speed/public-dns/ const socket = net.connect({ host: '8.8.8.8', port: 53 }); - const onError = (err: Error) => { + const onError = () => { // if we fail to access Google DNS (as in firewall blocks access), // fallback to querying IP locally resolve(ip.address()); @@ -32,8 +32,8 @@ export default async function myIpAddress(): Promise { socket.destroy(); if (typeof addr === 'string') { resolve(addr); - } else if (addr.address) { - resolve(addr.address); + } else if ((addr as AddressInfo).address) { + resolve((addr as AddressInfo).address); } else { reject(new Error('Expected a `string`')); } diff --git a/src/shExpMatch.ts b/src/shExpMatch.ts index 1819c37..1942400 100644 --- a/src/shExpMatch.ts +++ b/src/shExpMatch.ts @@ -21,7 +21,7 @@ */ export default function shExpMatch(str: string, shexp: string): boolean { - var re = toRegExp(shexp); + const re = toRegExp(shexp); return re.test(str); } @@ -36,5 +36,5 @@ function toRegExp(str: string): RegExp { .replace(/\./g, '\\.') .replace(/\?/g, '.') .replace(/\*/g, '.*'); - return new RegExp('^' + str + '$'); + return new RegExp(`^${str}$`); } diff --git a/src/timeRange.ts b/src/timeRange.ts index ba31c00..c86ab62 100644 --- a/src/timeRange.ts +++ b/src/timeRange.ts @@ -41,32 +41,31 @@ */ export default function timeRange(): boolean { - var args = Array.prototype.slice.call(arguments), - lastArg = args.pop(), - useGMTzone = lastArg == 'GMT', - currentDate = new Date(); + // eslint-disable-next-line prefer-rest-params + const args = Array.prototype.slice.call(arguments); + const lastArg = args.pop(); + const useGMTzone = lastArg === 'GMT'; + const currentDate = new Date(); if (!useGMTzone) { args.push(lastArg); } - var noOfArgs = args.length, - result = false, - numericArgs = args.map(function (n) { - return parseInt(n); - }); + const noOfArgs = args.length; + let result = false; + let numericArgs = args.map((n) => parseInt(n, 10)); // timeRange(hour) - if (noOfArgs == 1) { - result = getCurrentHour(useGMTzone, currentDate) == numericArgs[0]; + if (noOfArgs === 1) { + result = getCurrentHour(useGMTzone, currentDate) === numericArgs[0]; // timeRange(hour1, hour2) - } else if (noOfArgs == 2) { - var currentHour = getCurrentHour(useGMTzone, currentDate); + } else if (noOfArgs === 2) { + const currentHour = getCurrentHour(useGMTzone, currentDate); result = numericArgs[0] <= currentHour && currentHour < numericArgs[1]; // timeRange(hour1, min1, hour2, min2) - } else if (noOfArgs == 4) { + } else if (noOfArgs === 4) { result = valueInRange( secondsElapsedToday(numericArgs[0], numericArgs[1], 0), secondsElapsedToday( @@ -78,7 +77,7 @@ export default function timeRange(): boolean { ); // timeRange(hour1, min1, sec1, hour2, min2, sec2) - } else if (noOfArgs == 6) { + } else if (noOfArgs === 6) { result = valueInRange( secondsElapsedToday(numericArgs[0], numericArgs[1], numericArgs[2]), secondsElapsedToday( diff --git a/src/util.ts b/src/util.ts index fbeade5..98547a6 100644 --- a/src/util.ts +++ b/src/util.ts @@ -1,5 +1,5 @@ -import { GMT } from './index'; import { LookupAddress, LookupOptions, lookup } from 'dns'; +import { GMT } from './index'; export function dnsLookup( host: string, diff --git a/src/weekdayRange.ts b/src/weekdayRange.ts index b13f73a..2d04956 100644 --- a/src/weekdayRange.ts +++ b/src/weekdayRange.ts @@ -70,19 +70,18 @@ export default function weekdayRange( } let todaysDay = getTodaysDay(useGMTzone); - let result = false; + let result: boolean; if (wd2Index < 0) { - result = todaysDay == wd1Index; + result = todaysDay === wd1Index; + } else if (wd1Index <= wd2Index) { + result = valueInRange(wd1Index, todaysDay, wd2Index); } else { - if (wd1Index <= wd2Index) { - result = valueInRange(wd1Index, todaysDay, wd2Index); - } else { - result = - valueInRange(wd1Index, todaysDay, 6) || - valueInRange(0, todaysDay, wd2Index); - } + result = + valueInRange(wd1Index, todaysDay, 6) || + valueInRange(0, todaysDay, wd2Index); } + return result; }