Shared ESLint config used in Ionic and Capacitor projects.
This is meant to be used alongside Prettier (with @ionic/prettier-config).
v0.5.0 requires ESLint 10 and a flat config file. Staying on ESLint 8 or 9? Keep using
@ionic/eslint-config@0.4.0.
-
Install
eslintand the config:npm install -D eslint @ionic/eslint-config -
Create an
eslint.config.cjsin your project root:const ionic = require('@ionic/eslint-config/recommended'); module.exports = [ { ignores: ['dist/**', 'build/**'] }, ...ionic, ];
From an ESM config (
eslint.config.mjs), import'@ionic/eslint-config/recommended.js'.
📝 You can also use the base rule set: @ionic/eslint-config
Both rule sets apply only to TypeScript files (.ts, .tsx, .mts, .cts). To lint
JavaScript too, add your own config block.
-
Set up Prettier and
@ionic/prettier-config. -
When using with Prettier and
@ionic/prettier-config, ESLint should run first. Set up your scripts inpackage.jsonlike this:"scripts": { "lint": "npm run eslint && npm run prettier -- --check", "fmt": "npm run eslint -- --fix && npm run prettier -- --write", "prettier": "prettier \"**/*.ts\"", "eslint": "eslint" }
npm run lint: for checking if ESLint and Prettier complainnpm run fmt: attempt to autofix lint issues and autoformat code
📝 Not every rule in this configuration is autofixable, so
npm run fmtmay continue failing until lint issues are addressed manually.
- Delete the
eslintConfigblock frompackage.json(or any.eslintrcfile). - Add an
eslint.config.cjsas shown above. - Move
.eslintignoreentries intoignores, then delete the file. - Drop
--ext tsfrom lint scripts; flat config ignores the flag.
New reports to expect:
no-unused-varsnow flags unusedcatch (e)bindings. Usecatch {}instead.no-var-requireswas renamed tono-require-imports. Update any disable comments.import/*rules are nowimport-x/*. Update any disable comments.prefer-optional-chainis no longer inrecommended; it now requires typed linting. Re-enable it in your own config if you use typed linting.
-
Install husky:
npm install -D husky -
Add the following to
package.json:"husky": { "hooks": { "pre-commit": "npm run lint" } },