Skip to content

Commit

Permalink
ci(eslint): migrate to eslint + prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
chimurai committed Aug 30, 2020
1 parent c8cd3ce commit 86d9df2
Show file tree
Hide file tree
Showing 13 changed files with 460 additions and 108 deletions.
18 changes: 18 additions & 0 deletions .eslintrc.js
@@ -0,0 +1,18 @@
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 2020,
sourceType: 'module',
},
extends: [
'plugin:@typescript-eslint/recommended',
'prettier/@typescript-eslint',
'plugin:prettier/recommended',
],
rules: {
'@typescript-eslint/no-unused-vars': [
'error',
{ vars: 'all', args: 'none', ignoreRestSiblings: false },
],
},
};
35 changes: 21 additions & 14 deletions .github/workflows/lint.yml
Expand Up @@ -3,20 +3,27 @@ name: Lint
on: ["push","pull_request"]

jobs:
build:
name: Lint

run-linters:
name: Run linters
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [14.x]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: yarn install
- run: yarn lint
- name: Check out Git repository
uses: actions/checkout@v2

- name: Set up Node.js
uses: actions/setup-node@v1
with:
node-version: 14

# ESLint and Prettier must be in `package.json`
- name: Install Node.js dependencies
run: yarn install

- name: Run linters
uses: wearerequired/lint-action@v1
with:
github_token: ${{ secrets.github_token }}
# Enable linters
eslint: true
prettier: true
1 change: 1 addition & 0 deletions .lintstagedrc
@@ -1,3 +1,4 @@
{
"**/*.{js,ts,md}": "prettier --write",
"**/*.{js,ts}": "eslint --fix",
}
18 changes: 12 additions & 6 deletions package.json
Expand Up @@ -9,10 +9,12 @@
],
"scripts": {
"clean": "rm -rf dist && rm -rf coverage",
"lint": "yarn lint:prettier && yarn lint:tslint",
"lint:prettier": "prettier --check \"**/*.{js,ts,md}\"",
"lint:tslint": "yarn tslint -c tslint.json '{lib,test}/**/*.ts'",
"lint:fix": "prettier --write \"**/*.{js,ts,md}\"",
"lint": "yarn prettier && yarn eslint",
"lint:fix": "yarn prettier:fix && yarn eslint:fix",
"lint:eslint": "eslint '{lib,test}/**/*.ts'",
"lint:eslint:fix": "yarn eslint --fix",
"lint:prettier": "prettier --list-different \"**/*.{js,ts,md}\"",
"lint:prettier:fix": "prettier --write \"**/*.{js,ts,md}\"",
"build": "tsc",
"pretest": "yarn build",
"test": "jest",
Expand Down Expand Up @@ -55,8 +57,14 @@
"@types/micromatch": "^4.0.1",
"@types/node": "^14.6.2",
"@types/supertest": "^2.0.10",
"@types/ws": "^7.2.6",
"@typescript-eslint/eslint-plugin": "^3.10.1",
"@typescript-eslint/parser": "^3.10.1",
"browser-sync": "^2.26.12",
"connect": "^3.7.0",
"eslint": "^7.7.0",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-prettier": "^3.1.4",
"express": "^4.17.1",
"husky": "^4.2.5",
"jest": "^26.4.2",
Expand All @@ -66,8 +74,6 @@
"prettier": "^2.1.1",
"supertest": "^4.0.2",
"ts-jest": "^26.3.0",
"tslint": "^6.1.3",
"tslint-config-prettier": "^1.18.0",
"typescript": "^4.0.2",
"ws": "^7.3.1"
},
Expand Down
5 changes: 3 additions & 2 deletions test/e2e/_utils.ts
@@ -1,14 +1,15 @@
import * as express from 'express';
import { Express, RequestHandler } from 'express';

export { createProxyMiddleware } from '../../dist/index';

export function createApp(middleware) {
export function createApp(middleware: RequestHandler): Express {
const app = express();
app.use(middleware);
return app;
}

export function createAppWithPath(path, middleware) {
export function createAppWithPath(path: string | string[], middleware: RequestHandler): Express {
const app = express();
app.use(path, middleware);
return app;
Expand Down
6 changes: 2 additions & 4 deletions test/e2e/express-router.spec.ts
Expand Up @@ -12,16 +12,14 @@ describe('Usage in Express', () => {
});

afterEach(() => {
// tslint:disable-next-line: no-unused-expression
server && server.close();
server?.close();
});

// https://github.com/chimurai/http-proxy-middleware/issues/94
describe('Express Sub Route', () => {
beforeEach(() => {
// sub route config
// @ts-ignore: Only a void function can be called with the 'new' keyword.ts(2350)
const sub = new express.Router();
const sub = express.Router();

function filter(pathname, req) {
const urlFilter = new RegExp('^/sub/api');
Expand Down
8 changes: 4 additions & 4 deletions test/e2e/http-proxy-middleware.spec.ts
Expand Up @@ -19,19 +19,19 @@ describe('E2E http-proxy-middleware', () => {
beforeEach(() => {
isSkipped = false;

let middleware;

const mockReq = { url: '/foo/bar', originalUrl: '/foo/bar' };
const mockRes = {};
const mockNext = () => {
// mockNext will be called when request is not proxied
isSkipped = true;
};

middleware = createProxyMiddleware('/api', {
const middleware = createProxyMiddleware('/api', {
target: `http://localhost:8000`,
});
middleware(mockReq, mockRes, mockNext);

// eslint-disable-next-line @typescript-eslint/no-explicit-any
middleware(mockReq as any, mockRes as any, mockNext);
});

it('should not proxy requests when request url does not match context', () => {
Expand Down
5 changes: 0 additions & 5 deletions test/e2e/websocket.spec.ts
Expand Up @@ -21,7 +21,6 @@ describe('E2E WebSocket proxy', () => {

proxyServer = express().use(proxy).listen(3000);

// @ts-ignore: Expected arguments error
wss = new WebSocketServer({ port: 9000 });

wss.on('connection', function connection(websocket) {
Expand All @@ -47,7 +46,6 @@ describe('E2E WebSocket proxy', () => {
// do a second http request to make
// sure only 1 listener subscribes to upgrade request
http.get('http://localhost:3000/', () => {
// @ts-ignore: Expected arguments error
ws = new WebSocket('ws://localhost:3000/socket');

ws.on('message', function incoming(message) {
Expand All @@ -71,7 +69,6 @@ describe('E2E WebSocket proxy', () => {
beforeEach((done) => {
proxyServer.on('upgrade', proxy.upgrade);

// @ts-ignore: Expected arguments error
ws = new WebSocket('ws://localhost:3000/socket');

ws.on('message', function incoming(message) {
Expand Down Expand Up @@ -104,7 +101,6 @@ describe('E2E WebSocket proxy', () => {
beforeEach((done) => {
proxyServer.on('upgrade', proxy.upgrade);

// @ts-ignore: Expected arguments error
ws = new WebSocket('ws://localhost:3000/socket');

ws.on('message', function incoming(message) {
Expand Down Expand Up @@ -138,7 +134,6 @@ describe('E2E WebSocket proxy', () => {
beforeEach((done) => {
proxyServer.on('upgrade', proxy.upgrade);

// @ts-ignore: Expected arguments error
ws = new WebSocket('ws://localhost:3000/socket');

ws.on('message', function incoming(message) {
Expand Down
12 changes: 6 additions & 6 deletions test/types.spec.ts
Expand Up @@ -118,39 +118,39 @@ describe('http-proxy-middleware TypeScript Types', () => {

describe('HPM http-proxy events', () => {
it('should have onError type', () => {
// tslint:disable no-empty
// eslint-disable-next-line @typescript-eslint/no-empty-function
options = { onError: (err, req, res) => {} };
expect(options).toBeDefined();
});

it('should have onProxyReq type', () => {
// tslint:disable no-empty
// eslint-disable-next-line @typescript-eslint/no-empty-function
options = { onProxyReq: (proxyReq, req, res) => {} };
expect(options).toBeDefined();
});

it('should have onProxyRes type', () => {
// tslint:disable no-empty
// eslint-disable-next-line @typescript-eslint/no-empty-function
options = { onProxyRes: (proxyRes, req, res) => {} };
expect(options).toBeDefined();
});

it('should have onProxyReqWs type', () => {
options = {
// tslint:disable no-empty
// eslint-disable-next-line @typescript-eslint/no-empty-function
onProxyReqWs: (proxyReq, req, socket, opts, head) => {},
};
expect(options).toBeDefined();
});

it('should have onOpen type', () => {
// tslint:disable no-empty
// eslint-disable-next-line @typescript-eslint/no-empty-function
options = { onOpen: (proxySocket) => {} };
expect(options).toBeDefined();
});

it('should have onClose type', () => {
// tslint:disable no-empty
// eslint-disable-next-line @typescript-eslint/no-empty-function
options = { onClose: (res, socket, head) => {} };
expect(options).toBeDefined();
});
Expand Down
2 changes: 1 addition & 1 deletion test/unit/context-matcher.spec.ts
Expand Up @@ -257,7 +257,7 @@ describe('Context Matching', () => {
});

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

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

it('should not throw when async function config is provided', () => {
// tslint:disable-next-line: no-empty
// eslint-disable-next-line @typescript-eslint/no-empty-function
expect(badFn(async () => {})).not.toThrowError(Error);
});
});
Expand Down
12 changes: 0 additions & 12 deletions tslint.json

This file was deleted.

0 comments on commit 86d9df2

Please sign in to comment.