https://github.com/stackvault/eslint-config-typescript
TypeScript ESLint configuration
https://github.com/stackvault/eslint-config-typescript
code-quality code-style eslint eslint-config eslint9 eslintconfig flat-config lint stackvault stylistic type-checking typescript typescript-eslint
Last synced: 26 days ago
JSON representation
TypeScript ESLint configuration
- Host: GitHub
- URL: https://github.com/stackvault/eslint-config-typescript
- Owner: stackvault
- License: mit
- Created: 2025-09-05T21:11:54.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2025-09-06T12:13:55.000Z (9 months ago)
- Last Synced: 2025-10-06T01:28:52.073Z (8 months ago)
- Topics: code-quality, code-style, eslint, eslint-config, eslint9, eslintconfig, flat-config, lint, stackvault, stylistic, type-checking, typescript, typescript-eslint
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/@stackvault/eslint-config-typescript
- Size: 31.3 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# @stackvault/eslint-config-typescript
Modern TypeScript ESLint configuration with strict type checking and comprehensive stylistic rules. Built for ESLint 9+ flat config with full TypeScript 5.5+ support.
## Features
- ✨ **ESLint 9 Flat Config** - Modern configuration format with better performance
- 🎯 **Strict Type Checking** - Comprehensive type-aware rules to catch errors at build time
- 🎨 **Built-in Formatting** - Replaces Prettier with @stylistic/eslint-plugin for unified tooling
- 🚀 **TypeScript 5.5+ Support** - Leverages latest TypeScript features and optimizations
- 📦 **Zero Config Philosophy** - Sensible defaults that work out of the box
- ⚡ **Performance Optimized** - Uses `projectService` for faster type checking
## Installation
```bash
npm install --save-dev @stackvault/eslint-config-typescript eslint typescript
```
or with Yarn:
```bash
yarn add --dev @stackvault/eslint-config-typescript eslint typescript
```
## Requirements
- Node.js >=18.18.0
- ESLint >=9.22.0
- TypeScript >=5.5.0
## Usage
Create an `eslint.config.js` file in your project root:
```javascript
import typeScriptConfig from '@stackvault/eslint-config-typescript';
export default [
...typeScriptConfig,
// Your custom rules here
];
```
### With Custom Rules
```javascript
import typeScriptConfig from '@stackvault/eslint-config-typescript';
export default [
...typeScriptConfig,
{
rules: {
// Override or add custom rules
'no-console': 'off',
'@typescript-eslint/no-explicit-any': 'warn',
}
}
];
```
### For Monorepos
```javascript
import typeScriptConfig from '@stackvault/eslint-config-typescript';
export default [
...typeScriptConfig,
{
languageOptions: {
parserOptions: {
projectService: true,
tsconfigRootDir: import.meta.dirname,
project: ['./packages/*/tsconfig.json'],
}
}
}
];
```
## What's Included
### Type Safety Rules
- **Strict type checking** with `strictTypeChecked` and `stylisticTypeChecked` configs
- **No unsafe operations** - Prevents `any` type pollution
- **Smart boolean expressions** - Allows practical nullish checks while maintaining safety
- **Comprehensive async/promise rules** - Ensures proper handling of asynchronous code
### Code Organization
- **Enforced import sorting** with eslint-plugin-simple-import-sort
- **Consistent type imports** - Prefers `import { type User }` syntax
- **Naming conventions** - PascalCase for types/interfaces, T-prefix for generics
- **Explicit return types** for functions (with smart exceptions)
### Stylistic Rules (Prettier Replacement)
Built-in formatting rules via @stylistic/eslint-plugin:
- 2-space indentation
- Single quotes
- Semicolons required
- Trailing commas in multiline
- 120 character line limit
- Consistent spacing and formatting
### Special File Handling
- **Test files** (`*.spec.ts`, `*.test.ts`) - Relaxed rules for testing
- **JavaScript files** - Type checking disabled, basic linting enabled
- **Declaration files** (`*.d.ts`) - Minimal rules for type definitions
## Key Rules Explained
### Type Safety
```typescript
// ❌ Error: no-explicit-any
const data: any = fetchData();
// ✅ Correct
const data: User = fetchData();
```
### Smart Boolean Expressions
```typescript
// ✅ Allowed - practical nullish checks
if (user) { } // User | null
if (isEnabled) { } // boolean | undefined
// ❌ Error - string/number coercion
if (userName) { } // string (use userName !== '')
if (count) { } // number (use count !== 0)
```
### Async/Promise Handling
```typescript
// ❌ Error: no-floating-promises
fetchData();
// ✅ Correct
await fetchData();
// or
void fetchData();
```
### Import Organization
```typescript
// ✅ Automatically sorted and organized
import { type User, type Product } from '@/types';
import { calculateTotal } from '@/utils';
import React from 'react';
```
## VSCode Integration
Add to `.vscode/settings.json`:
```json
{
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit"
},
"eslint.experimental.useFlatConfig": true,
"eslint.validate": [
"javascript",
"javascriptreact",
"typescript",
"typescriptreact"
]
}
```
## Package.json Scripts
```json
{
"scripts": {
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"lint:debug": "eslint . --debug",
"type-check": "tsc --noEmit"
}
}
```
## Migration from ESLint 8
1. Remove `.eslintrc.*` files
2. Create `eslint.config.js` with flat config
3. Update VSCode settings for flat config
4. Remove Prettier (this config handles formatting)
## Performance Tips
- Use `projectService: true` for better TypeScript performance
- Enable ESLint cache: `eslint . --cache`
- Exclude build directories in your tsconfig.json
- Consider using `--max-warnings 0` in CI/CD
## Philosophy
This configuration prioritizes:
1. **Type Safety** - Catch errors at build time, not runtime
2. **Consistency** - Unified formatting without Prettier
3. **Performance** - Optimized for large TypeScript projects
4. **Developer Experience** - Clear errors with practical rules
## License
MIT
## Contributing
Issues and PRs welcome at [GitHub](https://github.com/stackvault/eslint-config-typescript)