From 4bffdb542a3fa4ce7d1e6c8a9d9cd67bb366c4f9 Mon Sep 17 00:00:00 2001 From: Chace Daniels Date: Wed, 2 Sep 2026 10:23:13 -0500 Subject: [PATCH] feat: update plugins to ESLint 10 --- eslint.config.cjs | 14 ++++++++++++ package.json | 12 +++++------ src/index.ts | 54 ++++++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 70 insertions(+), 10 deletions(-) create mode 100644 eslint.config.cjs diff --git a/eslint.config.cjs b/eslint.config.cjs new file mode 100644 index 0000000..0752f1f --- /dev/null +++ b/eslint.config.cjs @@ -0,0 +1,14 @@ +const ionic = require('@ionic/eslint-config/recommended'); + +module.exports = [ + { + ignores: [ + '**/dist/**', + // lint TypeScript only + '**/*.js', + '**/*.mjs', + '**/*.cjs', + ], + }, + ...ionic, +]; diff --git a/package.json b/package.json index 63c4771..9cf90c5 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "scripts": { "lint": "npm run eslint && npm run prettier -- --check", "fmt": "npm run eslint -- --fix && npm run prettier -- --write", - "eslint": "eslint . --ext ts", + "eslint": "eslint .", "prettier": "prettier \"**/*.{css,html,js,mjs,ts,json}\"", "build": "npm run clean && tsc", "clean": "rimraf ./dist", @@ -30,19 +30,17 @@ "author": "Ionic Team ", "license": "MIT", "prettier": "@ionic/prettier-config", - "eslintConfig": { - "extends": "@ionic/eslint-config/recommended" - }, "bugs": { "url": "https://github.com/ionic-team/migrate-capacitor-plugin/issues" }, "homepage": "https://github.com/ionic-team/migrate-capacitor-plugin#readme", "devDependencies": { - "@ionic/eslint-config": "^0.4.0", + "@ionic/eslint-config": "^1.0.0", "@ionic/prettier-config": "^4.0.0", "@types/fs-extra": "^11.0.4", "@types/node": "^24.10.1", - "eslint": "^8.57.0", + "@types/semver": "^7.7.1", + "eslint": "^10.0.0", "prettier": "^3.6.2", "typescript": "^5.9.3" }, @@ -54,4 +52,4 @@ "rimraf": "^6.1.0", "semver": "^7.7.3" } -} \ No newline at end of file +} diff --git a/src/index.ts b/src/index.ts index 12fa32d..9860b04 100644 --- a/src/index.ts +++ b/src/index.ts @@ -20,9 +20,34 @@ const gradleVersion = '9.5.1'; const AGPVersion = '9.2.1'; const gmsVersion = '4.5.0'; const docgenVersion = '^0.3.1'; -const eslintVersion = '^8.57.1'; -const ionicEslintVersion = '^0.4.0'; +const eslintVersion = '^10.0.0'; +const ionicEslintVersion = '^1.0.0'; const ionicPrettierVersion = '^4.0.0'; + +const eslintConfigCjs = `const ionic = require('@ionic/eslint-config/recommended'); + +module.exports = [ + { + ignores: [ + '**/build/**', + '**/dist/**', + 'example-app/**', + // lint TypeScript only + '**/*.js', + '**/*.mjs', + '**/*.cjs', + ], + }, + ...ionic, + { + files: ['**/*.ts'], + rules: { + // underscore-prefixed parameters are intentionally unused (interface signatures) + '@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }], + }, + }, +]; +`; const ionicSwiftlintVersion = '^2.0.0'; const prettierJavaVersion = '^2.7.7'; const prettierVersion = '^3.6.2'; @@ -82,11 +107,17 @@ export const run = async (): Promise => { pluginJSON.peerDependencies[dep] = `>=${coreVersion}`; } } + let eslintUpdated = false; if (pluginJSON.devDependencies?.['@ionic/eslint-config']) { pluginJSON.devDependencies['@ionic/eslint-config'] = ionicEslintVersion; if (pluginJSON.devDependencies?.['eslint']) { pluginJSON.devDependencies['eslint'] = eslintVersion; } + delete pluginJSON.eslintConfig; + if (pluginJSON.scripts?.['eslint']) { + pluginJSON.scripts['eslint'] = pluginJSON.scripts['eslint'].replace(' --ext ts', ''); + } + eslintUpdated = true; } if (pluginJSON.devDependencies?.['@ionic/swiftlint-config']) { pluginJSON.devDependencies['@ionic/swiftlint-config'] = ionicSwiftlintVersion; @@ -165,6 +196,16 @@ export const run = async (): Promise => { writeFileSync(packageJson, packageJsonText, 'utf-8'); + if (eslintUpdated) { + const eslintIgnore = join(dir, '.eslintignore'); + if (existsSync(eslintIgnore)) { + removeSync(eslintIgnore); + } + if (!['eslint.config.js', 'eslint.config.mjs', 'eslint.config.cjs'].some((file) => existsSync(join(dir, file)))) { + writeFileSync(join(dir, 'eslint.config.cjs'), eslintConfigCjs, 'utf-8'); + } + } + rimraf.sync(join(dir, 'node_modules/@capacitor')); rimraf.sync(join(dir, 'package-lock.json')); @@ -173,7 +214,7 @@ export const run = async (): Promise => { ...opts, cwd: dir, }); - } catch (e: any) { + } catch { logger.warn('npm install failed, please, install the dependencies using your package manager of choice'); } @@ -238,6 +279,13 @@ export const run = async (): Promise => { logger.info('Plugin migrated to Capacitor 9!'); + if (eslintUpdated) { + logger.info(''); + logger.info('⚠️ Note: ESLint has been updated to v10 and @ionic/eslint-config to v1, which uses flat config.'); + logger.info('An eslint.config.cjs file was added; .eslintignore and the eslintConfig block in package.json were removed.'); + logger.info('Running lint may surface new reports; see https://github.com/ionic-team/eslint-config#migrating-from-0x'); + } + if (prettierUpdatedFromV2) { logger.info(''); logger.info('⚠️ Note: Prettier has been updated from v2 to v3.');