From 553de06b9ff31a6adc2d94a7b2fbf501e752fa42 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Sun, 15 Nov 2026 21:45:30 +0000 Subject: [PATCH] Lint against inline imports, nested classes and console in lib Co-authored-by: ProxyMesh AI --- eslint.config.js | 21 +++++++++++++++++++++ lib/axios-proxy.js | 1 + lib/got-proxy.js | 1 + lib/ky-proxy.js | 1 + lib/needle-proxy.js | 2 ++ lib/node-fetch-proxy.js | 1 + lib/superagent-proxy.js | 1 + lib/typed-rest-client-proxy.js | 4 ++++ lib/undici-proxy.js | 1 + lib/wretch-proxy.js | 1 + 10 files changed, 34 insertions(+) diff --git a/eslint.config.js b/eslint.config.js index 0f2c442..b48d246 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -19,4 +19,25 @@ export default [ ], }, }, + { + files: ["lib/**/*.js"], + rules: { + "no-console": "error", + "no-restricted-syntax": [ + "error", + { + selector: ":function ImportExpression", + message: "Import at the top of the module.", + }, + { + selector: ":function CallExpression[callee.name='require']", + message: "Require at the top of the module.", + }, + { + selector: ":function :matches(ClassDeclaration, ClassExpression)", + message: "Define classes at the top level of the module.", + }, + ], + }, + }, ]; diff --git a/lib/axios-proxy.js b/lib/axios-proxy.js index f73a7f8..2084d4b 100644 --- a/lib/axios-proxy.js +++ b/lib/axios-proxy.js @@ -32,6 +32,7 @@ export async function createProxyAxios(options) { let axios; try { + // eslint-disable-next-line no-restricted-syntax -- optional peer dependency, loaded on first use axios = (await import('axios')).default; } catch { throw new Error('axios is required. Install it with: npm install axios'); diff --git a/lib/got-proxy.js b/lib/got-proxy.js index b2672cb..2abeee7 100644 --- a/lib/got-proxy.js +++ b/lib/got-proxy.js @@ -32,6 +32,7 @@ export async function createProxyGot(options) { let got; try { + // eslint-disable-next-line no-restricted-syntax -- optional peer dependency, loaded on first use got = (await import('got')).default; } catch { throw new Error('got is required. Install it with: npm install got'); diff --git a/lib/ky-proxy.js b/lib/ky-proxy.js index c05ae94..03a6733 100644 --- a/lib/ky-proxy.js +++ b/lib/ky-proxy.js @@ -105,6 +105,7 @@ export async function createProxyKy(options) { let ky; try { + // eslint-disable-next-line no-restricted-syntax -- optional peer dependency, loaded on first use ky = (await import('ky')).default; } catch { throw new Error('ky is required. Install it with: npm install ky'); diff --git a/lib/needle-proxy.js b/lib/needle-proxy.js index ae4d2c9..072685c 100644 --- a/lib/needle-proxy.js +++ b/lib/needle-proxy.js @@ -26,6 +26,7 @@ export async function proxyNeedleGet(url, options = {}) { throw new Error('proxy option is required'); } + // eslint-disable-next-line no-restricted-syntax -- optional peer dependency, loaded on first use const needle = require('needle'); const agent = new ProxyHeadersAgent(proxy, { @@ -75,6 +76,7 @@ export function createProxyNeedle(options) { proxyTlsOptions, }); + // eslint-disable-next-line no-restricted-syntax -- optional peer dependency, loaded on first use const needle = require('needle'); return { diff --git a/lib/node-fetch-proxy.js b/lib/node-fetch-proxy.js index 4541ae0..380ab88 100644 --- a/lib/node-fetch-proxy.js +++ b/lib/node-fetch-proxy.js @@ -37,6 +37,7 @@ export async function proxyFetch(url, options = {}) { let fetch; try { + // eslint-disable-next-line no-restricted-syntax -- optional peer dependency, loaded on first use fetch = (await import('node-fetch')).default; } catch { throw new Error('node-fetch is required. Install it with: npm install node-fetch'); diff --git a/lib/superagent-proxy.js b/lib/superagent-proxy.js index b4f6428..0713f4f 100644 --- a/lib/superagent-proxy.js +++ b/lib/superagent-proxy.js @@ -81,6 +81,7 @@ export function proxyPlugin(options) { export async function createProxySuperagent(options) { let superagent; try { + // eslint-disable-next-line no-restricted-syntax -- optional peer dependency, loaded on first use superagent = (await import('superagent')).default; } catch { throw new Error('superagent is required. Install it with: npm install superagent'); diff --git a/lib/typed-rest-client-proxy.js b/lib/typed-rest-client-proxy.js index 0534862..fbf9095 100644 --- a/lib/typed-rest-client-proxy.js +++ b/lib/typed-rest-client-proxy.js @@ -40,6 +40,7 @@ function attachRestProxyHeaders(processed, res) { * @param {import('typed-rest-client/HttpClient').HttpClient} Base */ function createProxyHeadersHttpClientClass(HttpClient) { + // eslint-disable-next-line no-restricted-syntax -- extends an optional peer dependency class return class ProxyHeadersHttpClient extends HttpClient { /** * @param {string} userAgent @@ -90,6 +91,7 @@ function createProxyHeadersHttpClientClass(HttpClient) { * @param {ReturnType} ProxyHeadersHttpClient */ function createProxyHeadersRestClientClass(RestClient, ProxyHeadersHttpClient) { + // eslint-disable-next-line no-restricted-syntax -- extends an optional peer dependency class return class ProxyHeadersRestClient extends RestClient { /** * @param {string} userAgent @@ -151,7 +153,9 @@ export function createProxyRestClient(options) { throw new Error('proxy option is required'); } + // eslint-disable-next-line no-restricted-syntax -- optional peer dependency, loaded on first use const { RestClient } = require('typed-rest-client/RestClient'); + // eslint-disable-next-line no-restricted-syntax -- optional peer dependency, loaded on first use const { HttpClient } = require('typed-rest-client/HttpClient'); const PHC = createProxyHeadersHttpClientClass(HttpClient); diff --git a/lib/undici-proxy.js b/lib/undici-proxy.js index 2df72d0..e344628 100644 --- a/lib/undici-proxy.js +++ b/lib/undici-proxy.js @@ -160,6 +160,7 @@ export async function request(url, options = {}) { let undici; try { + // eslint-disable-next-line no-restricted-syntax -- optional peer dependency, loaded on first use undici = await import('undici'); } catch { throw new Error('undici is required. Install it with: npm install undici'); diff --git a/lib/wretch-proxy.js b/lib/wretch-proxy.js index 7597d56..266af2b 100644 --- a/lib/wretch-proxy.js +++ b/lib/wretch-proxy.js @@ -31,6 +31,7 @@ export async function createProxyWretch(options) { let rawWretch; try { + // eslint-disable-next-line no-restricted-syntax -- optional peer dependency, loaded on first use rawWretch = (await import('wretch')).default; } catch { throw new Error('wretch is required. Install it with: npm install wretch');