Skip to content

Commit a0e75fc

Browse files
authored
ci(eslint): migrate to eslint + prettier (#468)
1 parent 00d9dca commit a0e75fc

21 files changed

+722
-206
lines changed

.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dist/*

.eslintrc.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
module.exports = {
2+
parser: '@typescript-eslint/parser',
3+
parserOptions: {
4+
ecmaVersion: 2020,
5+
sourceType: 'module',
6+
},
7+
extends: ['plugin:@typescript-eslint/recommended', 'plugin:prettier/recommended'],
8+
rules: {
9+
'@typescript-eslint/no-unused-vars': [
10+
'error',
11+
{ vars: 'all', args: 'none', ignoreRestSiblings: false },
12+
],
13+
'prettier/prettier': 'warn',
14+
},
15+
overrides: [
16+
{
17+
files: ['examples/**/*.js'],
18+
rules: {
19+
'@typescript-eslint/no-var-requires': 'off',
20+
},
21+
},
22+
],
23+
};

.github/workflows/coveralls.yml

+14-16
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,25 @@
1-
on: ["push","pull_request"]
1+
on: ['push', 'pull_request']
22

33
name: Coveralls
44

55
jobs:
6-
76
build:
87
name: coveralls/build
98
runs-on: ubuntu-latest
109
steps:
10+
- uses: actions/checkout@master
1111

12-
- uses: actions/checkout@master
13-
14-
- name: Use Node.js 14.x
15-
uses: actions/setup-node@master
16-
with:
17-
node-version: 14.x
12+
- name: Use Node.js 14.x
13+
uses: actions/setup-node@master
14+
with:
15+
node-version: 14.x
1816

19-
- name: yarn install, coverage
20-
run: |
21-
yarn install
22-
yarn coverage
17+
- name: yarn install, coverage
18+
run: |
19+
yarn install
20+
yarn coverage
2321
24-
- name: Coveralls
25-
uses: coverallsapp/github-action@master
26-
with:
27-
github-token: ${{ secrets.github_token }}
22+
- name: Coveralls
23+
uses: coverallsapp/github-action@master
24+
with:
25+
github-token: ${{ secrets.github_token }}

.github/workflows/lint.yml

+10-15
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,17 @@
11
name: Lint
22

3-
on: ["push","pull_request"]
3+
on: ['push', 'pull_request']
44

55
jobs:
6-
build:
7-
name: Lint
8-
6+
run-linters:
7+
name: Run linters
98
runs-on: ubuntu-latest
109

11-
strategy:
12-
matrix:
13-
node-version: [14.x]
14-
1510
steps:
16-
- uses: actions/checkout@v2
17-
- name: Use Node.js ${{ matrix.node-version }}
18-
uses: actions/setup-node@v2
19-
with:
20-
node-version: ${{ matrix.node-version }}
21-
- run: yarn install
22-
- run: yarn lint
11+
- uses: actions/checkout@v2
12+
- name: Use Node.js ${{ matrix.node-version }}
13+
uses: actions/setup-node@v2
14+
with:
15+
node-version: ${{ matrix.node-version }}
16+
- run: yarn install
17+
- run: yarn lint

.github/workflows/test.yml

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: Test
22

3-
on: ["push","pull_request"]
3+
on: ['push', 'pull_request']
44

55
jobs:
66
build:
@@ -13,10 +13,10 @@ jobs:
1313
node-version: [10.x, 12.x, 14.x]
1414

1515
steps:
16-
- uses: actions/checkout@v2
17-
- name: Use Node.js ${{ matrix.node-version }}
18-
uses: actions/setup-node@v2
19-
with:
20-
node-version: ${{ matrix.node-version }}
21-
- run: yarn install
22-
- run: yarn test
16+
- uses: actions/checkout@v2
17+
- name: Use Node.js ${{ matrix.node-version }}
18+
uses: actions/setup-node@v2
19+
with:
20+
node-version: ${{ matrix.node-version }}
21+
- run: yarn install
22+
- run: yarn test

.lintstagedrc

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"**/*.{js,ts,md}": "prettier --write",
2+
"**/*.{js,ts,md,yml,json,html}": "prettier --write",
3+
"**/*.{js,ts}": "eslint --fix",
34
}

.travis.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ dist: bionic
22
sudo: false
33
language: node_js
44
node_js:
5-
- 'stable'
6-
- '12'
7-
- '10'
5+
- 'stable'
6+
- '12'
7+
- '10'
88
cache: yarn
99
stages:
1010
- lint

.vscode/settings.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
{
2-
"deno.enable": false
3-
}
2+
"deno.enable": false,
3+
"editor.codeActionsOnSave": {
4+
"source.fixAll.eslint": true
5+
}
6+
}

examples/websocket/index.html

+61-56
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,72 @@
11
<!DOCTYPE html>
22
<html lang="en">
3-
<head>
4-
<meta charset="UTF-8">
3+
<head>
4+
<meta charset="UTF-8" />
55
<title>http-proxy-middleware - WebSocket example</title>
66
<style>
7-
fieldset {
8-
border: 0;
9-
}
10-
label {
11-
display: inline-block;
12-
width: 5em;
13-
vertical-align: top;
14-
}
15-
code {
16-
background-color: #eee;
17-
}
7+
fieldset {
8+
border: 0;
9+
}
10+
label {
11+
display: inline-block;
12+
width: 5em;
13+
vertical-align: top;
14+
}
15+
code {
16+
background-color: #eee;
17+
}
1818
</style>
19-
</head>
20-
21-
<body>
19+
</head>
2220

21+
<body>
2322
<h2>WebSocket demo</h2>
2423

25-
<p>
26-
Proxy <code>ws://localhost:3000</code> to <code>ws://echo.websocket.org</code>
27-
</p>
24+
<p>Proxy <code>ws://localhost:3000</code> to <code>ws://echo.websocket.org</code></p>
2825

2926
<fieldset id="configuration">
30-
<p>
31-
<label for="location">location:</label>
32-
<input id="location" type="text" value="ws://localhost:3000">
33-
<button id="connectBtn">connect</button>
34-
<button id="disconnectBtn" disabled="disabled">disconnect</button>
35-
</p>
27+
<p>
28+
<label for="location">location:</label>
29+
<input id="location" type="text" value="ws://localhost:3000" />
30+
<button id="connectBtn">connect</button>
31+
<button id="disconnectBtn" disabled="disabled">disconnect</button>
32+
</p>
3633
</fieldset>
3734
<fieldset id="messaging" disabled="disabled">
38-
<p>
39-
<label for="message">message:</label>
40-
<input type="text" id="message" value="Hello WebSocket">
41-
<button id="sendBtn">send</button>
42-
</p>
43-
<p>
44-
<label for="logger">log:</label>
45-
<textarea id="logger" cols="30" rows="10"></textarea>
46-
</p>
35+
<p>
36+
<label for="message">message:</label>
37+
<input type="text" id="message" value="Hello WebSocket" />
38+
<button id="sendBtn">send</button>
39+
</p>
40+
<p>
41+
<label for="logger">log:</label>
42+
<textarea id="logger" cols="30" rows="10"></textarea>
43+
</p>
4744
</fieldset>
4845

4946
<script>
50-
window.onload = function () {
47+
window.onload = function () {
5148
// elements
5249
const configuration = document.getElementById('configuration');
53-
const location = document.getElementById('location');
54-
const connectBtn = document.getElementById('connectBtn');
50+
const location = document.getElementById('location');
51+
const connectBtn = document.getElementById('connectBtn');
5552
const disconnectBtn = document.getElementById('disconnectBtn');
56-
const messaging = document.getElementById('messaging');
57-
const message = document.getElementById('message');
58-
const sendBtn = document.getElementById('sendBtn');
59-
const logger = document.getElementById('logger');
53+
const messaging = document.getElementById('messaging');
54+
const message = document.getElementById('message');
55+
const sendBtn = document.getElementById('sendBtn');
56+
const logger = document.getElementById('logger');
6057

6158
// ws
6259
let socket;
6360

64-
connectBtn.onclick = () => { connect(); }
65-
disconnectBtn.onclick = () => { disconnect(); }
66-
sendBtn.onclick = () => { sendMessage(message.value); }
61+
connectBtn.onclick = () => {
62+
connect();
63+
};
64+
disconnectBtn.onclick = () => {
65+
disconnect();
66+
};
67+
sendBtn.onclick = () => {
68+
sendMessage(message.value);
69+
};
6770

6871
function connect() {
6972
setupSocket(location.value);
@@ -79,35 +82,37 @@ <h2>WebSocket demo</h2>
7982
function sendMessage(val) {
8083
log('SEND: ' + val);
8184
socket.send(val);
82-
};
85+
}
8386

8487
function setupSocket(url) {
8588
socket = new WebSocket(url);
8689
socket.addEventListener('open', () => {
8790
log('CONNECTED');
88-
})
91+
});
8992
socket.addEventListener('close', () => {
9093
log('DISCONNECTED');
91-
})
92-
socket.addEventListener('error', () => { log('SOCKET ERROR OCCURED'); })
93-
socket.addEventListener('message', (msg) => { log('RECEIVED:' + msg.data); })
94+
});
95+
socket.addEventListener('error', () => {
96+
log('SOCKET ERROR OCCURED');
97+
});
98+
socket.addEventListener('message', (msg) => {
99+
log('RECEIVED:' + msg.data);
100+
});
94101
}
95102

96-
function log (message) {
103+
function log(message) {
97104
logger.value = logger.value + message + '\n';
98105
logger.scrollTop = logger.scrollHeight; // scroll to bottom
99106
}
100107

101108
function toggleControls() {
102-
[connectBtn, disconnectBtn, messaging].forEach(el => toggleEnabled(el))
109+
[connectBtn, disconnectBtn, messaging].forEach((el) => toggleEnabled(el));
103110
}
104111

105112
function toggleEnabled(el) {
106-
el.disabled = (el.disabled) ? false : true;
113+
el.disabled = el.disabled ? false : true;
107114
}
108-
109-
}
115+
};
110116
</script>
111-
112-
</body>
117+
</body>
113118
</html>

package.json

+12-6
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99
],
1010
"scripts": {
1111
"clean": "rm -rf dist && rm -rf coverage",
12-
"lint": "yarn lint:prettier && yarn lint:tslint",
13-
"lint:prettier": "prettier --check \"**/*.{js,ts,md}\"",
14-
"lint:tslint": "yarn tslint -c tslint.json '{lib,test}/**/*.ts'",
15-
"lint:fix": "prettier --write \"**/*.{js,ts,md}\"",
12+
"lint": "yarn prettier && yarn eslint",
13+
"lint:fix": "yarn prettier:fix && yarn eslint:fix",
14+
"eslint": "eslint '{src,test}/**/*.ts'",
15+
"eslint:fix": "yarn eslint --fix",
16+
"prettier": "prettier --list-different \"**/*.{js,ts,md,yml,json,html}\"",
17+
"prettier:fix": "prettier --write \"**/*.{js,ts,md,yml,json,html}\"",
1618
"build": "tsc",
1719
"pretest": "yarn build",
1820
"test": "jest",
@@ -55,8 +57,14 @@
5557
"@types/micromatch": "^4.0.1",
5658
"@types/node": "^14.14.37",
5759
"@types/supertest": "^2.0.10",
60+
"@types/ws": "^7.4.0",
61+
"@typescript-eslint/eslint-plugin": "^4.19.0",
62+
"@typescript-eslint/parser": "^4.19.0",
5863
"browser-sync": "^2.26.14",
5964
"connect": "^3.7.0",
65+
"eslint": "^7.23.0",
66+
"eslint-config-prettier": "^8.1.0",
67+
"eslint-plugin-prettier": "^3.3.1",
6068
"express": "^4.17.1",
6169
"husky": "^4.3.0",
6270
"jest": "^26.6.3",
@@ -66,8 +74,6 @@
6674
"prettier": "^2.2.1",
6775
"supertest": "^6.1.3",
6876
"ts-jest": "^26.5.4",
69-
"tslint": "^6.1.3",
70-
"tslint-config-prettier": "^1.18.0",
7177
"typescript": "^4.2.3",
7278
"ws": "^7.4.4"
7379
},

src/logger.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* eslint-disable prefer-rest-params */
2+
13
import * as util from 'util';
24

35
let loggerInstance;

src/types.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* eslint-disable @typescript-eslint/no-empty-interface */
2+
13
import * as express from 'express';
24
import * as http from 'http';
35
import * as httpProxy from 'http-proxy';

test/e2e/_utils.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import * as express from 'express';
2+
import { Express, RequestHandler } from 'express';
23

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

5-
export function createApp(middleware) {
6+
export function createApp(middleware: RequestHandler): Express {
67
const app = express();
78
app.use(middleware);
89
return app;
910
}
1011

11-
export function createAppWithPath(path, middleware) {
12+
export function createAppWithPath(path: string | string[], middleware: RequestHandler): Express {
1213
const app = express();
1314
app.use(path, middleware);
1415
return app;

0 commit comments

Comments
 (0)