Airbnb Base ESLint Config for TypeScript
This package provides an ESLint configuration that extends the popular Airbnb Base JavaScript style guide with support for TypeScript. It integrates `@typescript-eslint/parser` and `@typescript-eslint/eslint-plugin` to enable linting TypeScript code according to Airbnb's rules. The current stable version is 1.1.0, last updated in April 2020. This config focuses solely on TypeScript and base JavaScript rules, differentiating it from other Airbnb TypeScript configurations that might include React-specific rules. It requires manual installation of its peer dependencies.
Common errors
-
Failed to load plugin 'import' declared in '.eslintrc.js'
cause The `eslint-plugin-import` peer dependency was not installed or is an incompatible version.fixRun `npm install --save-dev eslint-plugin-import` to install the plugin. Ensure it's a compatible version with your ESLint setup. -
Parsing error: "The file must be included in at least one of the projects provided."
cause ESLint is attempting to lint a file that is not covered by the `include` or `files` array in the `tsconfig.json` specified by `parserOptions.project`.fixVerify that your `tsconfig.json` (or a `tsconfig.eslint.json`) includes the files you are trying to lint in its `include` array. Adjust the `parserOptions.project` path if using a custom TypeScript configuration file for ESLint. -
Definition for rule '@typescript-eslint/no-unsafe-member-access' was not found
cause This error (or similar for `@typescript-eslint` rules) indicates that `@typescript-eslint/eslint-plugin` or `@typescript-eslint/parser` is missing, or an outdated version is installed that does not support the rule.fixEnsure both `@typescript-eslint/eslint-plugin` and `@typescript-eslint/parser` are installed and up-to-date. Run `npm install --save-dev @typescript-eslint/eslint-plugin @typescript-eslint/parser`.
Warnings
- gotcha This ESLint configuration, like many others, requires manual installation of all its peer dependencies. Failing to install packages like `eslint`, `@typescript-eslint/parser`, and `eslint-plugin-import` will lead to 'Module not found' or 'Failed to load plugin' errors.
- gotcha The configuration implicitly relies on `@typescript-eslint/parser`'s `parserOptions.project` setting to function correctly with type-aware rules. This property must point to your `tsconfig.json` file (or an extended version like `tsconfig.eslint.json`).
- gotcha This package (`eslint-config-airbnb-base-typescript`) is based on `eslint-config-airbnb-base`, meaning it does *not* include React-specific linting rules or plugins (`eslint-plugin-react`, `eslint-plugin-jsx-a11y`).
- deprecated This package (ekoeryanto/eslint-config-airbnb-base-typescript) has not seen significant updates since April 2020 (version 1.1.0) and may not fully support the latest ESLint or TypeScript versions. More actively maintained alternatives exist for similar functionality.
Install
-
npm install eslint-config-airbnb-base-typescript -
yarn add eslint-config-airbnb-base-typescript -
pnpm add eslint-config-airbnb-base-typescript
Imports
- airbnb-base-typescript
import airbnbBaseTsConfig from 'eslint-config-airbnb-base-typescript';
module.exports = { extends: ['airbnb-base-typescript'] };
Quickstart
{
// .eslintrc.js (or .eslintrc.cjs)
"root": true,
"env": {
"node": true,
"es2020": true
},
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 2020,
"sourceType": "module",
"project": "./tsconfig.json" // IMPORTANT: Adjust path to your tsconfig.json
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"airbnb-base-typescript"
],
"rules": {
// Add or override rules here, for example:
// "no-console": "warn"
}
}
// To install the necessary packages:
// npm install --save-dev \
// eslint \
// eslint-config-airbnb-base-typescript \
// eslint-plugin-import \
// @typescript-eslint/eslint-plugin \
// @typescript-eslint/parser
// Example tsconfig.json (must include files to be linted):
// {
// "compilerOptions": {
// "target": "es2020",
// "module": "commonjs",
// "strict": true,
// "esModuleInterop": true,
// "forceConsistentCasingInFileNames": true
// },
// "include": ["src/**/*.ts", "test/**/*.ts"]
// }
// To run ESLint:
// npx eslint --ext .js,.ts .