chore: fix all lint issues (#21810)

* chore: fix all lint issues

* fix unit tests

* apply copilot suggestion
This commit is contained in:
Edgars Eglītis
2025-12-13 15:24:16 +02:00
committed by GitHub
parent b0b219aa01
commit a5ba1c5efb
52 changed files with 227 additions and 256 deletions

View File

@@ -1,24 +1,30 @@
import tsConfig from '@appium/eslint-config-appium-ts';
import appiumConfig from '@appium/eslint-config-appium-ts';
import {defineConfig, globalIgnores} from 'eslint/config';
export default [
...tsConfig,
{
...tsConfig.find(({name}) => name === 'Test Files'),
name: 'Test Support',
files: [
'packages/test-support/lib/**',
'packages/driver-test-support/lib/**',
'packages/plugin-test-support/lib/**',
],
},
{
name: 'Ignores',
ignores: [
'**/build-fixtures/**',
'packages/appium/docs/**/assets/**',
'packages/appium/docs/**/js/**',
'packages/appium/sample-code/**',
],
},
// Create a modified config subset for test support files:
// Extract the test file related configs (Mocha plugin and custom rules),
// then override their 'files' property
const testFileConfigItems = [appiumConfig[8], appiumConfig[9]];
const testSupportFiles = [
'packages/test-support/lib/**',
'packages/driver-test-support/lib/**',
'packages/plugin-test-support/lib/**',
];
const testSupportConfig = testFileConfigItems.map((item) => ({...item, files: testSupportFiles}));
export default defineConfig([
{
name: 'Base Config',
extends: [appiumConfig],
},
{
name: 'Test Support',
extends: [testSupportConfig],
},
globalIgnores([
'**/build-fixtures/**',
'packages/appium/docs/**/assets/**',
'packages/appium/docs/**/js/**',
'packages/appium/sample-code/**',
]),
]);

338
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -86,9 +86,10 @@
"devDependencies": {
"@colors/colors": "1.6.0",
"@eslint/js": "9.39.1",
"@stylistic/eslint-plugin": "5.6.1",
"@tsconfig/node20": "20.1.8",
"@types/argparse": "2.0.17",
"@types/archiver": "7.0.0",
"@types/argparse": "2.0.17",
"@types/async-lock": "1.4.2",
"@types/base64-stream": "1.0.5",
"@types/bluebird": "3.5.42",
@@ -126,8 +127,9 @@
"eslint": "9.39.1",
"eslint-config-prettier": "10.1.8",
"eslint-import-resolver-typescript": "4.4.4",
"eslint-plugin-import": "2.32.0",
"eslint-plugin-import-x": "4.16.1",
"eslint-plugin-mocha": "11.2.0",
"eslint-plugin-n": "17.23.1",
"eslint-plugin-promise": "7.2.1",
"finalhandler": "2.1.1",
"get-port": "7.1.0",

View File

@@ -23,7 +23,7 @@ import type {
BiDiResultData
} from '@appium/types';
type ExtensionPlugin = Plugin & ExtensionCore
type ExtensionPlugin = Plugin & ExtensionCore;
type AnyDriver = ExternalDriver | AppiumDriver;
type SendData = (data: string | Buffer) => Promise<void>;
type LogSocketError = (err: Error) => void;
@@ -448,7 +448,7 @@ function initBidiEventListeners(
// sure the client is subscribed and then pass it on
const eventLogCounts: Record<string, number> = BIDI_EVENTS_MAP.get(bidiHandlerDriver) ?? {};
BIDI_EVENTS_MAP.set(bidiHandlerDriver, eventLogCounts);
const eventListenerFactory = (extType: 'driver'|'plugin', ext: ExtensionCore) => {
const eventListenerFactory = (extType: 'driver' | 'plugin', ext: ExtensionCore) => {
const eventListener = async ({context, method, params = {}}) => {
// if the driver didn't specify a context, use the empty context
if (!context) {

View File

@@ -8,7 +8,6 @@ const {fs, util, logger} = require('@appium/support');
const Handlebars = require('handlebars');
const _ = require('lodash');
const {asyncify} = require('asyncbox');
const url = require('url');
const log = logger.getLogger('YamlParser');
@@ -192,7 +191,7 @@ Handlebars.registerHelper('if_eq', function ifEq(a, b, opts) {
});
function getBaseHostname(fullUrl) {
const baseUrl = url.parse(fullUrl);
const baseUrl = new URL(fullUrl);
return baseUrl.hostname;
}

View File

@@ -1,4 +1,3 @@
// eslint-disable-next-line import/named
import {createSandbox} from 'sinon';
import {getGitRev, getBuildInfo, updateBuildInfo, APPIUM_VER} from '../../lib/config';
import axios from 'axios';

View File

@@ -6,7 +6,6 @@ import {fs, tempDir} from '@appium/support';
import axios from 'axios';
import B from 'bluebird';
import _ from 'lodash';
// eslint-disable-next-line import/named
import {createSandbox} from 'sinon';
import {remote as wdio} from 'webdriverio';
import {runExtensionCommand} from '../../lib/cli/extension';

View File

@@ -6,7 +6,6 @@ import {BaseDriver} from '@appium/base-driver';
import {FakeDriver} from '@appium/fake-driver';
import {sleep} from 'asyncbox';
import _ from 'lodash';
// eslint-disable-next-line import/named
import {createSandbox} from 'sinon';
import {finalizeSchema, registerSchema, resetSchema} from '../../lib/schema/schema';
import {insertAppiumPrefixes, removeAppiumPrefixes} from '../../lib/utils';

View File

@@ -2,7 +2,6 @@ import {tempDir, fs, npm} from '@appium/support';
import {loadExtensions} from '../../../lib/extension';
import {Manifest} from '../../../lib/extension/manifest';
import DriverCommand from '../../../lib/cli/driver-command';
// eslint-disable-next-line import/named
import {createSandbox} from 'sinon';
describe('DriverCommand', function () {

View File

@@ -1,4 +1,3 @@
// eslint-disable-next-line import/named
import {createSandbox} from 'sinon';
import {finalizeSchema, resetSchema, SchemaFinalizationError} from '../../../lib/schema/schema';
import {rewiremock} from '../../helpers';

View File

@@ -1,4 +1,3 @@
// eslint-disable-next-line import/named
import {createSandbox} from 'sinon';
import {system} from '@appium/support';
import {getPresetDrivers} from '../../../lib/cli/setup-command';

View File

@@ -1,7 +1,6 @@
// @ts-check
import fs from 'fs';
// eslint-disable-next-line import/named
import {createSandbox} from 'sinon';
import * as YAML from 'yaml';
import * as schema from '../../lib/schema/schema';

View File

@@ -1,7 +1,6 @@
// @ts-check
import _ from 'lodash';
// eslint-disable-next-line import/named
import {createSandbox} from 'sinon';
import {getParser} from '../../lib/cli/parser';
import {

View File

@@ -7,7 +7,6 @@
import {EventEmitter} from 'events';
import path from 'path';
// eslint-disable-next-line import/named
import {createSandbox} from 'sinon';
import {version as APPIUM_VER} from '../../../package.json';

View File

@@ -1,6 +1,5 @@
// @ts-check
// eslint-disable-next-line import/named
import {createSandbox} from 'sinon';
import {rewiremock} from '../helpers';

View File

@@ -1,5 +1,4 @@
import {init as logsinkInit, clear as logsinkClear} from '../../lib/logsink';
// eslint-disable-next-line import/named
import {createSandbox} from 'sinon';
import {logger} from '@appium/support';

View File

@@ -1,7 +1,6 @@
// @ts-check
import _ from 'lodash';
// eslint-disable-next-line import/named
import {createSandbox} from 'sinon';
import {DRIVER_TYPE, PLUGIN_TYPE} from '../../../lib/constants';
import {AppiumConfigJsonSchema} from '@appium/schema';

View File

@@ -10,7 +10,6 @@ import {
import {BASE_CAPS, W3C_CAPS} from '../helpers';
import _ from 'lodash';
import {stripColors} from '@colors/colors';
// eslint-disable-next-line import/named
import {createSandbox} from 'sinon';
import logger from '../../lib/logger';
import {fs} from '@appium/support';

View File

@@ -26,7 +26,7 @@ export type CliCommandSetupSubcommand = 'mobile' | 'browser' | 'desktop' | 'rese
* Possible subcommands of {@linkcode CliCommandDriver} or
* {@linkcode CliCommandPlugin}.
*/
export type CliExtensionSubcommand = 'install' | 'list' | 'run' | 'uninstall' | 'update'| 'doctor';
export type CliExtensionSubcommand = 'install' | 'list' | 'run' | 'uninstall' | 'update' | 'doctor';
export interface CliExtensionSubcommandListArgs {
showInstalled?: boolean;

View File

@@ -28,7 +28,7 @@ export type ParsedCaps<C extends Constraints> = {
export type ValidateCapsOpts = {
/** if true, skip the presence constraint */
skipPresenceConstraint?: boolean;
}
};
/**
* Takes primary caps object and merges it into a secondary caps object.

View File

@@ -1,6 +1,5 @@
import _ from 'lodash';
import path from 'path';
import url from 'url';
import logger from './logger';
import {tempDir, fs, util, timing, node} from '@appium/support';
import { LRUCache } from 'lru-cache';
@@ -354,12 +353,16 @@ export function generateDriverLogPrefix(obj, sessionId = null) {
* @returns {Promise<RemoteAppData>}
*/
async function queryAppLink(appLink, reqHeaders) {
const {href, auth} = url.parse(appLink);
const axiosUrl = auth ? href.replace(`${auth}@`, '') : href;
const url = new URL(appLink);
// Extract credentials, then remove them from the URL for axios
const {username, password} = url;
url.username = '';
url.password = '';
const axiosUrl = url.href;
/** @type {import('axios').AxiosBasicCredentials|undefined} */
const axiosAuth = auth ? {
username: auth.substring(0, auth.indexOf(':')),
password: auth.substring(auth.indexOf(':') + 1),
const axiosAuth = username ? {
username,
password,
} : undefined;
/**
* @type {import('axios').RawAxiosRequestConfig}

View File

@@ -122,7 +122,6 @@ export function configureServer({
// set up static assets
app.use(favicon(path.resolve(STATIC_DIR, 'favicon.ico')));
// eslint-disable-next-line import/no-named-as-default-member
app.use(express.static(STATIC_DIR));
// crash routes, for testing

View File

@@ -443,6 +443,7 @@ export class JWProxy {
* @returns {ParsedUrl}
*/
_parseUrl(url) {
// eslint-disable-next-line n/no-deprecated-api -- we need relative URL support
const parsedUrl = nodeUrl.parse(url || '/');
if (
_.isNil(parsedUrl.href) || _.isNil(parsedUrl.pathname)

View File

@@ -74,7 +74,7 @@ export class ProtocolError extends BaseError {
* @see https://w3c.github.io/webdriver-bidi/#protocol-definition
* @returns The object conforming to the shape of a BiDi error response
*/
bidiErrObject(id: string|number): ErrorBiDiCommandResponse {
bidiErrObject(id: string | number): ErrorBiDiCommandResponse {
// if we don't have an id, the client didn't send one, so we have nothing to send back.
// send back zero rather than making something up
const intId = (_.isInteger(id) ? id : (parseInt(`${id}`, 10) || 0)) as number;
@@ -1116,6 +1116,6 @@ interface W3CError {
}
interface ParameterRequirements {
required: string[]|string;
optional?: string[]|string;
required: string[] | string;
optional?: string[] | string;
}

View File

@@ -1,5 +1,4 @@
import path from 'path';
import url from 'url';
import {fs} from '@appium/support';
import {configureApp} from '../../../lib/basedriver/helpers';
import http from 'http';
@@ -83,7 +82,7 @@ describe('app download and configuration', function () {
return;
}
// for testing zip file content types
const contentType = new URLSearchParams(url.parse(req.url).search).get('content-type');
const contentType = new URLSearchParams(new URL(req.url, 'http://localhost').search).get('content-type');
if (contentType !== null) {
res.setHeader('content-type', contentType);
}

View File

@@ -1,6 +1,5 @@
import {server, routeConfiguringFunction} from '../../../lib';
import axios from 'axios';
// eslint-disable-next-line import/named
import {createSandbox} from 'sinon';
import {getTestPort, TEST_HOST} from '@appium/driver-test-support';
import {MockExecuteDriver} from '../protocol/mock-execute-driver';

View File

@@ -1,6 +1,5 @@
import {server} from '../../../lib';
import axios from 'axios';
// eslint-disable-next-line import/named
import {createSandbox} from 'sinon';
import B from 'bluebird';
import _ from 'lodash';

View File

@@ -1,4 +1,3 @@
// eslint-disable-next-line import/no-named-as-default
import Express from 'express';
import bodyParser from 'body-parser';

View File

@@ -1,7 +1,6 @@
import {server, routeConfiguringFunction, errors, JWProxy, BaseDriver} from '../../../lib';
import {FakeDriver} from './fake-driver';
import axios from 'axios';
// eslint-disable-next-line import/named
import {createSandbox} from 'sinon';
import {StatusCodes as HTTPStatusCodes} from 'http-status-codes';
import {createProxyServer} from './helpers';

View File

@@ -3,7 +3,6 @@
import B from 'bluebird';
import {BaseDriver, errors} from '../../../lib/index';
import {validator} from '../../../lib/basedriver/validation';
// eslint-disable-next-line import/named
import {createSandbox} from 'sinon';
// TODO: we need module-level mocks for the logger

View File

@@ -1,5 +1,4 @@
// @ts-check
// eslint-disable-next-line import/named
import {createSandbox} from 'sinon';
import _ from 'lodash';
import {BaseDriver} from '../../../../lib';

View File

@@ -1,7 +1,6 @@
// @ts-check
import {BaseDriver} from '../../../lib';
// eslint-disable-next-line import/named
import {createSandbox} from 'sinon';
describe('timeout', function () {

View File

@@ -2,7 +2,6 @@
import {server, routeConfiguringFunction} from '../../../lib';
import {configureServer, normalizeBasePath} from '../../../lib/express/server';
// eslint-disable-next-line import/named
import {createSandbox} from 'sinon';
import {getTestPort} from '@appium/driver-test-support';

View File

@@ -1,5 +1,4 @@
import {welcome} from '../../../lib/express/static';
// eslint-disable-next-line import/named
import {createSandbox} from 'sinon';
describe('welcome', function () {

View File

@@ -10,7 +10,6 @@ import {getLogger} from '../logger';
import {fs} from '@appium/support';
import _ from 'lodash';
// eslint-disable-next-line import/named
import {sync as readPkg} from 'read-pkg';
import {hideBin} from 'yargs/helpers';
import yargs from 'yargs/yargs';

View File

@@ -151,7 +151,7 @@ export function writeFileString(filepath: string, content: JsonValue) {
});
}
type WhichFunction = (cmd: string, opts?: {nothrow: boolean}) => Promise<string|null>;
type WhichFunction = (cmd: string, opts?: {nothrow: boolean}) => Promise<string | null>;
/**
* `which` with memoization

View File

@@ -1,6 +1,5 @@
import _ from 'lodash';
import B from 'bluebird';
// eslint-disable-next-line import/named
import {createSandbox} from 'sinon';
// wrap these tests in a function so we can export the tests and re-use them

View File

@@ -2,7 +2,6 @@
import {fs} from 'appium/support';
import {main as appiumServer} from 'appium';
import getPort from 'get-port';
// eslint-disable-next-line import/named
import {info, success, warning} from 'log-symbols';
import {exec} from 'teen_process';
@@ -36,7 +35,6 @@ export function pluginE2EHarness(opts) {
*/
let server;
// eslint-disable-next-line mocha/no-top-level-hooks
before(async function () {
const chai = await import('chai');
const chaiAsPromised = await import('chai-as-promised');
@@ -136,7 +134,6 @@ export function pluginE2EHarness(opts) {
await createServer();
});
// eslint-disable-next-line mocha/no-top-level-hooks
after(async function () {
if (server) {
await server.close();

View File

@@ -1,7 +1,6 @@
import path from 'node:path';
import rewiremock from 'rewiremock/node';
import {
// eslint-disable-next-line import/named
createSandbox,
SinonSandbox,
SinonStubbedMember

View File

@@ -2,7 +2,6 @@ import path from 'node:path';
import rewiremock from 'rewiremock/node';
import type {Strongbox as TStrongbox, StrongboxOpts, Item, Value} from '../../lib';
import {
// eslint-disable-next-line import/named
createSandbox,
SinonSandbox,
SinonStubbedMember,

View File

@@ -2,10 +2,10 @@
import {fs} from './fs';
import os from 'os';
import nodePath from 'path';
import cnst from 'constants';
import {constants} from 'node:fs';
import log from './logger';
const RDWR_EXCL = cnst.O_CREAT | cnst.O_TRUNC | cnst.O_RDWR | cnst.O_EXCL;
const RDWR_EXCL = constants.O_CREAT | constants.O_TRUNC | constants.O_RDWR | constants.O_EXCL;
/**
* Generate a temporary directory in os.tempdir() or process.env.APPIUM_TMP_DIR.

View File

@@ -128,7 +128,6 @@ function cancellableDelay(ms) {
// a promise, since `resolve`/`reject` are never called
delay.cancel = function () {
clearTimeout(timer);
// eslint-disable-next-line import/no-named-as-default-member
reject(new B.CancellationError());
};
return delay;

View File

@@ -6,7 +6,6 @@
*/
import path from 'path';
// eslint-disable-next-line import/named
import {createSandbox} from 'sinon';
export function initMocks(sandbox = createSandbox()) {

View File

@@ -1,6 +1,5 @@
import {fs, system, tempDir} from '../../lib';
import path from 'path';
// eslint-disable-next-line import/named
import {createSandbox} from 'sinon';
import {exec} from 'teen_process';
import _ from 'lodash';

View File

@@ -1,5 +1,4 @@
import * as teenProcess from 'teen_process';
// eslint-disable-next-line import/named
import {createSandbox} from 'sinon';
import {process, system} from '../../lib';
import {retryInterval} from 'asyncbox';

View File

@@ -1,6 +1,5 @@
import {system} from '../../lib';
import os from 'os';
// eslint-disable-next-line import/named
import {createSandbox} from 'sinon';
import * as teen_process from 'teen_process';
import _ from 'lodash';

View File

@@ -1,5 +1,4 @@
import _ from 'lodash';
// eslint-disable-next-line import/named
import {createSandbox} from 'sinon';
import {timing} from '../../lib';

View File

@@ -1,6 +1,5 @@
import {util, fs, tempDir} from '../../lib';
import B from 'bluebird';
// eslint-disable-next-line import/named
import {createSandbox} from 'sinon';
import os from 'os';
import path from 'path';

View File

@@ -37,7 +37,7 @@ export interface IDoctorCheck {
* if hasAutofix returns true or
* returns a string description for possible manual fixes
*/
fix(): Promise<string|null>;
fix(): Promise<string | null>;
/**
* Whether calling {@link fix()} would resolve the found issue
*/

View File

@@ -380,11 +380,11 @@ export interface CachedAppInfo {
/**
* Date instance; the value of the file's `Last-Modified` header
*/
lastModified?: Date|null;
lastModified?: Date | null;
/**
* The value of the file's `Etag` header
*/
etag?: string|null;
etag?: string | null;
/**
* `true` if the file contains an `immutable` mark in `Cache-control` header
*/
@@ -392,7 +392,7 @@ export interface CachedAppInfo {
/**
* Integer representation of `maxAge` parameter in `Cache-control` header
*/
maxAge?: number|null;
maxAge?: number | null;
/**
* The timestamp this item has been added to the cache (measured in Unix epoch milliseconds)
*/

View File

@@ -24,7 +24,7 @@ export type AppiumLoggerContext = {
sessionId?: string;
sessionSignature?: string;
[key: string]: any
}
};
/**
* Describes the internal logger.

View File

@@ -123,5 +123,5 @@ export type PluginCommand<
export type PluginClass<P extends Plugin = Plugin> = Class<
P,
PluginStatic<P>,
[pluginName: string, cliArgs: StringRecord<unknown>, driverId: string|null]
[pluginName: string, cliArgs: StringRecord<unknown>, driverId: string | null]
>;