├── .gitignore ├── .npmrc ├── LICENSE ├── README.md ├── index.js ├── package.json └── recommended.js /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | 6 | # Runtime data 7 | pids 8 | *.pid 9 | *.seed 10 | 11 | # Directory for instrumented libs generated by jscoverage/JSCover 12 | lib-cov 13 | 14 | # Coverage directory used by tools like istanbul 15 | coverage 16 | 17 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 18 | .grunt 19 | 20 | # node-waf configuration 21 | .lock-wscript 22 | 23 | # Compiled binary addons (http://nodejs.org/api/addons.html) 24 | build/Release 25 | 26 | # Dependency directory 27 | node_modules 28 | 29 | # Optional npm cache directory 30 | .npm 31 | 32 | # Optional REPL history 33 | .node_repl_history 34 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | package-lock=false 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Ionic 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # @ionic/eslint-config 2 | 3 | Shared ESLint config used in Ionic and Capacitor projects. 4 | 5 | This is meant to be used alongside Prettier (with [`@ionic/prettier-config`](https://github.com/ionic-team/prettier-config/)). 6 | 7 | ## Usage 8 | 9 | 1. Remove existing `.eslintrc.*` file, if present. 10 | 1. Install `eslint` and the config. 11 | 12 | ``` 13 | npm install -D eslint @ionic/eslint-config 14 | ``` 15 | 16 | 1. Add the following to `package.json`: 17 | 18 | ``` 19 | "eslintConfig": { 20 | "extends": "@ionic/eslint-config/recommended" 21 | } 22 | ``` 23 | 24 | :memo: You can also use the base rule set: `@ionic/eslint-config` 25 | 26 | ### With Prettier and `@ionic/prettier-config` 27 | 28 | 1. Set up Prettier and [`@ionic/prettier-config`](https://github.com/ionic-team/prettier-config/). 29 | 1. When using with Prettier and `@ionic/prettier-config`, ESLint should run first. Set up your scripts in `package.json` like this: 30 | 31 | ```json 32 | "scripts": { 33 | "lint": "npm run eslint && npm run prettier -- --check", 34 | "fmt": "npm run eslint -- --fix && npm run prettier -- --write", 35 | "prettier": "prettier \"**/*.ts\"", 36 | "eslint": "eslint . --ext .ts", 37 | } 38 | ``` 39 | 40 | - `npm run lint`: for checking if ESLint and Prettier complain 41 | - `npm run fmt`: attempt to autofix lint issues and autoformat code 42 | 43 | :memo: Not every rule in this configuration is autofixable, so `npm run fmt` may continue failing until lint issues are addressed manually. 44 | 45 | ### With Husky 46 | 47 | 1. Install [husky](https://github.com/typicode/husky): 48 | 49 | ``` 50 | npm install -D husky 51 | ``` 52 | 53 | 1. Add the following to `package.json`: 54 | 55 | ``` 56 | "husky": { 57 | "hooks": { 58 | "pre-commit": "npm run lint" 59 | } 60 | }, 61 | ``` 62 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | parser: '@typescript-eslint/parser', 3 | plugins: [ 4 | '@typescript-eslint', 5 | 'import' 6 | ], 7 | extends: [ 8 | 'eslint:recommended', 9 | 'plugin:@typescript-eslint/recommended', 10 | 'prettier', 11 | 'plugin:import/typescript', 12 | ], 13 | rules: { 14 | // https://eslint.org/docs/rules/ 15 | 'no-fallthrough': 'off', // https://github.com/ionic-team/eslint-config/issues/7 16 | 'no-constant-condition': 'off', 17 | 18 | // https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/eslint-plugin/docs/rules 19 | '@typescript-eslint/no-this-alias': 'off', 20 | '@typescript-eslint/no-explicit-any': 'off', 21 | '@typescript-eslint/explicit-module-boundary-types': ['warn', { 'allowArgumentsExplicitlyTypedAsAny': true }], 22 | }, 23 | }; -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@ionic/eslint-config", 3 | "version": "0.4.0", 4 | "description": "Common eslint rules/preferences for Ionic.", 5 | "main": "index.js", 6 | "repository": { 7 | "type": "git", 8 | "url": "git+https://github.com/ionic-team/eslint-config.git" 9 | }, 10 | "keywords": [ 11 | "eslint", 12 | "eslintconfig", 13 | "lint", 14 | "ionic", 15 | "typescript" 16 | ], 17 | "author": "Ionic ", 18 | "license": "MIT", 19 | "bugs": { 20 | "url": "https://github.com/ionic-team/eslint-config/issues" 21 | }, 22 | "homepage": "https://github.com/ionic-team/eslint-config#readme", 23 | "dependencies": { 24 | "@typescript-eslint/eslint-plugin": "^5.58.0", 25 | "@typescript-eslint/parser": "^5.58.0", 26 | "eslint-config-prettier": "^8.8.0", 27 | "eslint-plugin-import": "^2.27.0" 28 | }, 29 | "peerDependencies": { 30 | "eslint": ">=7" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /recommended.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | extends: [ 3 | './index', 4 | 'plugin:import/typescript', 5 | ], 6 | plugins: [ 7 | 'import', 8 | ], 9 | rules: { 10 | // ./index.js 11 | '@typescript-eslint/explicit-module-boundary-types': [ 12 | 'error', 13 | { allowArgumentsExplicitlyTypedAsAny: true }, 14 | ], 15 | // https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/eslint-plugin/docs/rules 16 | '@typescript-eslint/array-type': 'error', 17 | '@typescript-eslint/consistent-type-assertions': 'error', 18 | '@typescript-eslint/consistent-type-imports': 'error', 19 | '@typescript-eslint/prefer-for-of': 'error', 20 | '@typescript-eslint/prefer-optional-chain': 'error', 21 | 22 | // https://github.com/benmosher/eslint-plugin-import 23 | 'import/first': 'error', 24 | 'import/order': [ 25 | 'error', 26 | { 27 | 'alphabetize': { order: 'asc', caseInsensitive: false }, 28 | 'groups': [['builtin', 'external'], 'parent', ['sibling', 'index']], 29 | 'newlines-between': 'always', 30 | }, 31 | ], 32 | 'import/newline-after-import': 'error', 33 | 'import/no-duplicates': 'error', 34 | 'import/no-mutable-exports': 'error', 35 | }, 36 | }; 37 | --------------------------------------------------------------------------------