Example app using eslint, prettier, airbnb-base, and typescript
Start by installing the necessary dependencies:
npm install --save-dev \
@typescript-eslint/eslint-plugin \
eslint \
eslint-config-airbnb-base \
eslint-config-airbnb-typescript \
eslint-plugin-import \
eslint-plugin-prettier \
prettier \
typescriptAfter 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,
extends: 'airbnb-typescript/base',
plugins: ['import', 'prettier'],
parserOptions: {
project: './tsconfig.eslint.json',
},
};This config will:
- Extend the
airbnb-typescript/baseconfig - Use the
importandprettiereslint plugins - Read settings defined in
tsconfig.eslint.jsonfor
Create a new .prettierrc file and define your own Prettier rule:
{
"printWidth": 80,
"tabWidth": 2,
"useTabs": false,
"semi": true,
"singleQuote": true,
"trailingComma": "es5",
"bracketSpacing": true,
"jsxSingleQuote": false,
"arrowParens": "always",
"proseWrap": "never",
"htmlWhitespaceSensitivity": "strict",
"endOfLine": "lf"
}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.