Skip to content

Commit c62a114

Browse files
authored
Chore: eslint-autofixes (#9421)
* sort and remove a few * autofix 1 * remove useless undefined * fix types * number seperators * native coercion * utf8 * explicit number * dom node dataset * explicit unused catch * array find * fix types * prefer negative index * from code point * fix error layout * prefer ternary * explicit length * useless case * named functions * utf8 * import style * default parameters * no instance of * clone * use regex test * single call * prettier * fix types * Revert "use regex test" This reverts commit 8fb9e99.
1 parent 4fb51a1 commit c62a114

File tree

227 files changed

+809
-972
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

227 files changed

+809
-972
lines changed

eslint.config.mjs

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -29,47 +29,23 @@ export default defineConfig([
2929
'unicorn/prefer-dom-node-text-content': 'off', // we use this in an e2e test
3030
'unicorn/prefer-response-static-json': 'off', // unsafe in our templating worker
3131

32-
'unicorn/text-encoding-identifier-case': 'off', // TODO: delete me
33-
'unicorn/prefer-add-event-listener': 'off', // TODO: delete me
32+
'unicorn/no-array-for-each': 'off', // TODO: delete me
33+
'unicorn/no-array-reverse': 'off', // TODO: delete me
34+
'unicorn/no-array-sort': 'off', // TODO: delete me
35+
'unicorn/no-negated-condition': 'off', // TODO: delete me
3436
'unicorn/no-object-as-default-parameter': 'off', // TODO: delete me
37+
'unicorn/no-this-assignment': 'off', // TODO: delete me
38+
'unicorn/no-zero-fractions': 'off', // TODO: delete me
39+
'unicorn/prefer-add-event-listener': 'off', // TODO: delete me
3540
'unicorn/prefer-array-some': 'off', // TODO: delete me
41+
'unicorn/prefer-at': 'off', // TODO: delete me -
3642
'unicorn/prefer-global-this': 'off', // TODO: delete me
3743
'unicorn/prefer-logical-operator-over-ternary': 'off', // TODO: delete me
38-
'unicorn/prefer-string-replace-all': 'off', // TODO: delete me
3944
'unicorn/prefer-regexp-test': 'off', // TODO: delete me
40-
'unicorn/no-array-sort': 'off', // TODO: delete me
41-
'unicorn/prefer-single-call': 'off', // TODO: delete me
42-
'unicorn/prefer-ternary': 'off', // TODO: delete me
43-
'unicorn/no-array-for-each': 'off', // TODO: delete me
44-
'unicorn/import-style': 'off', // TODO: delete me
45-
'unicorn/prefer-number-properties': 'off', // TODO: delete me
46-
'unicorn/no-negated-condition': 'off', // TODO: delete me
47-
'unicorn/prefer-optional-catch-binding': 'off', // TODO: delete me
48-
'unicorn/prefer-at': 'off', // TODO: delete me
45+
'unicorn/prefer-set-has': 'off', // TODO: delete me
4946
'unicorn/prefer-string-raw': 'off', // TODO: delete me
50-
'unicorn/prefer-code-point': 'off', // TODO: delete me
51-
'unicorn/no-new-array': 'off', // TODO: delete me
52-
'unicorn/prefer-native-coercion-functions': 'off', // TODO: delete me
47+
'unicorn/prefer-string-replace-all': 'off', // TODO: delete me
5348
'unicorn/prefer-switch': 'off', // TODO: delete me
54-
'unicorn/no-lonely-if': 'off', // TODO: delete me
55-
'unicorn/no-array-reverse': 'off', // TODO: delete me
56-
'unicorn/no-useless-undefined': 'off', // TODO: delete me
57-
'unicorn/prefer-structured-clone': 'off', // TODO: delete me
58-
'unicorn/escape-case': 'off', // TODO: delete me
59-
'unicorn/no-useless-promise-resolve-reject': 'off', // TODO: delete me
60-
'unicorn/prefer-set-has': 'off', // TODO: delete me
61-
'unicorn/prefer-negative-index': 'off', // TODO: delete me
62-
'unicorn/no-anonymous-default-export': 'off', // TODO: delete me
63-
'unicorn/prefer-default-parameters': 'off', // TODO: delete me
64-
'unicorn/no-instanceof-builtins': 'off', // TODO: delete me
65-
'unicorn/no-zero-fractions': 'off', // TODO: delete me
66-
'unicorn/no-useless-switch-case': 'off', // TODO: delete me
67-
'unicorn/prefer-type-error': 'off', // TODO: delete me
68-
'unicorn/consistent-existence-index-check': 'off', // TODO: delete me
69-
'unicorn/no-this-assignment': 'off', // TODO: delete me
70-
'unicorn/numeric-separators-style': 'off', // TODO: delete me
71-
'unicorn/prefer-array-find': 'off', // TODO: delete me
72-
'unicorn/prefer-dom-node-dataset': 'off', // TODO: delete me
7349
},
7450
},
7551
{

packages/insomnia-inso/src/cli.ts

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import fs from 'node:fs';
22
import { readFile } from 'node:fs/promises';
33
import { homedir } from 'node:os';
4-
import path, { dirname } from 'node:path';
4+
import nodePath from 'node:path';
55

66
import * as commander from 'commander';
77
import type { logType } from 'consola';
@@ -122,13 +122,13 @@ export class InsoError extends Error {
122122
export function getAppDataDir(app: string): string {
123123
switch (process.platform) {
124124
case 'darwin': {
125-
return path.join(homedir(), 'Library', 'Application Support', app);
125+
return nodePath.join(homedir(), 'Library', 'Application Support', app);
126126
}
127127
case 'win32': {
128-
return path.join(process.env.APPDATA || path.join(homedir(), 'AppData', 'Roaming'), app);
128+
return nodePath.join(process.env.APPDATA || nodePath.join(homedir(), 'AppData', 'Roaming'), app);
129129
}
130130
case 'linux': {
131-
return path.join(process.env.XDG_DATA_HOME || path.join(homedir(), '.config'), app);
131+
return nodePath.join(process.env.XDG_DATA_HOME || nodePath.join(homedir(), '.config'), app);
132132
}
133133
default: {
134134
throw new Error('Unsupported platform');
@@ -152,12 +152,12 @@ export const getAbsoluteFilePath = ({ workingDir, file }: { workingDir?: string;
152152

153153
if (workingDir) {
154154
if (fs.existsSync(workingDir) && !fs.statSync(workingDir).isDirectory()) {
155-
return path.resolve(dirname(workingDir), file);
155+
return nodePath.resolve(nodePath.dirname(workingDir), file);
156156
}
157-
return path.resolve(workingDir, file);
157+
return nodePath.resolve(workingDir, file);
158158
}
159159

160-
return path.resolve(process.cwd(), file);
160+
return nodePath.resolve(process.cwd(), file);
161161
};
162162
export const logErrorAndExit = (err?: Error) => {
163163
if (err instanceof InsoError) {
@@ -182,7 +182,7 @@ const noConsoleLog = async <T>(callback: () => Promise<T>): Promise<T> => {
182182

183183
const getWorkingDir = (options: { workingDir?: string }): string => {
184184
if (options.workingDir) {
185-
return path.resolve(options.workingDir);
185+
return nodePath.resolve(options.workingDir);
186186
}
187187

188188
logger.warn('No working directory provided, using local app data directory.');
@@ -266,7 +266,7 @@ const getListFromFileOrUrl = (content: string, fileType?: string): Record<string
266266
);
267267
}
268268
throw new Error('Invalid JSON file uploaded, JSON file must be array of key-value pairs.');
269-
} catch (error) {
269+
} catch {
270270
throw new Error('Upload JSON file can not be parsed');
271271
}
272272
} else if (fileType === 'csv') {
@@ -402,7 +402,7 @@ export const go = (args?: string[]) => {
402402
.option('-r, --reporter <reporter>', `reporter to use, options are [${reporterTypes.join(', ')}]`, defaultReporter)
403403
.option('-b, --bail', 'abort ("bail") after first test failure', false)
404404
.option('--keepFile', 'do not delete the generated test file', false)
405-
.option('--requestTimeout <duration>', 'milliseconds before request times out', undefined) // defaults to user settings
405+
.option('--requestTimeout <duration>', 'milliseconds before request times out') // defaults to user settings
406406
.option('-k, --disableCertValidation', 'disable certificate validation for requests with SSL', false)
407407
.option('--httpsProxy <proxy>', 'URL for the proxy server for https requests.', proxySettings.httpsProxy)
408408
.option('--httpProxy <proxy>', 'URL for the proxy server for http requests.', proxySettings.httpProxy)
@@ -496,7 +496,7 @@ export const go = (args?: string[]) => {
496496
validateSSL: !options.disableCertValidation,
497497
...proxyOptions,
498498
dataFolders: options.dataFolders,
499-
...(options.requestTimeout ? { timeout: parseInt(options.requestTimeout, 10) } : {}),
499+
...(options.requestTimeout ? { timeout: Number.parseInt(options.requestTimeout, 10) } : {}),
500500
});
501501
// Generate test file
502502
const testFileContents = generate(
@@ -535,7 +535,7 @@ export const go = (args?: string[]) => {
535535
.option('-e, --env <identifier>', 'environment to use', '')
536536
.option('-g, --globals <identifier>', 'global environment to use (filepath or id)', '')
537537
.option('--delay-request <duration>', 'milliseconds to delay between requests', '0')
538-
.option('--requestTimeout <duration>', 'milliseconds before request times out', undefined) // defaults to user settings
538+
.option('--requestTimeout <duration>', 'milliseconds before request times out') // defaults to user settings
539539
.option('--env-var <key=value>', 'override environment variables', collect, [])
540540
.option('-n, --iteration-count <count>', 'number of times to repeat', '1')
541541
.option('-d, --iteration-data <path/url>', 'file path or url (JSON or CSV)', '')
@@ -605,7 +605,7 @@ export const go = (args?: string[]) => {
605605
}
606606
try {
607607
fs.accessSync(outputFilePath, fs.constants.W_OK);
608-
} catch (err) {
608+
} catch {
609609
logger.fatal(`Output file "${outputFilePath}" is not writable.`);
610610
return process.exit(1);
611611
}
@@ -792,7 +792,7 @@ export const go = (args?: string[]) => {
792792
}
793793

794794
try {
795-
const iterationCount = parseInt(options.iterationCount, 10);
795+
const iterationCount = Number.parseInt(options.iterationCount, 10);
796796

797797
const iterationData = await pathToIterationData(options.iterationData, options.envVar);
798798
const transientVariables: Environment = {
@@ -833,7 +833,7 @@ export const go = (args?: string[]) => {
833833
validateSSL: !options.disableCertValidation,
834834
...proxyOptions,
835835
dataFolders: options.dataFolders,
836-
...(options.requestTimeout ? { timeout: parseInt(options.requestTimeout, 10) } : {}),
836+
...(options.requestTimeout ? { timeout: Number.parseInt(options.requestTimeout, 10) } : {}),
837837
},
838838
iterationData,
839839
iterationCount,
@@ -888,7 +888,7 @@ export const go = (args?: string[]) => {
888888
}
889889
}
890890

891-
await new Promise(r => setTimeout(r, parseInt(options.delayRequest, 10)));
891+
await new Promise(r => setTimeout(r, Number.parseInt(options.delayRequest, 10)));
892892

893893
if (res.nextRequestIdOrName) {
894894
const offset = getNextRequestOffset(requestsToRun.slice(reqIndex), res.nextRequestIdOrName);
@@ -934,14 +934,14 @@ export const go = (args?: string[]) => {
934934
let isIdentifierAFile = false;
935935
try {
936936
isIdentifierAFile = identifier && (await fs.promises.stat(identifierAsAbsPath)).isFile();
937-
} catch (err) {}
937+
} catch {}
938938
const pathToSearch = '';
939939
let specContent: string | undefined;
940940
let rulesetFileName: string | undefined;
941941
if (isIdentifierAFile) {
942942
// try load as a file
943943
logger.trace(`Linting specification file from identifier: \`${identifierAsAbsPath}\``);
944-
specContent = await fs.promises.readFile(identifierAsAbsPath, 'utf-8');
944+
specContent = await fs.promises.readFile(identifierAsAbsPath, 'utf8');
945945
rulesetFileName = await getRuleSetFileFromFolderByFilename(identifierAsAbsPath);
946946
if (!specContent) {
947947
logger.fatal(`Specification content not found using path: ${identifier} in ${identifierAsAbsPath}`);
@@ -1048,12 +1048,12 @@ export const go = (args?: string[]) => {
10481048

10491049
const getNextRequestOffset = (leftRequestsToRun: Request[], nextRequestIdOrName: string) => {
10501050
const idMatchOffset = leftRequestsToRun.findIndex(req => req._id.trim() === nextRequestIdOrName.trim());
1051-
if (idMatchOffset >= 0) {
1051+
if (idMatchOffset !== -1) {
10521052
return idMatchOffset;
10531053
}
10541054

10551055
const nameMatchOffset = leftRequestsToRun.reverse().findIndex(req => req.name.trim() === nextRequestIdOrName.trim());
1056-
if (nameMatchOffset >= 0) {
1056+
if (nameMatchOffset !== -1) {
10571057
return leftRequestsToRun.length - 1 - nameMatchOffset;
10581058
}
10591059

packages/insomnia-inso/src/commands/run-collection/result-report.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import fs from 'node:fs';
2-
import { dirname } from 'node:path';
2+
import nodePath from 'node:path';
33

44
import type { Consola } from 'consola';
55
import { pick } from 'es-toolkit';
@@ -87,7 +87,7 @@ export class RunCollectionResultReport {
8787
}
8888

8989
private getStats() {
90-
const iterationStatusArray = new Array(this.iterationCount).fill(true);
90+
const iterationStatusArray = Array.from({ length: this.iterationCount }).fill(true);
9191
let failedRequests = 0;
9292
let totalTests = 0;
9393
let failedTests = 0;
@@ -275,7 +275,7 @@ export class RunCollectionResultReport {
275275
}
276276

277277
const jsonReport = this.generateJSONReport();
278-
await fs.promises.mkdir(dirname(this.options.outputFilePath), { recursive: true });
278+
await fs.promises.mkdir(nodePath.dirname(this.options.outputFilePath), { recursive: true });
279279
await fs.promises.writeFile(this.options.outputFilePath, JSON.stringify(jsonReport, null, 2), 'utf8');
280280
this.logger.log('Result report saved to:', this.options.outputFilePath);
281281
};

packages/insomnia-inso/src/db/adapters/git-adapter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const gitAdapter: DbAdapter = async (dir, filterTypes) => {
1515
let files = null;
1616
try {
1717
files = await fs.promises.readdir(insomniaFolder);
18-
} catch (error) {
18+
} catch {
1919
if (files?.length === 0) {
2020
console.error(`.insomnia folder found at "${insomniaFolder}"
2121
but no files found inside. Ensure your workingDir is correct.`);

packages/insomnia-inso/src/db/adapters/insomnia-adapter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ const insomniaAdapter: DbAdapter = async (filePath, filterTypes) => {
7878
const db = emptyDb();
7979

8080
// Now, reading and parsing
81-
const content = await fs.promises.readFile(filePath, { encoding: 'utf-8' });
81+
const content = await fs.promises.readFile(filePath, { encoding: 'utf8' });
8282
let parsed:
8383
| {
8484
__export_format: number;

packages/insomnia-inso/src/db/adapters/ne-db-adapter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const neDbAdapter: DbAdapter = async (dir, filterTypes) => {
1111
// Confirm if db files exist
1212
try {
1313
await stat(path.join(dir, 'insomnia.Workspace.db'));
14-
} catch (err) {
14+
} catch {
1515
return null;
1616
}
1717

packages/insomnia-inso/src/db/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ interface Options {
5959
export const isFile = async (path: string) => {
6060
try {
6161
return (await stat(path)).isFile();
62-
} catch (error) {
62+
} catch {
6363
return false;
6464
}
6565
};

packages/insomnia-inso/src/db/models/util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function indent(level: number, code: string, tab = ' |'): string {
1010
return code;
1111
}
1212

13-
const prefix = new Array(level + 1).join(tab);
13+
const prefix = Array.from({ length: level + 1 }).join(tab);
1414
return `${prefix} ${code}`;
1515
}
1616

packages/insomnia-scripting-environment/src/objects/__tests__/auth.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { Variable, VariableList } from '../variables';
55

66
const varListToObject = (obj: VariableList<Variable> | undefined) => {
77
if (!obj) {
8-
return undefined;
8+
return;
99
}
1010

1111
return obj.map(

packages/insomnia-scripting-environment/src/objects/__tests__/response.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ describe('test request and response objects', () => {
3535
{ key: 'header2', value: 'val2' },
3636
{ key: 'Content-Length', value: '100' },
3737
{ key: 'Content-Disposition', value: 'attachment; filename="filename.txt"' },
38-
{ key: 'Content-Type', value: 'text/plain; charset=utf-8' },
38+
{ key: 'Content-Type', value: 'text/plain; charset=utf8' },
3939
],
4040
cookie: [
4141
{ key: 'header1', value: 'val1' },
@@ -54,8 +54,8 @@ describe('test request and response objects', () => {
5454
key: 888,
5555
});
5656
expect(resp.contentInfo()).toEqual({
57-
charset: 'utf-8',
58-
contentType: 'text/plain; charset=utf-8',
57+
charset: 'utf8',
58+
contentType: 'text/plain; charset=utf8',
5959
fileExtension: 'txt',
6060
fileName: 'filename',
6161
mimeFormat: '',

0 commit comments

Comments
 (0)