Skip to content

Commit e9c860e

Browse files
committed
chore: migrate ESLint config
1 parent 944509a commit e9c860e

9 files changed

Lines changed: 89 additions & 57 deletions

File tree

.eslintignore

Lines changed: 0 additions & 6 deletions
This file was deleted.

.eslintrc.json

Lines changed: 0 additions & 17 deletions
This file was deleted.

eslint.config.mjs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { defineConfig, globalIgnores } from 'eslint/config';
2+
import typescriptEslint from '@typescript-eslint/eslint-plugin';
3+
import globals from 'globals';
4+
import tsParser from '@typescript-eslint/parser';
5+
import path from 'node:path';
6+
import { fileURLToPath } from 'node:url';
7+
import js from '@eslint/js';
8+
import { FlatCompat } from '@eslint/eslintrc';
9+
10+
const __filename = fileURLToPath(import.meta.url);
11+
const __dirname = path.dirname(__filename);
12+
const compat = new FlatCompat({
13+
baseDirectory: __dirname,
14+
recommendedConfig: js.configs.recommended,
15+
allConfig: js.configs.all
16+
});
17+
18+
export default defineConfig([
19+
globalIgnores([
20+
'**/node_modules/',
21+
'**/built/',
22+
'**/package-lock.json',
23+
'**/package.json',
24+
'tests/unit/requests/',
25+
'tests/unit/responses/',
26+
'.vscode/',
27+
'tsconfig.json'
28+
]),
29+
{
30+
extends: compat.extends(
31+
'eslint:recommended',
32+
'plugin:@typescript-eslint/recommended'
33+
),
34+
35+
plugins: {
36+
'@typescript-eslint': typescriptEslint
37+
},
38+
39+
languageOptions: {
40+
globals: {
41+
...globals.browser,
42+
...globals.node
43+
},
44+
45+
parser: tsParser,
46+
ecmaVersion: 'latest',
47+
sourceType: 'module'
48+
},
49+
50+
rules: {
51+
'@typescript-eslint/no-explicit-any': 'off'
52+
}
53+
}
54+
]);

lib/CloudConvert.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ export class UploadFile {
7676
}
7777

7878
if (Symbol.asyncIterator in data) {
79-
const it = data[Symbol.asyncIterator]();
8079
for await (const chunk of data) {
8180
if (typeof chunk === 'string')
8281
throw new Error(

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
"socket.io-client": "^4.7.4"
2323
},
2424
"devDependencies": {
25+
"@eslint/eslintrc": "^3.3.1",
26+
"@eslint/js": "^9.24.0",
2527
"@types/chai": "^5.2.1",
2628
"@types/mocha": "^10.0.10",
2729
"@types/node": "^20.11.19",
@@ -33,6 +35,7 @@
3335
"eslint-config-prettier": "^10.1.2",
3436
"eslint-config-typescript": "^3.0.0",
3537
"eslint-plugin-prettier": "^5.1.3",
38+
"globals": "^16.0.0",
3639
"mocha": "^11.1.0",
3740
"nock": "^14.0.3",
3841
"prettier": "3.5.3",

tests/integration/JobsResourceTest.ts

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,20 @@ import apiKey from './ApiKey.js';
66
import axios from 'axios';
77

88
describe('JobsResource', () => {
9+
let cloudConvert: CloudConvert;
10+
let tmpPath: string;
11+
912
beforeEach(() => {
10-
this.cloudConvert = new CloudConvert(apiKey, true);
13+
cloudConvert = new CloudConvert(apiKey, true);
1114
});
1215

1316
describe('create()', () => {
1417
beforeEach(() => {
15-
this.tmpPath = os.tmpdir() + '/tmp.png';
18+
tmpPath = os.tmpdir() + '/tmp.png';
1619
});
1720

1821
it('test upload and download files', async () => {
19-
let job = await this.cloudConvert.jobs.create({
22+
let job = await cloudConvert.jobs.create({
2023
tag: 'integration-test-upload-download',
2124
tasks: {
2225
'import-it': { operation: 'import/upload' },
@@ -32,18 +35,18 @@ describe('JobsResource', () => {
3235
__dirname + '/../integration/files/input.png'
3336
);
3437

35-
await this.cloudConvert.tasks.upload(uploadTask, stream);
38+
await cloudConvert.tasks.upload(uploadTask, stream);
3639

37-
job = await this.cloudConvert.jobs.wait(job.id);
40+
job = await cloudConvert.jobs.wait(job.id);
3841

3942
assert.equal(job.status, 'finished');
4043

4144
// download export file
42-
const file = this.cloudConvert.jobs.getExportUrls(job)[0];
45+
const file = cloudConvert.jobs.getExportUrls(job)[0];
4346

4447
assert.equal(file.filename, 'input.png');
4548

46-
const writer = fs.createWriteStream(this.tmpPath);
49+
const writer = fs.createWriteStream(tmpPath);
4750

4851
const response = await axios(file.url, { responseType: 'stream' });
4952

@@ -55,21 +58,21 @@ describe('JobsResource', () => {
5558
});
5659

5760
// check file size
58-
const stat = fs.statSync(this.tmpPath);
61+
const stat = fs.statSync(tmpPath);
5962

6063
assert.equal(stat.size, 46937);
6164

62-
await this.cloudConvert.jobs.delete(job.id);
65+
await cloudConvert.jobs.delete(job.id);
6366
}).timeout(30000);
6467

6568
afterEach(() => {
66-
fs.unlinkSync(this.tmpPath);
69+
fs.unlinkSync(tmpPath);
6770
});
6871
});
6972

7073
describe('subscribeEvent()', () => {
7174
it('test listening for finished event', async () => {
72-
let job = await this.cloudConvert.jobs.create({
75+
const job = await cloudConvert.jobs.create({
7376
tag: 'integration-test-socket',
7477
tasks: {
7578
'import-it': { operation: 'import/upload' },
@@ -85,23 +88,19 @@ describe('JobsResource', () => {
8588
__dirname + '/../integration/files/input.png'
8689
);
8790

88-
this.cloudConvert.tasks.upload(uploadTask, stream);
91+
cloudConvert.tasks.upload(uploadTask, stream);
8992

9093
const event = await new Promise(resolve => {
91-
this.cloudConvert.jobs.subscribeEvent(
92-
job.id,
93-
'finished',
94-
resolve
95-
);
94+
cloudConvert.jobs.subscribeEvent(job.id, 'finished', resolve);
9695
});
9796

9897
assert.equal(event.job.status, 'finished');
9998

100-
await this.cloudConvert.jobs.delete(job.id);
99+
await cloudConvert.jobs.delete(job.id);
101100
}).timeout(30000);
102101

103102
afterEach(() => {
104-
this.cloudConvert.closeSocket();
103+
cloudConvert.closeSocket();
105104
});
106105
});
107106
});

tests/integration/TasksResourceTest.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,30 @@ import * as fs from 'fs';
44
import apiKey from './ApiKey.js';
55

66
describe('TasksResource', () => {
7+
let cloudConvert: CloudConvert;
8+
79
beforeEach(() => {
8-
this.cloudConvert = new CloudConvert(apiKey, true);
10+
cloudConvert = new CloudConvert(apiKey, true);
911
});
1012

1113
describe('upload()', () => {
1214
it('uploads input.png', async () => {
13-
let task = await this.cloudConvert.tasks.create('import/upload', {
15+
let task = await cloudConvert.tasks.create('import/upload', {
1416
name: 'upload-test'
1517
});
1618

1719
const stream = fs.createReadStream(
1820
__dirname + '/../integration/files/input.png'
1921
);
2022

21-
await this.cloudConvert.tasks.upload(task, stream);
23+
await cloudConvert.tasks.upload(task, stream);
2224

23-
task = await this.cloudConvert.tasks.wait(task.id);
25+
task = await cloudConvert.tasks.wait(task.id);
2426

2527
assert.equal(task.status, 'finished');
2628
assert.equal(task.result.files[0].filename, 'input.png');
2729

28-
await this.cloudConvert.tasks.delete(task.id);
30+
await cloudConvert.tasks.delete(task.id);
2931
}).timeout(30000);
3032
});
3133
});

tests/integration/UsersResourceTest.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@ import apiKey from './ApiKey.js';
33
import { assert } from 'chai';
44

55
describe('UsersResource', () => {
6+
let cloudConvert: CloudConvert;
7+
68
beforeEach(() => {
7-
this.cloudConvert = new CloudConvert(apiKey, true);
9+
cloudConvert = new CloudConvert(apiKey, true);
810
});
911

1012
describe('me()', () => {
1113
it('should fetch the current user', async () => {
12-
const data = await this.cloudConvert.users.me();
14+
const data = await cloudConvert.users.me();
1315

1416
console.log(data);
1517

tsconfig.json

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,7 @@
1717
"strict": true,
1818
"resolveJsonModule": true,
1919
"target": "es6",
20-
"typeRoots": [
21-
"./node_modules/@types"
22-
]
20+
"typeRoots": ["./node_modules/@types"]
2321
},
24-
"include": [
25-
"./lib/*",
26-
]
27-
}
22+
"include": ["./lib/*"]
23+
}

0 commit comments

Comments
 (0)