@lobehub/eslint-config
v2.0.1
Published
ESLint Flat Config configuration for LobeHub projects
Keywords
Readme
ESLint Flat Config configuration for LobeHub projects
Features
- ESLint 9+ Flat Config
- TypeScript support with type-aware rules
- React / React Native / Next.js / Remix support
- Next.js ESLint rules (
@next/eslint-plugin-next) - Import sorting with
simple-import-sort - Interface and enum key sorting with
perfectionist - Unicorn best practices
- Accessibility rules (jsx-a11y)
- React Compiler support
Installation
pnpm add -D @lobehub/eslint-config eslint typescriptUsage
Create eslint.config.js (or eslint.config.mjs) in your project root:
import { defineConfig } from '@lobehub/eslint-config';
export default defineConfig();With React (Next.js)
import { defineConfig } from '@lobehub/eslint-config';
export default defineConfig({
react: 'next',
next: true,
});With React Native
import { defineConfig } from '@lobehub/eslint-config';
export default defineConfig({
react: 'expo',
reactNative: true,
});With Type-Checked Rules
import { defineConfig } from '@lobehub/eslint-config';
export default defineConfig({
typescript: 'strict',
typeChecked: true,
});With Experimental Decorators
import { defineConfig } from '@lobehub/eslint-config';
export default defineConfig({
parserOptions: {
emitDecoratorMetadata: true,
experimentalDecorators: true,
},
});Full Options
import { defineConfig } from '@lobehub/eslint-config';
export default defineConfig({
// TypeScript support: true | false | 'strict'
typescript: true,
// Enable type-aware rules (requires tsconfig)
typeChecked: false,
// Custom tsconfig path
tsconfigPath: './tsconfig.json',
// React support: true | false | 'next' | 'remix' | 'vite' | 'expo'
react: false,
// React Native support
reactNative: false,
// React Compiler rules
reactCompiler: false,
// Accessibility rules (requires react)
a11y: false,
// Import sorting
sortImports: true,
// Interface and enum key sorting
sortKeys: true,
// Stylistic rules (jsx-sort-props, etc.)
stylistic: true,
// Regexp optimization rules
regexp: true,
// Additional ignore patterns
ignores: ['**/dist/**'],
});Custom Rule Overrides
Use rest parameters to add custom configurations with higher priority:
import { defineConfig } from '@lobehub/eslint-config';
export default defineConfig(
{ react: 'next' },
// Global rule overrides
{
rules: {
'no-console': 'warn',
},
},
// File-specific overrides
{
files: ['**/test/**', '**/*.test.ts', '**/*.spec.ts'],
rules: {
'no-console': 'off',
'@typescript-eslint/no-explicit-any': 'off',
},
},
{
files: ['**/scripts/**'],
rules: {
'unicorn/no-process-exit': 'off',
},
},
);Complex Configuration Example
import { defineConfig } from '@lobehub/eslint-config';
export default defineConfig(
{
react: 'next',
typescript: 'strict',
},
// Relax rules for test files
{
files: ['**/*.test.ts', '**/*.test.tsx', '**/test/**'],
rules: {
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
},
},
// Relax rules for scripts
{
files: ['scripts/**'],
rules: {
'no-console': 'off',
'unicorn/no-process-exit': 'off',
},
},
// Relax rules for config files
{
files: ['*.config.ts', '*.config.js'],
rules: {
'unicorn/no-anonymous-default-export': 'off',
},
},
);Options Reference
| Option | Type | Default | Description |
| --------------- | -------------------------------------------------- | ------- | --------------------------------- |
| typescript | boolean \| 'strict' | true | Enable TypeScript rules |
| typeChecked | boolean | false | Enable type-aware rules |
| tsconfigPath | string \| string[] | - | Custom tsconfig path |
| parserOptions | ParserOptions | - | TypeScript parser options |
| react | boolean \| 'next' \| 'remix' \| 'vite' \| 'expo' | false | Enable React rules |
| reactNative | boolean | false | Enable React Native rules |
| reactCompiler | boolean | false | Enable React Compiler rules |
| next | boolean | false | Enable Next.js ESLint rules |
| a11y | boolean | false | Enable accessibility rules |
| sortImports | boolean | true | Enable import sorting |
| sortKeys | boolean | true | Enable interface/enum/jsx sorting |
| stylistic | boolean | true | Enable stylistic rules |
| regexp | boolean | true | Enable regexp rules |
| ignores | string[] | [] | Additional ignore patterns |
API
function defineConfig(options?: Options, ...configs: FlatConfig[]): FlatConfigArray;options- Configuration options (see table above)...configs- Additional flat configs to append (highest priority)
Requirements
- Node.js >= 18
- ESLint >= 9.0.0
- TypeScript >= 5.0.0 (optional)
License
MIT © LobeHub
