What is eslint-config-google?
The eslint-config-google package provides a shareable ESLint configuration that follows the Google JavaScript style guide. It helps developers enforce consistent coding styles and best practices as defined by Google.
What are eslint-config-google's main functionalities?
Enforcing Google JavaScript Style Guide
By extending the 'google' configuration, ESLint will enforce the coding standards and best practices defined in the Google JavaScript style guide. This includes rules for indentation, quotes, semicolons, and more.
{
"extends": "google"
}
Customizable Rules
You can customize the rules provided by the Google configuration to better fit your project's needs. For example, you can change the quote style to single quotes and set the indentation to 2 spaces.
{
"extends": "google",
"rules": {
"quotes": ["error", "single"],
"indent": ["error", 2]
}
}
Other packages similar to eslint-config-google
eslint-config-airbnb
The eslint-config-airbnb package provides a shareable ESLint configuration based on the Airbnb JavaScript style guide. It is one of the most popular ESLint configurations and includes rules for React as well. Compared to eslint-config-google, it has a broader set of rules and is widely adopted in the JavaScript community.
eslint-config-standard
The eslint-config-standard package provides a shareable ESLint configuration based on JavaScript Standard Style. It focuses on simplicity and minimalism, enforcing a set of rules that aim to reduce cognitive overhead. Unlike eslint-config-google, it does not follow a specific company's style guide but rather a community-driven standard.
eslint-config-prettier
The eslint-config-prettier package turns off all ESLint rules that are unnecessary or might conflict with Prettier. It is often used in conjunction with other ESLint configurations to ensure that code formatting is handled by Prettier while ESLint focuses on code quality. This package complements eslint-config-google by allowing developers to use Prettier for formatting while still adhering to Google's style guide.
eslint-config-google
ESLint shareable config for the Google JavaScript style guide (ES2015+ version)
Installation
$ npm install --save-dev eslint eslint-config-google
Usage
Once the eslint-config-google
package is installed, you can use it by specifying google
in the extends
section of your ESLint configuration.
{
"extends": "google",
"rules": {
}
}
Using the google
config with eslint:recommended
There are several rules in the eslint:recommended
ruleset that Google style is not opinionated about that you might want to enforce in your project.
To use Google style in conjunction with ESLint's recommended rule set, extend them both, making sure to list google
last:
{
"extends": ["eslint:recommended", "google"],
"rules": {
}
}
To see how the google
config compares with eslint:recommended
, refer to the source code of index.js
, which lists every ESLint rule along with whether (and how) it is enforced by the google
config.
License
Apache-2 © Google