Skip to content

Commit 7541964

Browse files
committed
Fix lint
1 parent 51662a2 commit 7541964

24 files changed

Lines changed: 1200 additions & 7673 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ export function dataUriToBuffer(uri: string): MimeBuffer {
3737
for (let i = 1; i < meta.length; i++) {
3838
if (meta[i] === 'base64') {
3939
base64 = true;
40-
} else if(meta[i]) {
41-
typeFull += `;${ meta[i]}`;
40+
} else if (meta[i]) {
41+
typeFull += `;${meta[i]}`;
4242
if (meta[i].indexOf('charset=') === 0) {
4343
charset = meta[i].substring(8);
4444
}

packages/data-uri-to-buffer/test/data-uri-to-buffer.test.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import assert from 'assert';
22
import dataUriToBuffer from '../src';
33

4-
describe('data-uri-to-buffer', function() {
5-
it('should decode bare-bones Data URIs', function() {
4+
describe('data-uri-to-buffer', function () {
5+
it('should decode bare-bones Data URIs', function () {
66
const uri = 'data:,Hello%2C%20World!';
77

88
const buf = dataUriToBuffer(uri);
@@ -12,15 +12,15 @@ describe('data-uri-to-buffer', function() {
1212
assert.equal('Hello, World!', buf.toString());
1313
});
1414

15-
it('should decode bare-bones "base64" Data URIs', function() {
15+
it('should decode bare-bones "base64" Data URIs', function () {
1616
const uri = 'data:text/plain;base64,SGVsbG8sIFdvcmxkIQ%3D%3D';
1717

1818
const buf = dataUriToBuffer(uri);
1919
assert.equal('text/plain', buf.type);
2020
assert.equal('Hello, World!', buf.toString());
2121
});
2222

23-
it('should decode plain-text Data URIs', function() {
23+
it('should decode plain-text Data URIs', function () {
2424
const html =
2525
'<!DOCTYPE html>' +
2626
'<html lang="en">' +
@@ -40,7 +40,7 @@ describe('data-uri-to-buffer', function() {
4040
// the next 4 tests are from:
4141
// https://bug161965.bugzilla.mozilla.org/attachment.cgi?id=94670&action=view
4242

43-
it('should decode "ISO-8859-8 in Base64" URIs', function() {
43+
it('should decode "ISO-8859-8 in Base64" URIs', function () {
4444
const uri = 'data:text/plain;charset=iso-8859-8-i;base64,+ezl7Q==';
4545

4646
const buf = dataUriToBuffer(uri);
@@ -53,7 +53,7 @@ describe('data-uri-to-buffer', function() {
5353
assert.equal(0xed, buf[3]);
5454
});
5555

56-
it('should decode "ISO-8859-8 in URL-encoding" URIs', function() {
56+
it('should decode "ISO-8859-8 in URL-encoding" URIs', function () {
5757
const uri = 'data:text/plain;charset=iso-8859-8-i,%f9%ec%e5%ed';
5858

5959
const buf = dataUriToBuffer(uri);
@@ -66,7 +66,7 @@ describe('data-uri-to-buffer', function() {
6666
assert.equal(0xed, buf[3]);
6767
});
6868

69-
it('should decode "UTF-8 in Base64" URIs', function() {
69+
it('should decode "UTF-8 in Base64" URIs', function () {
7070
const uri = 'data:text/plain;charset=UTF-8;base64,16nXnNeV150=';
7171

7272
const buf = dataUriToBuffer(uri);
@@ -76,7 +76,7 @@ describe('data-uri-to-buffer', function() {
7676
assert.equal('שלום', buf.toString('utf8'));
7777
});
7878

79-
it('should decode "UTF-8 in URL-encoding" URIs', function() {
79+
it('should decode "UTF-8 in URL-encoding" URIs', function () {
8080
const uri = 'data:text/plain;charset=UTF-8,%d7%a9%d7%9c%d7%95%d7%9d';
8181

8282
const buf = dataUriToBuffer(uri);
@@ -88,7 +88,7 @@ describe('data-uri-to-buffer', function() {
8888

8989
// this next one is from Wikipedia IIRC
9090

91-
it('should decode "base64" Data URIs with newlines', function() {
91+
it('should decode "base64" Data URIs with newlines', function () {
9292
const uri =
9393
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUA\n' +
9494
'AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO\n' +
@@ -104,29 +104,29 @@ describe('data-uri-to-buffer', function() {
104104
);
105105
});
106106

107-
it('should decode a plain-text URI with a space character in it', function() {
107+
it('should decode a plain-text URI with a space character in it', function () {
108108
const uri = 'data:,foo bar';
109109

110110
const buf = dataUriToBuffer(uri);
111111
assert.equal('text/plain', buf.type);
112112
assert.equal('foo bar', buf.toString());
113113
});
114114

115-
it('should decode data with a "," comma char', function() {
115+
it('should decode data with a "," comma char', function () {
116116
const uri = 'data:,a,b';
117117
const buf = dataUriToBuffer(uri);
118118
assert.equal('text/plain', buf.type);
119119
assert.equal('a,b', buf.toString());
120120
});
121121

122-
it('should decode data with traditionally reserved characters like ";"', function() {
122+
it('should decode data with traditionally reserved characters like ";"', function () {
123123
const uri = 'data:,;test';
124124
const buf = dataUriToBuffer(uri);
125125
assert.equal('text/plain', buf.type);
126126
assert.equal(';test', buf.toString());
127127
});
128128

129-
it('should not default to US-ASCII if main type is provided', function() {
129+
it('should not default to US-ASCII if main type is provided', function () {
130130
const uri = 'data:text/plain,abc';
131131
const buf = dataUriToBuffer(uri);
132132
assert.equal('text/plain', buf.type);
@@ -135,7 +135,7 @@ describe('data-uri-to-buffer', function() {
135135
assert.equal('abc', buf.toString());
136136
});
137137

138-
it('should default to text/plain if main type is not provided', function() {
138+
it('should default to text/plain if main type is not provided', function () {
139139
const uri = 'data:;charset=UTF-8,abc';
140140
const buf = dataUriToBuffer(uri);
141141
assert.equal('text/plain', buf.type);
@@ -144,7 +144,7 @@ describe('data-uri-to-buffer', function() {
144144
assert.equal('abc', buf.toString());
145145
});
146146

147-
it('should not allow charset without a leading ;', function() {
147+
it('should not allow charset without a leading ;', function () {
148148
const uri = 'data:charset=UTF-8,abc';
149149
const buf = dataUriToBuffer(uri);
150150
assert.equal('charset=UTF-8', buf.type);
@@ -153,7 +153,7 @@ describe('data-uri-to-buffer', function() {
153153
assert.equal('abc', buf.toString());
154154
});
155155

156-
it('should allow custom media type parameters', function() {
156+
it('should allow custom media type parameters', function () {
157157
const uri = 'data:application/javascript;version=1.8;charset=UTF-8,abc';
158158
const buf = dataUriToBuffer(uri);
159159
assert.equal('application/javascript', buf.type);
@@ -165,7 +165,7 @@ describe('data-uri-to-buffer', function() {
165165
assert.equal('abc', buf.toString());
166166
});
167167

168-
it('should allow base64 annotation anywhere', function() {
168+
it('should allow base64 annotation anywhere', function () {
169169
const uri = 'data:text/plain;base64;charset=UTF-8,YWJj';
170170
const buf = dataUriToBuffer(uri);
171171
assert.equal('text/plain', buf.type);
@@ -174,7 +174,7 @@ describe('data-uri-to-buffer', function() {
174174
assert.equal('abc', buf.toString());
175175
});
176176

177-
it('should parse meta with unnecessary semicolons', function() {
177+
it('should parse meta with unnecessary semicolons', function () {
178178
const uri = 'data:text/plain;;charset=UTF-8;;;base64;;;;,YWJj';
179179
const buf = dataUriToBuffer(uri);
180180
assert.equal('text/plain', buf.type);

packages/degenerator/src/index.ts

Lines changed: 38 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@ import { VM, VMScript } from 'vm2';
1414
* @api public
1515
*/
1616

17-
export function degenerator(
18-
code: string,
19-
_names: DegeneratorNames
20-
): string {
17+
export function degenerator(code: string, _names: DegeneratorNames): string {
2118
if (!Array.isArray(_names)) {
2219
throw new TypeError('an array of async function "names" is required');
2320
}
@@ -124,45 +121,45 @@ export function degenerator(
124121
return generate(ast);
125122
}
126123

127-
export type DegeneratorName = string | RegExp;
128-
export type DegeneratorNames = DegeneratorName[];
129-
export interface CompileOptions extends RunningScriptOptions {
130-
sandbox?: Context;
124+
export type DegeneratorName = string | RegExp;
125+
export type DegeneratorNames = DegeneratorName[];
126+
export interface CompileOptions extends RunningScriptOptions {
127+
sandbox?: Context;
128+
}
129+
export function compile<R = unknown, A extends unknown[] = []>(
130+
code: string,
131+
returnName: string,
132+
names: DegeneratorNames,
133+
options: CompileOptions = {}
134+
): (...args: A) => Promise<R> {
135+
const compiled = degenerator(code, names);
136+
const vm = new VM(options);
137+
const script = new VMScript(`${compiled};${returnName}`, {
138+
filename: options.filename,
139+
});
140+
const fn = vm.run(script);
141+
if (typeof fn !== 'function') {
142+
throw new Error(
143+
`Expected a "function" to be returned for \`${returnName}\`, but got "${typeof fn}"`
144+
);
131145
}
132-
export function compile<R = unknown, A extends unknown[] = []>(
133-
code: string,
134-
returnName: string,
135-
names: DegeneratorNames,
136-
options: CompileOptions = {}
137-
): (...args: A) => Promise<R> {
138-
const compiled = degenerator(code, names);
139-
const vm = new VM(options);
140-
const script = new VMScript(`${compiled};${returnName}`, {
141-
filename: options.filename,
142-
});
143-
const fn = vm.run(script);
144-
if (typeof fn !== "function") {
145-
throw new Error(
146-
`Expected a "function" to be returned for \`${returnName}\`, but got "${typeof fn}"`
147-
);
148-
}
149-
const r = function (this: unknown, ...args: A): Promise<R> {
150-
try {
151-
const p = fn.apply(this, args);
152-
if (typeof p?.then === "function") {
153-
return p;
154-
}
155-
return Promise.resolve(p);
156-
} catch (err) {
157-
return Promise.reject(err);
146+
const r = function (this: unknown, ...args: A): Promise<R> {
147+
try {
148+
const p = fn.apply(this, args);
149+
if (typeof p?.then === 'function') {
150+
return p;
158151
}
159-
};
160-
Object.defineProperty(r, "toString", {
161-
value: fn.toString.bind(fn),
162-
enumerable: false,
163-
});
164-
return r;
165-
}
152+
return Promise.resolve(p);
153+
} catch (err) {
154+
return Promise.reject(err);
155+
}
156+
};
157+
Object.defineProperty(r, 'toString', {
158+
value: fn.toString.bind(fn),
159+
enumerable: false,
160+
});
161+
return r;
162+
}
166163

167164
/**
168165
* Returns `true` if `node` has a matching name to one of the entries in the

packages/get-uri/.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dist

packages/get-uri/src/file.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,16 @@ export const file: GetUriProtocol<FileOptions> = async (
5555

5656
// `fs.ReadStream` takes care of calling `fs.close()` on the
5757
// fd after it's done reading
58-
// @ts-ignore - `@types/node` doesn't allow `null` as file path :/
58+
// @ts-expect-error `@types/node` doesn't allow `null` as file path :/
5959
const rs = createReadStream(null, {
6060
autoClose: true,
6161
...opts,
6262
fd,
6363
}) as FileReadable;
6464
rs.stat = stat;
6565
return rs;
66-
} catch (err: any) {
67-
if (err.code === 'ENOENT') {
66+
} catch (err: unknown) {
67+
if ((err as NodeJS.ErrnoException).code === 'ENOENT') {
6868
throw new NotFoundError();
6969
}
7070
throw err;

packages/get-uri/src/ftp.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ export const ftp: GetUriProtocol<FTPOptions> = async (url, opts = {}) => {
4848
// try the MDTM command first, which is an optional extension command.
4949
try {
5050
lastModified = await client.lastMod(filepath);
51-
} catch (err: any) {
51+
} catch (err: unknown) {
5252
// handle the "file not found" error code
53-
if (err.code === 550) {
53+
if ((err as { code: number }).code === 550) {
5454
throw new NotFoundError();
5555
}
5656
}

packages/get-uri/src/http.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,13 @@ export const http: GetUriProtocol<HttpOptions> = async (url, opts = {}) => {
100100
debug('got %o response status code', code);
101101

102102
// any 2xx response is a "success" code
103-
let type = (code / 100) | 0;
103+
const type = (code / 100) | 0;
104104

105105
// check for a 3xx "redirect" status code
106-
let location = res.headers.location;
106+
const location = res.headers.location;
107107
if (type === 3 && location) {
108108
if (!opts.redirects) opts.redirects = [];
109-
let redirects = opts.redirects;
109+
const redirects = opts.redirects;
110110

111111
if (redirects.length < maxRedirects) {
112112
debug('got a "redirect" status code with Location: %o', location);
@@ -117,10 +117,10 @@ export const http: GetUriProtocol<HttpOptions> = async (url, opts = {}) => {
117117
// hang on to this Response object for the "redirects" Array
118118
redirects.push(res);
119119

120-
let newUri = new URL(location, url.href);
120+
const newUri = new URL(location, url.href);
121121
debug('resolved redirect URL: %o', newUri.href);
122122

123-
let left = maxRedirects - redirects.length;
123+
const left = maxRedirects - redirects.length;
124124
debug('%o more redirects allowed after this one', left);
125125

126126
// check if redirecting to a different protocol

packages/get-uri/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { https } from './https';
1010

1111
const debug = createDebug('get-uri');
1212

13+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
1314
type Protocol<T> = T extends `${infer Protocol}:${infer _}` ? Protocol : never;
1415

1516
export type GetUriProtocol<T> = (parsed: URL, opts?: T) => Promise<Readable>;
@@ -72,5 +73,5 @@ export async function getUri<Uri extends string>(
7273
}
7374

7475
const getter = protocols[protocol];
75-
return getter(url, opts as any);
76+
return getter(url, opts as never);
7677
}

packages/get-uri/test/ftp.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ describe('get-uri', () => {
1111

1212
beforeAll(async () => {
1313
server = new FtpServer('127.0.0.1', {
14-
// @ts-ignore
14+
// @ts-expect-error ...
1515
logLevel: -1,
1616
getInitialCwd(_socket, fn) {
17-
// @ts-expect-error
17+
// @ts-expect-error ...
1818
fn?.(undefined, '/');
1919
},
2020
getRoot() {
@@ -24,21 +24,21 @@ describe('get-uri', () => {
2424

2525
server.on('client:connected', (conn) => {
2626
let username: string;
27-
// @ts-expect-error
28-
conn.on('command:user', (user, success, failure) => {
27+
// @ts-expect-error ...
28+
conn.on('command:user', (user, success) => {
2929
username = user;
3030
success();
3131
});
32-
// @ts-expect-error
33-
conn.on('command:pass', (pass, success, failure) => {
32+
// @ts-expect-error ...
33+
conn.on('command:pass', (pass, success) => {
3434
success(username);
3535
});
3636
});
3737

3838
port = await new Promise<number>((r) =>
39-
// @ts-expect-error
39+
// @ts-expect-error ...
4040
server.listen(0, () => {
41-
// @ts-expect-error
41+
// @ts-expect-error ...
4242
r(server.server.address().port);
4343
})
4444
);

packages/get-uri/test/http.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ describe('get-uri', () => {
1616
// setup target HTTP server
1717
server = http.createServer(st(__dirname));
1818
await listen(server);
19-
// @ts-expect-error
19+
// @ts-expect-error `port` definitely exists
2020
port = server.address().port;
2121
});
2222

0 commit comments

Comments
 (0)