Skip to content

Commit 5fd2546

Browse files
authoredDec 6, 2024··
Run format check in CI (#355)
1 parent 77c3599 commit 5fd2546

File tree

24 files changed

+168
-107
lines changed

24 files changed

+168
-107
lines changed
 

‎.github/workflows/test.yml

+23
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,29 @@ jobs:
7171

7272
- name: Run Lint
7373
run: pnpm lint
74+
id: lint
75+
continue-on-error: true
76+
77+
- name: Run Format
78+
run: pnpm format:check
79+
id: format
80+
continue-on-error: true
81+
82+
- name: Check Results
83+
run: |
84+
declare -A OUTCOMES=(
85+
[lint]="${{ steps.lint.outcome }}"
86+
[format]="${{ steps.format.outcome }}"
87+
)
88+
STATUS=0
89+
for STEP in "${!OUTCOMES[@]}"; do
90+
OUTCOME="${OUTCOMES[$STEP]}"
91+
echo "$STEP: $OUTCOME"
92+
if [ "$OUTCOME" != "success" ]; then
93+
STATUS=1
94+
fi
95+
done
96+
exit $STATUS
7497
7598
e2e:
7699
name: E2E

‎.prettierignore

+3
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
packages/*/dist
22
packages/degenerator/test/*.js
3+
*.md
4+
*.pac
5+
pnpm-lock.yaml

‎.prettierrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"singleQuote": true
2+
"singleQuote": true
33
}

‎package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"lint": "turbo run lint",
88
"test": "turbo run test",
99
"test-e2e": "turbo run test-e2e",
10-
"format": "prettier --write \"**/*.{ts,js,mjs}\"",
10+
"format": "prettier --write .",
11+
"format:check": "prettier --check .",
1112
"ci:version": "changeset version && pnpm install --no-frozen-lockfile",
1213
"ci:publish": "pnpm publish -r && changeset tag"
1314
},

‎packages/agent-base/tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"extends": "tsconfig/base.json",
33
"compilerOptions": {
4-
"outDir": "dist",
4+
"outDir": "dist"
55
},
66
"include": ["src"],
77
"exclude": ["node_modules"]

‎packages/data-uri-to-buffer/src/common.ts

+46-42
Original file line numberDiff line numberDiff line change
@@ -15,55 +15,59 @@ export interface IBufferConversions {
1515
*
1616
* @param {String} uri Data URI to turn into a Buffer instance
1717
*/
18-
export const makeDataUriToBuffer = (convert: IBufferConversions) => (uri: string | URL): ParsedDataURI => {
19-
uri = String(uri);
18+
export const makeDataUriToBuffer =
19+
(convert: IBufferConversions) =>
20+
(uri: string | URL): ParsedDataURI => {
21+
uri = String(uri);
2022

21-
if (!/^data:/i.test(uri)) {
22-
throw new TypeError(
23-
'`uri` does not appear to be a Data URI (must begin with "data:")'
24-
);
25-
}
23+
if (!/^data:/i.test(uri)) {
24+
throw new TypeError(
25+
'`uri` does not appear to be a Data URI (must begin with "data:")'
26+
);
27+
}
2628

27-
// strip newlines
28-
uri = uri.replace(/\r?\n/g, '');
29+
// strip newlines
30+
uri = uri.replace(/\r?\n/g, '');
2931

30-
// split the URI up into the "metadata" and the "data" portions
31-
const firstComma = uri.indexOf(',');
32-
if (firstComma === -1 || firstComma <= 4) {
33-
throw new TypeError('malformed data: URI');
34-
}
32+
// split the URI up into the "metadata" and the "data" portions
33+
const firstComma = uri.indexOf(',');
34+
if (firstComma === -1 || firstComma <= 4) {
35+
throw new TypeError('malformed data: URI');
36+
}
3537

36-
// remove the "data:" scheme and parse the metadata
37-
const meta = uri.substring(5, firstComma).split(';');
38+
// remove the "data:" scheme and parse the metadata
39+
const meta = uri.substring(5, firstComma).split(';');
3840

39-
let charset = '';
40-
let base64 = false;
41-
const type = meta[0] || 'text/plain';
42-
let typeFull = type;
43-
for (let i = 1; i < meta.length; i++) {
44-
if (meta[i] === 'base64') {
45-
base64 = true;
46-
} else if (meta[i]) {
47-
typeFull += `;${meta[i]}`;
48-
if (meta[i].indexOf('charset=') === 0) {
49-
charset = meta[i].substring(8);
41+
let charset = '';
42+
let base64 = false;
43+
const type = meta[0] || 'text/plain';
44+
let typeFull = type;
45+
for (let i = 1; i < meta.length; i++) {
46+
if (meta[i] === 'base64') {
47+
base64 = true;
48+
} else if (meta[i]) {
49+
typeFull += `;${meta[i]}`;
50+
if (meta[i].indexOf('charset=') === 0) {
51+
charset = meta[i].substring(8);
52+
}
5053
}
5154
}
52-
}
53-
// defaults to US-ASCII only if type is not provided
54-
if (!meta[0] && !charset.length) {
55-
typeFull += ';charset=US-ASCII';
56-
charset = 'US-ASCII';
57-
}
55+
// defaults to US-ASCII only if type is not provided
56+
if (!meta[0] && !charset.length) {
57+
typeFull += ';charset=US-ASCII';
58+
charset = 'US-ASCII';
59+
}
5860

59-
// get the encoded data portion and decode URI-encoded chars
60-
const data = unescape(uri.substring(firstComma + 1));
61-
const buffer = base64 ? convert.base64ToArrayBuffer(data) : convert.stringToBuffer(data);
61+
// get the encoded data portion and decode URI-encoded chars
62+
const data = unescape(uri.substring(firstComma + 1));
63+
const buffer = base64
64+
? convert.base64ToArrayBuffer(data)
65+
: convert.stringToBuffer(data);
6266

63-
return {
64-
type,
65-
typeFull,
66-
charset,
67-
buffer,
67+
return {
68+
type,
69+
typeFull,
70+
charset,
71+
buffer,
72+
};
6873
};
69-
}

‎packages/data-uri-to-buffer/src/index.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { makeDataUriToBuffer } from './common';
22

3-
export type { ParsedDataURI } from './common';
3+
export type { ParsedDataURI } from './common';
44

55
function base64ToArrayBuffer(base64: string) {
66
const chars =
@@ -55,4 +55,7 @@ function stringToBuffer(str: string): ArrayBuffer {
5555
*
5656
* @param {String} uri Data URI to turn into a Buffer instance
5757
*/
58-
export const dataUriToBuffer = makeDataUriToBuffer({ stringToBuffer, base64ToArrayBuffer });
58+
export const dataUriToBuffer = makeDataUriToBuffer({
59+
stringToBuffer,
60+
base64ToArrayBuffer,
61+
});

‎packages/data-uri-to-buffer/src/node.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { makeDataUriToBuffer } from './common';
22

3-
export type { ParsedDataURI } from './common';
3+
export type { ParsedDataURI } from './common';
44

55
function nodeBuffertoArrayBuffer(nodeBuf: Buffer) {
66
if (nodeBuf.byteLength === nodeBuf.buffer.byteLength) {
@@ -25,4 +25,7 @@ function stringToBuffer(str: string): ArrayBuffer {
2525
*
2626
* @param {String} uri Data URI to turn into a Buffer instance
2727
*/
28-
export const dataUriToBuffer = makeDataUriToBuffer({ stringToBuffer, base64ToArrayBuffer });
28+
export const dataUriToBuffer = makeDataUriToBuffer({
29+
stringToBuffer,
30+
base64ToArrayBuffer,
31+
});

‎packages/degenerator/tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"extends": "tsconfig/base.json",
33
"compilerOptions": {
4-
"outDir": "dist",
4+
"outDir": "dist"
55
},
66
"include": ["src"],
77
"exclude": ["node_modules"]

‎packages/get-uri/tsconfig.json

+1-4
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@
88
"outDir": "dist",
99
"sourceMap": true,
1010
"declaration": true,
11-
"typeRoots": [
12-
"./@types",
13-
"./node_modules/@types"
14-
]
11+
"typeRoots": ["./@types", "./node_modules/@types"]
1512
},
1613
"include": ["src/**/*"],
1714
"exclude": ["node_modules"]

‎packages/http-proxy-agent/tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"extends": "tsconfig/base.json",
33
"compilerOptions": {
4-
"outDir": "dist",
4+
"outDir": "dist"
55
},
66
"include": ["src"],
77
"exclude": ["node_modules"]

‎packages/https-proxy-agent/test/e2e.test.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ interface NordVPNServer {
99
locations: {
1010
country: {
1111
code: string;
12-
}
13-
12+
};
1413
}[];
1514
technologies: {
1615
identifier: string;

‎packages/https-proxy-agent/tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"extends": "tsconfig/base.json",
33
"compilerOptions": {
4-
"outDir": "dist",
4+
"outDir": "dist"
55
},
66
"include": ["src"],
77
"exclude": ["node_modules"]

‎packages/pac-proxy-agent/test/test.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,10 @@ describe('PacProxyAgent', () => {
188188
)}`;
189189
const agent = new PacProxyAgent(uri);
190190

191-
const res = await req(new URL('/test', httpServerUrl), { agent, headers: { upgrade: 'websocket' } });
191+
const res = await req(new URL('/test', httpServerUrl), {
192+
agent,
193+
headers: { upgrade: 'websocket' },
194+
});
192195
const data = await json(res);
193196
assert.equal(httpServerUrl.host, data.host);
194197
assert(!('via' in data)); // Used CONNECT rather than plain HTTP proxy

‎packages/pac-proxy-agent/tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"extends": "tsconfig/base.json",
33
"compilerOptions": {
4-
"outDir": "dist",
4+
"outDir": "dist"
55
},
66
"include": ["src"],
77
"exclude": ["node_modules"]

‎packages/pac-resolver/src/ip.ts

+29-23
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,35 @@ export const ip = {
77
// Default to `ipv4`
88
const family = normalizeFamily();
99

10-
const all = Object.values(interfaces).map((addrs = []) => {
11-
const addresses = addrs.filter((details) => {
12-
const detailsFamily = normalizeFamily(details.family);
13-
if (detailsFamily !== family || ip.isLoopback(details.address)) {
14-
return false;
15-
}
16-
return true;
17-
18-
});
19-
20-
return addresses.length ? addresses[0].address : undefined;
21-
}).filter(Boolean);
22-
23-
return !all.length ? ip.loopback(family) : all[0] as string;
10+
const all = Object.values(interfaces)
11+
.map((addrs = []) => {
12+
const addresses = addrs.filter((details) => {
13+
const detailsFamily = normalizeFamily(details.family);
14+
if (
15+
detailsFamily !== family ||
16+
ip.isLoopback(details.address)
17+
) {
18+
return false;
19+
}
20+
return true;
21+
});
22+
23+
return addresses.length ? addresses[0].address : undefined;
24+
})
25+
.filter(Boolean);
26+
27+
return !all.length ? ip.loopback(family) : (all[0] as string);
2428
},
2529

2630
isLoopback(addr: string): boolean {
27-
return /^(::f{4}:)?127\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/
28-
.test(addr)
29-
|| /^fe80::1$/.test(addr)
30-
|| /^::1$/.test(addr)
31-
|| /^::$/.test(addr);
31+
return (
32+
/^(::f{4}:)?127\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/.test(
33+
addr
34+
) ||
35+
/^fe80::1$/.test(addr) ||
36+
/^::1$/.test(addr) ||
37+
/^::$/.test(addr)
38+
);
3239
},
3340

3441
loopback(family: IpFamily): string {
@@ -40,8 +47,7 @@ export const ip = {
4047
}
4148

4249
return family === 'ipv4' ? '127.0.0.1' : 'fe80::1';
43-
}
44-
50+
},
4551
};
4652

4753
function normalizeFamily(family?: unknown): IpFamily {
@@ -51,7 +57,7 @@ function normalizeFamily(family?: unknown): IpFamily {
5157
if (family === 6) {
5258
return 'ipv6';
5359
}
54-
return family ? (family as string).toLowerCase() as IpFamily : 'ipv4';
60+
return family ? ((family as string).toLowerCase() as IpFamily) : 'ipv4';
5561
}
5662

57-
type IpFamily = 'ipv4' | 'ipv6'
63+
type IpFamily = 'ipv4' | 'ipv6';

‎packages/pac-resolver/tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"extends": "tsconfig/base.json",
33
"compilerOptions": {
4-
"outDir": "dist",
4+
"outDir": "dist"
55
},
66
"include": ["src"],
77
"exclude": ["node_modules"]

0 commit comments

Comments
 (0)
Please sign in to comment.