Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update to eslint v9 #2830

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 87 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import tsEslint from 'typescript-eslint';
import tsStylistic from '@stylistic/eslint-plugin-ts';
import apify from '@apify/eslint-config';
import prettier from 'eslint-config-prettier';

export default [
{
ignores: ['**/dist', 'node_modules', 'coverage', '**/*.d.ts'],
},
...apify,
prettier,
{
languageOptions: {
parser: tsEslint.parser,
parserOptions: {
project: 'tsconfig.eslint.json',
},
},
},
{
plugins: {
'@typescript-eslint': tsEslint.plugin,
'@stylistic': tsStylistic,
},
rules: {
'@typescript-eslint/no-empty-object-type': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'max-classes-per-file': 'off',
'no-empty-function': 'off',
'import/order': 'off', // TODO
'max-len': 'off', // TODO
'operator-linebreak': 'off', // TODO
'no-use-before-define': 'off', // TODO
'consistent-return': 'off', // TODO
'no-param-reassign': 'off',
'no-void': 'off',
'no-underscore-dangle': 'off',
'no-console': 'off',
'import/no-extraneous-dependencies': 'off',
'import/extensions': 'off',
'import/no-default-export': 'off',

'@typescript-eslint/array-type': 'error',
'@typescript-eslint/ban-ts-comment': 0,
// https://typescript-eslint.io/rules/ban-types/
// '@typescript-eslint/ban-types': [
// 'error',
// {
// 'types': {
// '{}': false
// },
// 'extendDefaults': true
// }
// ],
'@typescript-eslint/consistent-type-imports': [
'error',
{
'disallowTypeAnnotations': false,
},
],
'@typescript-eslint/consistent-type-definitions': ['error', 'interface'],
'@stylistic/member-delimiter-style': [
'error',
{
'multiline': { 'delimiter': 'semi', 'requireLast': true },
'singleline': { 'delimiter': 'semi', 'requireLast': false },
},
],
'@typescript-eslint/no-empty-interface': 'off',
'@typescript-eslint/promise-function-async': 'off',
'no-promise-executor-return': 'off',
'@typescript-eslint/prefer-destructuring': 'off',
'prefer-destructuring': 'off',
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/no-floating-promises': 'error',
'@typescript-eslint/no-unused-vars': 'off',
'@stylistic/comma-dangle': ['error', 'always-multiline'],
},
},
{
files: ['packages/templates/**/*'],
rules: {
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': 'off',
},
},
];
13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,15 @@
"prepare": "husky"
},
"devDependencies": {
"@apify/eslint-config-ts": "^0.4.1",
"@apify/eslint-config": "^0.5.0-beta.4",
"@apify/log": "^2.4.0",
"@apify/tsconfig": "^0.1.0",
"@biomejs/biome": "^1.7.3",
"@commitlint/config-conventional": "^19.0.0",
"@playwright/browser-chromium": "1.50.0",
"@playwright/browser-firefox": "1.50.0",
"@playwright/browser-webkit": "1.50.0",
"@stylistic/eslint-plugin-ts": "^3.0.0",
"@types/content-type": "^1.1.5",
"@types/deep-equal": "^1.0.1",
"@types/domhandler": "^2.4.2",
Expand All @@ -81,8 +82,6 @@
"@types/semver": "^7.3.12",
"@types/stream-json": "^1.7.2",
"@types/yargs": "^17.0.26",
"@typescript-eslint/eslint-plugin": "^7.18.0",
"@typescript-eslint/parser": "^7.18.0",
"@vitest/coverage-v8": "^2.0.0",
"apify": "*",
"apify-node-curl-impersonate": "^1.0.15",
Expand All @@ -91,11 +90,12 @@
"commitlint": "^19.0.0",
"cross-env": "^7.0.3",
"deep-equal": "^2.0.5",
"eslint": "^8.57.1",
"eslint-config-prettier": "^10.0.0",
"eslint": "^9.19.0",
"eslint-config-prettier": "^10.0.1",
"express": "^4.18.1",
"fs-extra": "^11.0.0",
"gen-esm-wrapper": "^1.1.3",
"globals": "^15.14.0",
"globby": "^14.0.0",
"got": "^13.0.0",
"husky": "^9.0.11",
Expand All @@ -110,7 +110,8 @@
"rimraf": "^6.0.0",
"tsx": "^4.4.0",
"turbo": "^2.1.0",
"typescript": "^5.7.2",
"typescript": "^5.7.3",
"typescript-eslint": "^8.22.0",
"vite-tsconfig-paths": "^4.3.2",
"vitest": "^2.0.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/browser-crawler/src/internals/browser-crawler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,7 @@ export async function browserCrawlerEnqueueLinks({
* @ignore
*/
export async function extractUrlsFromPage(
// eslint-disable-next-line @typescript-eslint/ban-types
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
page: { $$eval: Function },
selector: string,
baseUrl: string,
Expand Down
1 change: 0 additions & 1 deletion packages/browser-pool/src/container-proxy-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export async function createProxyServerForContainers(fallbackProxyUrl?: string)
};
}

// eslint-disable-next-line no-console
console.warn(`Request without proxy ${localAddress} ${request.headers.host}`);
}

Expand Down
1 change: 0 additions & 1 deletion packages/browser-pool/src/playwright/load-firefox-addon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ export const loadFirefoxAddon = async (port: number, host: string, addonPath: st
let remainingBytes = 0;

socket.on('data', (data) => {
// eslint-disable-next-line no-constant-condition
while (true) {
if (remainingBytes === 0) {
const index = data.indexOf(':');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ export class PlaywrightController extends BrowserController<

const { remoteIPAddress } = response;
if (remoteIPAddress && remoteIPAddress !== proxyip) {
// eslint-disable-next-line no-console
console.warn(
`Request to ${response.url} was through ${remoteIPAddress} instead of ${proxyip}`,
);
Expand Down
7 changes: 1 addition & 6 deletions packages/browser-pool/tab-as-a-container/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ chrome.cookies.onChanged.addListener(async (changeInfo) => {
const opener = getOpenerId(tabId);

if (tabId !== opener) {
// eslint-disable-next-line no-console
console.log(`${realCookieName} -> ${keyFromTabId(opener)}`);

await chrome.cookies.remove({
Expand Down Expand Up @@ -107,7 +106,6 @@ chrome.webRequest.onBeforeSendHeaders.addListener(
// We don't want these in order to prevent cluttering cookies.
// Yes, `webNavigation.onCommitted` is emitted and `webNavigation.onCreatedNavigationTarget` is not.
if (header.name.toLowerCase() === 'purpose' && header.value === 'prefetch' && !counter.has(details.tabId)) {
// eslint-disable-next-line no-console
console.log(details);
return {
cancel: true,
Expand All @@ -116,23 +114,20 @@ chrome.webRequest.onBeforeSendHeaders.addListener(

// This one is for Firefox
if (header.name.toLowerCase() === 'x-moz' && header.value === 'prefetch' && !counter.has(details.tabId)) {
// eslint-disable-next-line no-console
console.log(details);
return {
cancel: true,
};
}

if (['beacon', 'csp_report', 'ping', 'speculative'].includes(details.type)) {
// eslint-disable-next-line no-console
console.log(details);
return {
cancel: true,
};
}

if (details.tabId === -1) {
// eslint-disable-next-line no-console
console.log(details);
}
}
Expand Down Expand Up @@ -367,7 +362,7 @@ const onCompleted = async (details) => {
chrome.webNavigation.onCompleted.addListener(onCompleted);

// Load content scripts.
(async () => {
void (async () => {
const contentResponse = await fetch(chrome.runtime.getURL('content.js'));
const contentText = await contentResponse.text();

Expand Down
1 change: 0 additions & 1 deletion packages/browser-pool/tab-as-a-container/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,6 @@ try {
},
});
} catch (error) {
// eslint-disable-next-line no-console
console.error(error);
}

Expand Down
1 change: 0 additions & 1 deletion packages/cli/src/commands/CreateProjectCommand.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable no-console */
import { execSync } from 'node:child_process';
import { mkdirSync } from 'node:fs';
import { readFile, writeFile } from 'node:fs/promises';
Expand Down
2 changes: 0 additions & 2 deletions packages/cli/src/commands/InstallPlaywrightBrowsersCommand.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable no-console */

import { execSync } from 'node:child_process';

import ansiColors from 'ansi-colors';
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env node

// eslint-disable-next-line @typescript-eslint/no-var-requires
// eslint-disable-next-line @typescript-eslint/no-require-imports
require('yargonaut') //
.style('blue')
.style('yellow', 'required')
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/autoscaling/snapshotter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,9 @@ export class Snapshotter {
this.events.off(EventType.SYSTEM_INFO, this._snapshotCpu);
this.events.off(EventType.SYSTEM_INFO, this._snapshotMemory);
// Allow microtask queue to unwind before stop returns.
await new Promise((resolve) => setImmediate(resolve));
await new Promise((resolve) => {
setImmediate(resolve);
});
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/storages/key_value_store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const maybeStringify = <T>(value: T, options: { contentType?: string }) =
} catch (e) {
const error = e as Error;
// Give more meaningful error message
if (error.message?.indexOf('Invalid string length') >= 0) {
if (error.message?.includes('Invalid string length')) {
error.message = 'Object is too large';
}
throw new Error(`The "value" parameter cannot be stringified to JSON: ${error.message}`);
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/storages/request_list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ export class RequestList implements IRequestList {
this._ensureUniqueKeyValid(uniqueKey);

// Skip requests with duplicate uniqueKey
if (!this.uniqueKeyToIndex.hasOwnProperty(uniqueKey)) {
if (!Object.hasOwn(this.uniqueKeyToIndex, uniqueKey)) {
this.uniqueKeyToIndex[uniqueKey] = this.requests.length;
this.requests.push(request);
} else if (this.keepDuplicateUrls) {
Expand Down
10 changes: 6 additions & 4 deletions packages/core/src/storages/sitemap_request_list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export class SitemapRequestList implements IRequestList {
*
* If the loading is aborted and all the requests are handled, `isFinished()` will return `true`.
*/
private abortLoading: boolean = false;
private abortLoading = false;

/** Number of URLs that were marked as handled */
private handledUrlCount = 0;
Expand All @@ -167,7 +167,7 @@ export class SitemapRequestList implements IRequestList {

private store?: KeyValueStore;

private closed: boolean = false;
private closed = false;

/**
* Proxy URL to be used for sitemap loading.
Expand Down Expand Up @@ -278,7 +278,8 @@ export class SitemapRequestList implements IRequestList {
private async pushNextUrl(url: string | null) {
return new Promise<void>((resolve) => {
if (this.closed || (url && !this.isUrlMatchingPatterns(url))) {
return resolve();
resolve();
return;
}

if (!this.urlQueueStream.push(url)) {
Expand All @@ -301,7 +302,8 @@ export class SitemapRequestList implements IRequestList {
private async readNextUrl(): Promise<string | null> {
return new Promise((resolve) => {
if (this.closed) {
return resolve(null);
resolve(null);
return;
}

const result = this.urlQueueStream.read();
Expand Down
2 changes: 1 addition & 1 deletion packages/http-crawler/src/internals/http-crawler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ export class HttpCrawler<
const extensionOptions = extension.getCrawlerOptions();

for (const [key, value] of Object.entries(extensionOptions)) {
const isConfigurable = this.hasOwnProperty(key);
const isConfigurable = Object.hasOwn(this, key);
const originalType = typeof this[key as keyof this];
const extensionType = typeof value; // What if we want to null something? It is really needed?
const isSameType = originalType === extensionType || value == null; // fast track for deleting keys
Expand Down
2 changes: 1 addition & 1 deletion packages/impit-client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export class ImpitHttpClient implements BaseHttpClient {
});

if (this.followRedirects && response.status >= 300 && response.status < 400) {
const location = response.headers.location;
const { location } = response.headers;

if (!location) {
throw new Error('Redirect response missing location header.');
Expand Down
4 changes: 2 additions & 2 deletions packages/memory-storage/src/cache-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import mimeTypes from 'mime-types';
import { DatasetFileSystemEntry } from './fs/dataset/fs';
import { KeyValueFileSystemEntry } from './fs/key-value-store/fs';
import { RequestQueueFileSystemEntry } from './fs/request-queue/fs';
// eslint-disable-next-line import/order

import type { MemoryStorage } from './memory-storage';

const uuidRegex = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/i;
Expand Down Expand Up @@ -336,7 +336,7 @@ export async function findRequestQueueByPossibleId(client: MemoryStorage, entryN
JSON.parse(fileContent);

entries.add(entryName);
} catch (err) {
} catch {
memoryStorageLog.warning(
`Request queue entry "${entry.name}" for store ${entryNameOrId} has invalid JSON content and will be ignored from the store.`,
);
Expand Down
1 change: 1 addition & 0 deletions packages/memory-storage/test/__shared__.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { setTimeout } from 'node:timers/promises';
export async function waitTillWrittenToDisk(path: string): Promise<void> {
try {
await access(path);
return undefined;
} catch {
await setTimeout(50);
return waitTillWrittenToDisk(path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ export async function gotoExtended(
} catch (error) {
log.debug('Error inside request interceptor', { error });
}

return undefined;
};

await page.route('**/*', interceptRequestHandler);
Expand Down Expand Up @@ -297,7 +299,7 @@ export async function blockRequests(page: Page, options: BlockRequestsOptions =

await client.send('Network.enable');
await client.send('Network.setBlockedURLs', { urls: patternsToBlock });
} catch (error) {
} catch {
log.warning('blockRequests() helper is incompatible with non-Chromium browsers.');
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/playwright-crawler/src/logistic-regression.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
declare module 'ml-logistic-regression' {
import Matrix from 'ml-matrix';
import type Matrix from 'ml-matrix';

class LogisticRegressionTwoClasses {
testScores(Xtest: Matrix): number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,8 @@ function createInterceptRequestHandler(page: Page, requests: Set<string>): (req:
} else {
await req.abort('aborted'); // Prevents navigation by js
}

return undefined;
};
}

Expand Down
Loading