ESLint shareable config for the Google JavaScript style guide
npx @tessl/cli install tessl/npm-eslint-config-google@0.14.0ESLint Config Google provides a shareable ESLint configuration that enforces Google's JavaScript style guide for ES2015+ code. This package serves as a comprehensive linting ruleset that can be easily integrated into JavaScript projects to maintain consistent code style and quality according to Google's coding standards.
npm install --save-dev eslint eslint-config-googleThis package exports a single ESLint configuration object. It is typically used via ESLint's extends mechanism rather than direct import:
// .eslintrc.js or similar ESLint configuration file
module.exports = {
"extends": "google",
"rules": {
// Additional project-specific rules...
}
};For direct access to the configuration object:
const googleConfig = require('eslint-config-google');
// Access the rules object
const rules = googleConfig.rules;ESLint Config Google is a simple configuration package that:
// .eslintrc.js
module.exports = {
"extends": "google",
"rules": {
// Additional, per-project rules...
}
};// .eslintrc.js
module.exports = {
"extends": ["eslint:recommended", "google"],
"rules": {
// Additional, per-project rules...
}
};{
"extends": "google",
"rules": {
// Additional, per-project rules...
}
}The main export is a standard ESLint configuration object containing comprehensive rule definitions.
/**
* Main ESLint configuration object implementing Google JavaScript style guide
* @type {ESLintConfig}
*/
module.exports = {
rules: ESLintRules
};
interface ESLintConfig {
rules: ESLintRules;
}
interface ESLintRules {
[ruleName: string]: ESLintRuleConfig;
}
type ESLintRuleConfig =
| 0 | 1 | 2
| "off" | "warn" | "error"
| [0 | 1 | 2 | "off" | "warn" | "error", ...any[]];The package exports a comprehensive ESLint configuration object with rules organized by category. Below is the complete set of rules as configured in the source:
/**
* Complete ESLint rules configuration from eslint-config-google
* All rules listed exactly as configured in the source code
*/
rules: {
// Possible Errors
"no-cond-assign": 0,
"no-irregular-whitespace": 2,
"no-unexpected-multiline": 2,
"valid-jsdoc": [2, {
requireParamDescription: false,
requireReturnDescription: false,
requireReturn: false,
prefer: {returns: "return"}
}],
// Best Practices
"curly": [2, "multi-line"],
"guard-for-in": 2,
"no-caller": 2,
"no-extend-native": 2,
"no-extra-bind": 2,
"no-invalid-this": 2,
"no-multi-spaces": 2,
"no-multi-str": 2,
"no-new-wrappers": 2,
"no-throw-literal": 2,
"no-with": 2,
"prefer-promise-reject-errors": 2,
// Variables
"no-unused-vars": [2, {args: "none"}],
// Stylistic Issues
"array-bracket-newline": 0,
"array-bracket-spacing": [2, "never"],
"array-element-newline": 0,
"block-spacing": [2, "never"],
"brace-style": 2,
"camelcase": [2, {properties: "never"}],
"comma-dangle": [2, "always-multiline"],
"comma-spacing": 2,
"comma-style": 2,
"computed-property-spacing": 2,
"eol-last": 2,
"func-call-spacing": 2,
"indent": [2, 2, {
"CallExpression": {
"arguments": 2
},
"FunctionDeclaration": {
"body": 1,
"parameters": 2
},
"FunctionExpression": {
"body": 1,
"parameters": 2
},
"MemberExpression": 2,
"ObjectExpression": 1,
"SwitchCase": 1,
"ignoredNodes": [
"ConditionalExpression"
]
}],
"key-spacing": 2,
"keyword-spacing": 2,
"linebreak-style": 2,
"max-len": [2, {
code: 80,
tabWidth: 2,
ignoreUrls: true,
ignorePattern: "goog\\.(module|require)"
}],
"new-cap": 2,
"no-array-constructor": 2,
"no-mixed-spaces-and-tabs": 2,
"no-multiple-empty-lines": [2, {max: 2}],
"no-new-object": 2,
"no-tabs": 2,
"no-trailing-spaces": 2,
"object-curly-spacing": 2,
"one-var": [2, {
var: "never",
let: "never",
const: "never"
}],
"operator-linebreak": [2, "after"],
"padded-blocks": [2, "never"],
"quote-props": [2, "consistent"],
"quotes": [2, "single", {allowTemplateLiterals: true}],
"require-jsdoc": [2, {
require: {
FunctionDeclaration: true,
MethodDefinition: true,
ClassDeclaration: true
}
}],
"semi": 2,
"semi-spacing": 2,
"space-before-blocks": 2,
"space-before-function-paren": [2, {
asyncArrow: "always",
anonymous: "never",
named: "never"
}],
"spaced-comment": [2, "always"],
"switch-colon-spacing": 2,
// ECMAScript 6
"arrow-parens": [2, "always"],
"constructor-super": 2,
"generator-star-spacing": [2, "after"],
"no-new-symbol": 2,
"no-this-before-super": 2,
"no-var": 2,
"prefer-const": [2, {destructuring: "all"}],
"prefer-rest-params": 2,
"prefer-spread": 2,
"rest-spread-spacing": 2,
"yield-star-spacing": [2, "after"]
}Individual rules can be accessed programmatically:
/**
* Access individual rule configurations
* @param {string} ruleName - Name of the ESLint rule
* @returns {ESLintRuleConfig} Rule configuration
*/
const googleConfig = require('eslint-config-google');
const ruleConfig = googleConfig.rules[ruleName];
// Examples:
const indentRule = googleConfig.rules['indent']; // [2, 2, {...}]
const quotesRule = googleConfig.rules['quotes']; // [2, 'single', {...}]
const semiRule = googleConfig.rules['semi']; // 2/**
* ESLint rule severity levels
*/
type ESLintSeverity = 0 | 1 | 2 | "off" | "warn" | "error";
/**
* ESLint rule configuration
*/
type ESLintRuleConfig =
| ESLintSeverity
| [ESLintSeverity, ...any[]];
/**
* Complete ESLint rules object
*/
interface ESLintRules {
[ruleName: string]: ESLintRuleConfig;
}
/**
* ESLint configuration object structure
*/
interface ESLintConfig {
rules: ESLintRules;
}
/**
* Rule-specific option interfaces
*/
interface ValidJSDocOptions {
requireParamDescription: boolean;
requireReturnDescription: boolean;
requireReturn: boolean;
prefer: { returns: string };
}
interface IndentOptions {
CallExpression: { arguments: number };
FunctionDeclaration: { body: number; parameters: number };
FunctionExpression: { body: number; parameters: number };
MemberExpression: number;
ObjectExpression: number;
SwitchCase: number;
ignoredNodes: string[];
}
interface MaxLenOptions {
code: number;
tabWidth: number;
ignoreUrls: boolean;
ignorePattern: string;
}
interface CamelCaseOptions {
properties: "never";
}
interface OneVarOptions {
var: "never";
let: "never";
const: "never";
}
interface QuotesOptions {
allowTemplateLiterals: boolean;
}
interface RequireJSDocOptions {
require: {
FunctionDeclaration: boolean;
MethodDefinition: boolean;
ClassDeclaration: boolean;
};
}
interface SpaceBeforeFunctionParenOptions {
asyncArrow: "always";
anonymous: "never";
named: "never";
}
interface PreferConstOptions {
destructuring: "all";
}
interface NoUnusedVarsOptions {
args: "none";
}This package does not throw errors during normal usage. ESLint itself will validate the configuration and report any issues with rule definitions or conflicting settings.
Common configuration issues: