Example app using eslint, prettier, airbnb-base, and typescript
Start by installing the necessary dependencies:
# eslint-config-airbnb-base and all peerDependencies
npx install-peerdeps --dev eslint-config-airbnb-base
# install all other devDependencies
npm install eslint-config-airbnb-typescript \
@typescript-eslint/eslint-plugin@^5.13.0 \
@typescript-eslint/parser@^5.0.0 \
typescript \
prettier \
eslint-plugin-prettier \
eslint-config-prettier \
--save-devAfter the dependencies are installed, create a new tsconfig.json file at your project's root:
This will be your main TypeScript config file that defines your TypeScript project settings.
Then create tsconfig.eslint.json:
// tsconfig.eslint.json
{
"extends": "./tsconfig.json",
"include": ["./**/*.ts", "./**/*.js", "./.*.js"]
}This defines is the config that will be read by eslint.
Create your eslint config at .eslintrc.js:
// .eslintrc.js
module.exports = {
root: true,
plugins: ['@typescript-eslint', 'import', 'prettier'],
extends: [
'airbnb-typescript/base',
'prettier',
'plugin:@typescript-eslint/recommended',
'plugin:import/typescript',
],
parser: '@typescript-eslint/parser',
parserOptions: {
project: './tsconfig.eslint.json',
},
};Create a new .prettierrc file and define your own Prettier rule:
// .prettierrc
{
"printWidth": 80,
"tabWidth": 2,
"useTabs": false,
"semi": true,
"singleQuote": true,
"trailingComma": "es5",
"bracketSpacing": true,
"jsxSingleQuote": false,
"arrowParens": "always",
"proseWrap": "never",
"htmlWhitespaceSensitivity": "strict",
"endOfLine": "lf"
}{
"lint": "eslint --fix . && prettier --write .",
"build": "tsc"
}With that, your project is configured to use eslint, prettier, airbnb-base and typescript - setting you up for a successful linting configuration that will maintain a consistent style guide.