Code Linting
Linting your code greatly improves consistency and readability. This leads to improved maintainability, and often reduces bugs caused to coding quirks. Whilst completely optional, it is encouraged to lint your code; to assist with this, Elgato provides pre-defined configurations that we use for our projects.
Quick Start
Install the ESLint and Prettier configurations.
npm install @elgato/eslint-config @elgato/prettier-config --save-devUpdate your package.json file to include a lint script, and configure Prettier.
{
"scripts": {
"lint": "eslint --max-warnings 0"
},
"prettier": "@elgato/prettier-config"
}At the root of your project, download the .editorconfig file to configure your IDE, and create a eslint.config.js file to configure ESLint.
import { config } from "@elgato/eslint-config";
export default config.recommended;ESLint
ESLint is a popular static code analysis tool for JavaScript and Typescript projects, allowing you to quickly identify and resolve problems. The ESLing configuration used within Elgato's project is available publicly, and can optionally be added to your projects.
Installation
Install @elgato/eslint-config as a devDependency.
npm install @elgato/eslint-config --save-devCreate an eslint.config.js file at the root of your project.
import { config } from "@elgato/eslint-config";
export default config.recommended;There are two configurations available:
- Recommended —
config.recommended - Strict —
config.strict(stricter type enforcing)
Usage
The ESLint CLI provides an array of useful commands. These can optionally be added to your package.json scripts object to further streamline checking and formatting, for example.
- NPM Script
- Terminal
{
"scripts": {
"lint": "eslint --max-warnings 0"
}
}eslint --max-warnings 0Configuration
Extends
- JSDoc recommended
- ESLint recommended
- TypeScript ESLint recommended
Rules
| Rule | Recommended | Strict | Notes |
|---|---|---|---|
| Indent: Tabs | ⚠️ Warn | ⚠️ Warn | |
| JSDoc: Check tag names | ⚠️ Warn | ⚠️ Warn | Additional tags: csspart, cssproperty, jest-environment, slot |
| JSDoc: No undefined types | ⚠️ Warn | ⚠️ Warn | |
| JSDoc: Require JSDoc | ⚠️ Warn | ⚠️ Warn | |
| JSDoc: Require Returns | ⚠️ Warn | ⚠️ Warn | Disabled for getters. |
| TypeScript: Explicit function return types | ✅ Off | ⚠️ Warn | Disabled for JavaScript, tests, and mock files. |
| TypeScript: Explicit member accessibility | ⚠️ Warn | ⚠️ Warn | No public required constructor. |
| TypeScript: Member ordering | ⚠️ Warn | ⚠️ Warn | Grouped by type and then access, and ordered alphabetically. |
| TypeScript: Sort type constituents |