Skip to content

Commit

Permalink
chore(package): upgrade to eslint v9
Browse files Browse the repository at this point in the history
  • Loading branch information
chimurai committed Aug 31, 2024
1 parent 61d1933 commit 97f9390
Show file tree
Hide file tree
Showing 15 changed files with 297 additions and 342 deletions.
1 change: 0 additions & 1 deletion .eslintignore

This file was deleted.

30 changes: 0 additions & 30 deletions .eslintrc.js

This file was deleted.

2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"deno.enable": false,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
"source.fixAll.eslint": "explicit"
},
"markdown.extension.toc.levels": "2..3"
}
1 change: 1 addition & 0 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"restream",
"snyk",
"streamify",
"tseslint",
"typicode",
"vhosted",
"websockets",
Expand Down
38 changes: 38 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const eslintPluginPrettierRecommended = require('eslint-plugin-prettier/recommended');
const tseslint = require('typescript-eslint');
const tseslintParser = require('@typescript-eslint/parser');

/** @type {import('eslint').Linter.FlatConfig[]} */
module.exports = [
eslintPluginPrettierRecommended,
...tseslint.configs.recommended,
{
files: ['*.js'],
rules: {
'@typescript-eslint/no-var-requires': 'off',
},
},
{
files: ['**/*.ts'],
ignores: ['dist/*'],
languageOptions: {
parser: tseslintParser,
},
rules: {
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-unused-vars': [
'error',
{ vars: 'all', args: 'none', ignoreRestSiblings: false },
],
'prettier/prettier': 'warn',
},
// overrides: [
// {
// files: ['src/**/*.ts'],
// rules: {
// 'no-restricted-imports': ['error', { paths: ['express'] }],
// },
// },
// ],
},
];
17 changes: 9 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,17 @@
"@commitlint/cli": "19.4.1",
"@commitlint/config-conventional": "19.4.1",
"@types/debug": "4.1.12",
"@types/eslint": "8.56.10",
"@types/express": "4.17.21",
"@types/is-glob": "4.0.4",
"@types/jest": "29.5.12",
"@types/micromatch": "4.0.9",
"@types/node": "22.5.1",
"@types/supertest": "6.0.2",
"@types/ws": "8.5.12",
"@typescript-eslint/eslint-plugin": "7.16.0",
"@typescript-eslint/parser": "7.16.0",
"@typescript-eslint/parser": "8.3.0",
"body-parser": "1.20.2",
"eslint": "8.57.0",
"eslint": "9.9.1",
"eslint-config-prettier": "9.1.0",
"eslint-plugin-prettier": "5.2.1",
"express": "4.19.2",
Expand All @@ -79,11 +79,12 @@
"lint-staged": "15.2.9",
"mockttp": "3.15.2",
"open": "8.4.2",
"prettier": "3.3.3",
"supertest": "7.0.0",
"ts-jest": "29.2.5",
"typescript": "5.5.4",
"ws": "8.18.0"
"prettier": "3.2.5",
"supertest": "6.3.4",
"ts-jest": "29.1.2",
"typescript": "5.4.4",
"typescript-eslint": "8.3.0",
"ws": "8.16.0"
},
"dependencies": {
"@types/http-proxy": "^1.17.15",
Expand Down
6 changes: 3 additions & 3 deletions src/http-proxy-middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ export class HttpProxyMiddleware<TReq, TRes> {
debug(`proxy request to target: %O`, activeProxyOptions.target);
this.proxy.web(req, res, activeProxyOptions);
} catch (err) {
next && next(err);
next?.(err);
}
} else {
next && next();
next?.();
}

/**
Expand Down Expand Up @@ -79,7 +79,7 @@ export class HttpProxyMiddleware<TReq, TRes> {
private registerPlugins(proxy: httpProxy<TReq, TRes>, options: Options<TReq, TRes>) {
const plugins = getPlugins<TReq, TRes>(options);
plugins.forEach((plugin) => {
debug(`register plugin: "${getFunctionName(plugin)}"`);
debug(`register plugin: "${getFunctionName(plugin as () => void)}"`);
plugin(proxy, options);
});
}
Expand Down
2 changes: 0 additions & 2 deletions src/logger.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable @typescript-eslint/no-empty-function */

import { Logger, Options } from './types';

/**
Expand Down
2 changes: 0 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
* https://github.com/DefinitelyTyped/DefinitelyTyped/blob/6f529c6c67a447190f86bfbf894d1061e41e07b7/types/http-proxy-middleware/index.d.ts
*/

/* eslint-disable @typescript-eslint/no-empty-interface */

import type * as http from 'http';
import type * as httpProxy from 'http-proxy';
import type * as net from 'net';
Expand Down
4 changes: 1 addition & 3 deletions src/utils/function.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable @typescript-eslint/ban-types */

export function getFunctionName(fn: Function): string {
export function getFunctionName(fn: () => void): string {
return fn.name || '[anonymous Function]';
}
2 changes: 1 addition & 1 deletion test/types.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable @typescript-eslint/no-empty-function */
/* eslint-disable @typescript-eslint/no-unused-expressions */

import * as express from 'express';
import * as http from 'http';
Expand Down
1 change: 0 additions & 1 deletion test/unit/path-filter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,6 @@ describe('Path Filter', () => {
});

it('should not throw error with Function', () => {
// eslint-disable-next-line @typescript-eslint/no-empty-function
expect(testPathFilter(() => {})).not.toThrowError(Error);
});
});
Expand Down
2 changes: 0 additions & 2 deletions test/unit/path-rewriter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,10 @@ describe('Path rewriting', () => {
});

it('should not throw when function config is provided', () => {
// eslint-disable-next-line @typescript-eslint/no-empty-function
expect(badFn(() => {})).not.toThrowError(Error);
});

it('should not throw when async function config is provided', () => {
// eslint-disable-next-line @typescript-eslint/no-empty-function
expect(badFn(async () => {})).not.toThrowError(Error);
});
});
Expand Down
1 change: 0 additions & 1 deletion test/unit/utils/function.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-empty-function */
import { getFunctionName } from '../../../src/utils/function';

describe('getFunctionName()', () => {
Expand Down
Loading

0 comments on commit 97f9390

Please sign in to comment.