diff --git a/.eslintignore b/.eslintignore deleted file mode 100644 index abf24cdbf6..0000000000 --- a/.eslintignore +++ /dev/null @@ -1,8 +0,0 @@ -build -cli/assets -dist -types -android/capacitor/src/main/assets/native-bridge.js -ios/Sources/Capacitor/assets/native-bridge.js -ios/Frameworks/Capacitor.xcframework/ios-arm64_x86_64-simulator/Capacitor.framework/native-bridge.js -ios/Frameworks/Capacitor.xcframework/ios-arm64/Capacitor.framework/native-bridge.js diff --git a/cli/src/common.ts b/cli/src/common.ts index 1da9d1b21c..f26adfd2e0 100644 --- a/cli/src/common.ts +++ b/cli/src/common.ts @@ -531,7 +531,7 @@ export async function checkJDKMajorVersion(): Promise { } else { return -1; } - } catch (e) { + } catch { return -1; } } diff --git a/cli/src/config.ts b/cli/src/config.ts index aa8ba0c52d..0f4f3aea60 100644 --- a/cli/src/config.ts +++ b/cli/src/config.ts @@ -114,7 +114,7 @@ async function loadExtConfigTS( ); } - const ts = require(tsPath); // eslint-disable-line @typescript-eslint/no-var-requires + const ts = require(tsPath); // eslint-disable-line @typescript-eslint/no-require-imports const extConfigObject = (await requireTS(ts, extConfigFilePath)) as any; const extConfig = extConfigObject.default ? await extConfigObject.default : extConfigObject; @@ -143,6 +143,7 @@ async function loadExtConfigJS( extConfigType: 'js', extConfigName, extConfigFilePath: extConfigFilePath, + // eslint-disable-next-line @typescript-eslint/no-require-imports extConfig: await require(extConfigFilePath), }; } catch (e: any) { @@ -360,7 +361,7 @@ async function determineIOSWebDirAbs( return resolve(nativeProjectDirAbs, 'public'); } - } catch (e) { + } catch { // ignore } @@ -458,7 +459,7 @@ async function determinePackageManager( if (output != null) { gemfilePath = resolve(output, 'Gemfile'); } - } catch (e: any) { + } catch { // Nothing } } diff --git a/cli/src/ios/common.ts b/cli/src/ios/common.ts index 779dafd90f..546b4d4f6d 100644 --- a/cli/src/ios/common.ts +++ b/cli/src/ios/common.ts @@ -22,7 +22,7 @@ function execBundler() { try { const bundleOutput = execSync('bundle &> /dev/null ; echo $?'); return parseInt(bundleOutput.toString()); - } catch (e: any) { + } catch { return -1; } } diff --git a/cli/src/plugin.ts b/cli/src/plugin.ts index 884bba998a..244516639e 100644 --- a/cli/src/plugin.ts +++ b/cli/src/plugin.ts @@ -92,7 +92,7 @@ export async function resolvePlugin(config: Config, name: string): Promise { const allPlugins = await getPlugins(config, platform); - let plugins: Plugin[] = []; + let plugins: Plugin[]; if (platform === config.ios.name) { plugins = await getIOSPlugins(allPlugins); } else if (platform === config.android.name) { diff --git a/cli/src/tasks/migrate.ts b/cli/src/tasks/migrate.ts index dcc8898fdd..68d592dccd 100644 --- a/cli/src/tasks/migrate.ts +++ b/cli/src/tasks/migrate.ts @@ -15,7 +15,6 @@ import { extractTemplate } from '../util/template'; import { migrateToUIScene } from './migrate-uiscene'; -// eslint-disable-next-line prefer-const let allDependencies: { [key: string]: any } = {}; const libs = ['@capacitor/core', '@capacitor/cli', '@capacitor/ios', '@capacitor/android']; const plugins = [ @@ -156,7 +155,7 @@ export async function migrateCommand(config: Config, noprompt: boolean, packagem await runTask(`Installing Latest Modules using ${installerType}.`, () => { return installLatestLibs(installerType, runNpmInstall, config); }); - } catch (ex) { + } catch { logger.error( `${installerType} install failed. Try deleting node_modules folder and running ${c.input( `${installerType} install --force`, diff --git a/cli/src/util/js.ts b/cli/src/util/js.ts index 23bdb4f1ea..d039500b39 100644 --- a/cli/src/util/js.ts +++ b/cli/src/util/js.ts @@ -4,7 +4,7 @@ export function formatJSObject(o: { [key: string]: any }): string { try { o = JSON.parse(JSON.stringify(o)); } catch (e: any) { - throw new Error(`Cannot parse object as JSON: ${e.stack ? e.stack : e}`); + throw new Error(`Cannot parse object as JSON: ${e.stack ? e.stack : e}`, { cause: e }); } return util.inspect(o, { diff --git a/cli/src/util/monorepotools.ts b/cli/src/util/monorepotools.ts index 19367aa683..3b05a9422f 100644 --- a/cli/src/util/monorepotools.ts +++ b/cli/src/util/monorepotools.ts @@ -90,7 +90,7 @@ export function isMonorepo(currentPath: string): boolean { try { findMonorepoRoot(currentPath); return true; - } catch (error) { + } catch { return false; } } @@ -104,7 +104,7 @@ export function isNXMonorepo(currentPath: string): boolean { try { findNXMonorepoRoot(currentPath); return true; - } catch (error) { + } catch { return false; } } diff --git a/cli/src/util/node.ts b/cli/src/util/node.ts index 6f511da25b..a697c0c7bd 100644 --- a/cli/src/util/node.ts +++ b/cli/src/util/node.ts @@ -45,6 +45,7 @@ export const requireTS = async (ts: typeof typescript, p: string): Promise { try { return (await runCommand(command, args, options)).trim(); - } catch (e) { + } catch { return null; } } @@ -38,7 +38,7 @@ export async function getCommandOutput( export async function isInstalled(command: string): Promise { try { await which(command); - } catch (e) { + } catch { return false; } diff --git a/cli/src/util/xml.ts b/cli/src/util/xml.ts index 8a635c7256..b5dcd6b91f 100644 --- a/cli/src/util/xml.ts +++ b/cli/src/util/xml.ts @@ -9,7 +9,7 @@ export async function readXML(path: string): Promise { } catch (e: any) { throw `Error parsing: ${path}, ${e.stack ?? e}`; } - } catch (e) { + } catch { throw `Unable to read: ${path}`; } } diff --git a/cli/test/capacitor-package.spec.ts b/cli/test/capacitor-package.spec.ts index 1a61d65fc5..9498e75bb0 100644 --- a/cli/test/capacitor-package.spec.ts +++ b/cli/test/capacitor-package.spec.ts @@ -14,7 +14,7 @@ jest.mock('../src/common', () => ({ getCapacitorPackageVersion: jest.fn(), })); -// eslint-disable-next-line @typescript-eslint/no-var-requires +// eslint-disable-next-line @typescript-eslint/no-require-imports const { getCapacitorPackageVersion } = require('../src/common'); const SPM_DIR = '/app/ios/App/CapApp-SPM'; diff --git a/core/native-bridge.ts b/core/native-bridge.ts index 50f799f81b..a3a7c5234e 100644 --- a/core/native-bridge.ts +++ b/core/native-bridge.ts @@ -81,7 +81,7 @@ const convertBody = async ( if (contentType === 'application/json') { try { data = JSON.parse(data); - } catch (ignored) { + } catch { // ignore } type = 'json'; @@ -370,7 +370,7 @@ const initBridge = (w: any): void => { msg = JSON.stringify(msg); } return String(msg); - } catch (e) { + } catch { return ''; } }; @@ -1123,7 +1123,6 @@ const initBridge = (w: any): void => { }); }; - // eslint-disable-next-line @typescript-eslint/no-unused-vars cap.withPlugin = (_pluginId, _fn) => dummy; cap.Exception = CapacitorException; diff --git a/core/src/tests/bridge.spec.ts b/core/src/tests/bridge.spec.ts index daf7f0328e..13fa9e0053 100644 --- a/core/src/tests/bridge.spec.ts +++ b/core/src/tests/bridge.spec.ts @@ -15,7 +15,6 @@ describe('bridge', () => { initBridge(win); // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore - // eslint-disable-next-line @typescript-eslint/no-empty-function window.prompt = () => {}; }); diff --git a/eslint.config.cjs b/eslint.config.cjs new file mode 100644 index 0000000000..85793cfeb7 --- /dev/null +++ b/eslint.config.cjs @@ -0,0 +1,17 @@ +const ionic = require('@ionic/eslint-config/recommended'); + +module.exports = [ + { + ignores: [ + '**/build/**', + 'cli/assets/**', + '**/dist/**', + '**/types/**', + // lint TypeScript only + '**/*.js', + '**/*.mjs', + '**/*.cjs', + ], + }, + ...ionic, +]; diff --git a/package.json b/package.json index 8f339f1966..acb713c7a5 100644 --- a/package.json +++ b/package.json @@ -20,20 +20,17 @@ "lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint", "fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- --fix --format", "prettier": "prettier \"**/*.{css,html,java,js,mjs,ts}\" --plugin=prettier-plugin-java", - "eslint": "eslint . --ext ts", + "eslint": "eslint .", "swiftlint": "node-swiftlint", "version": "npm run sync-peer-dependencies" }, "prettier": "@ionic/prettier-config", - "eslintConfig": { - "extends": "@ionic/eslint-config/recommended" - }, "devDependencies": { - "@ionic/eslint-config": "^0.4.0", + "@ionic/eslint-config": "^0.5.0", "@ionic/prettier-config": "^4.0.0", "@ionic/swiftlint-config": "^2.0.0", "@types/node": "18.18.6", - "eslint": "^8.57.0", + "eslint": "^10.0.0", "lerna": "^7.1.3", "prettier": "^3.3.0", "prettier-plugin-java": "^2.6.4",