npm install @elgato/eslint-config --save-dev
Create an eslint.config.js
file at the root of your project.
// eslint.config.js
import { config } from "@elgato/eslint-config";
export default config.recommended;
Then add a linting script to your package.json
file.
{
"scripts": {
"lint": "eslint --max-warnings 0"
}
}
Finally, to test everything is working run npm run lint
.
The recommended
configuration is catered for TypeScript, and enforces stricter types through explicit return types and no any
, amongst other rules. Additionally, the configuration emphasizes the importance of well-documented code (jsdocs) and encourages structured code in the form of member ordering.
- JSDoc recommended
- ESLint recommended
- TypeScript ESLint recommended
Rule | Severity | Notes |
---|---|---|
Indent: Tabs | ||
JSDoc: Check tag names | ||
JSDoc: No undefined types | ||
JSDoc: Require JSDoc | ||
TypeScript: Explicit function return types | Disabled for JavaScript, tests, and mock files. | |
TypeScript: Explicit member accessibility | No public required constructor . |
|
TypeScript: Member ordering | Grouped by type and then access, and ordered alphabetically. | |
TypeScript: Sort type constituents |
Additionally, the following rules are disabled for test and mock files:
- TypeScript: No explicit
any
- TypeScript: No
require
imports
-
Mocks and tests
- Allow
any
andrequire
. - Do not require explicit return types.
- Allow
.github/
bin/
dist/
node_modules/
Members of a class should be grouped by type and then by access, and ordered alphabetically. The ordering is as follows:
Type Order
- Fields
- Constructors
- Signatures / call signatures
- Properties (get / set)
- Methods
Access Order
- Public (static / abstract / regular)
- Protected (static / abstract / regular)
- Private (static / abstract / regular)
Configuration settings can be overriden using the defineConfig
helper function from ESLint, extending @elgato/eslint-config
, and then defining your preferred settings.
// eslint.config.js
import { defineConfig } from "eslint/config";
import { config } from "@elgato/eslint-config";
export default defineConfig([
{
extends: [export default config.recommended],
// Anything from here will override @elgato/eslint-config
rules: {
"no-unused-vars": "warn",
},
},
]);
Learn more about overriding settings.