What is eslint-config-airbnb-typescript?
The eslint-config-airbnb-typescript package extends Airbnb's ESLint configuration, adapting it for TypeScript. It provides a set of linting rules that enforce JavaScript and TypeScript coding standards and best practices as defined by Airbnb. This package is designed to work with projects using TypeScript, helping developers to write cleaner, more consistent, and error-free code.
What are eslint-config-airbnb-typescript's main functionalities?
TypeScript Support
Integrates Airbnb's ESLint rules with TypeScript-specific adjustments. This feature allows developers to apply Airbnb's rigorous coding standards to TypeScript projects, ensuring consistency and quality in the codebase.
"extends": ["airbnb", "airbnb-typescript"]
Customizable Rules
Allows customization of linting rules. Developers can override or extend the default set provided by Airbnb to tailor the linting process to their project's specific needs, ensuring flexibility and control over code quality.
{
"rules": {
"@typescript-eslint/no-unused-vars": "error",
"react/jsx-filename-extension": [1, { "extensions": [".tsx"] }]
}
}
Other packages similar to eslint-config-airbnb-typescript
eslint-config-google
Provides a set of linting rules based on Google's JavaScript style guide. Similar to eslint-config-airbnb-typescript, it enforces coding standards and best practices but follows Google's guidelines instead of Airbnb's. It does not have built-in TypeScript support but can be adapted for use with TypeScript projects.
eslint-config-standard
An ESLint configuration package that adheres to the 'JavaScript Standard Style' guidelines. Unlike eslint-config-airbnb-typescript, which is tailored for Airbnb's style guide and TypeScript, eslint-config-standard focuses on a different set of rules and principles for JavaScript projects. TypeScript support can be added through additional plugins.
eslint-config-prettier
Disables all ESLint rules that are unnecessary or might conflict with Prettier. While eslint-config-airbnb-typescript focuses on enforcing specific coding standards, eslint-config-prettier is designed to be used in conjunction with other ESLint configurations to ensure compatibility with Prettier, rather than to enforce its own style rules.
eslint-config-airbnb-typescript
Airbnb's ESLint config with TypeScript support
Works with both JS and TS files.
I use eslint-config-airbnb (with React support)
Install dependencies. ESLint plugins must also be installed.
npm install eslint-config-airbnb-typescript \
eslint-plugin-import@^2.20.1 \
eslint-plugin-jsx-a11y@^6.2.3 \
eslint-plugin-react@^7.19.0 \
eslint-plugin-react-hooks@^2.5.0 \
@typescript-eslint/eslint-plugin@^3.1.0 \
--save-dev
Within your ESLint config file:
module.exports = {
extends: ['airbnb-typescript'],
parserOptions: {
project: './tsconfig.json',
},
};
Alter your eslint
command to include ts
and tsx
files:
eslint --ext .js,.jsx,.ts,.tsx ./
I use eslint-config-airbnb-base (no React support)
Install dependencies. ESLint plugins must also be installed.
npm install eslint-config-airbnb-typescript \
eslint-plugin-import@^2.20.1 \
@typescript-eslint/eslint-plugin@^3.1.0 \
--save-dev
Within your ESLint config file:
module.exports = {
extends: ['airbnb-typescript/base'],
parserOptions: {
project: './tsconfig.json',
},
};
Alter your eslint
command to include ts
and tsx
files:
eslint --ext .js,.jsx,.ts,.tsx ./
I wish this config would support [...]
The goal of eslint-config-airbnb-typescript
is decorate eslint-config-airbnb
with TypeScript support. All rules and settings are identical. It's a drop-in replacement for eslint-config-airbnb
, including linting for JavaScript files.
It's recommended to alter your ESLint config for additional functionality. Here's an example:
{
"extends": [
"airbnb-typescript",
"airbnb/hooks",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking"
],
}
My personal ESLint config file with support for Jest, Promises, and Prettier can be found in create-exposed-app.
Additional Documentation
Credits
Authored and maintained by Matt Turnbull (iamturns.com / @iamturns)
To all contributors (if you exist) - thank you!
License
Open source licensed as MIT.