feat: add ESLint flat config, Prettier, dependency-cruiser, and Husky
Setup code quality tooling for the monorepo: - ESLint 9 flat config with TypeScript, import ordering, and NestJS rules - Prettier with consistent formatting across all files - dependency-cruiser enforcing module boundary rules (no cross-module internals, no circular deps) - Husky + lint-staged for pre-commit hooks - Auto-fixed existing files for type imports and import ordering Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
121
eslint.config.mjs
Normal file
121
eslint.config.mjs
Normal file
@@ -0,0 +1,121 @@
|
||||
import js from '@eslint/js';
|
||||
import tseslint from 'typescript-eslint';
|
||||
import importPlugin from 'eslint-plugin-import-x';
|
||||
import eslintConfigPrettier from 'eslint-config-prettier';
|
||||
import globals from 'globals';
|
||||
|
||||
export default tseslint.config(
|
||||
// Global ignores
|
||||
{
|
||||
ignores: [
|
||||
'**/node_modules/**',
|
||||
'**/dist/**',
|
||||
'**/.next/**',
|
||||
'**/coverage/**',
|
||||
'**/*.js',
|
||||
'**/*.cjs',
|
||||
'**/*.mjs',
|
||||
'!eslint.config.mjs',
|
||||
],
|
||||
},
|
||||
|
||||
// Base JS recommended rules
|
||||
js.configs.recommended,
|
||||
|
||||
// TypeScript recommended rules
|
||||
...tseslint.configs.recommended,
|
||||
|
||||
// Import plugin
|
||||
importPlugin.flatConfigs.recommended,
|
||||
importPlugin.flatConfigs.typescript,
|
||||
|
||||
// Prettier (disables conflicting rules)
|
||||
eslintConfigPrettier,
|
||||
|
||||
// Shared settings for all TS files
|
||||
{
|
||||
files: ['**/*.ts', '**/*.tsx'],
|
||||
languageOptions: {
|
||||
globals: {
|
||||
...globals.node,
|
||||
},
|
||||
},
|
||||
settings: {
|
||||
'import-x/resolver': {
|
||||
typescript: {
|
||||
project: ['apps/*/tsconfig.json', 'tsconfig.base.json'],
|
||||
},
|
||||
},
|
||||
},
|
||||
rules: {
|
||||
// TypeScript
|
||||
'@typescript-eslint/no-unused-vars': [
|
||||
'error',
|
||||
{ argsIgnorePattern: '^_', varsIgnorePattern: '^_' },
|
||||
],
|
||||
'@typescript-eslint/no-explicit-any': 'warn',
|
||||
'@typescript-eslint/consistent-type-imports': [
|
||||
'error',
|
||||
{ prefer: 'type-imports', fixStyle: 'inline-type-imports' },
|
||||
],
|
||||
|
||||
// Import ordering
|
||||
'import-x/order': [
|
||||
'error',
|
||||
{
|
||||
groups: ['builtin', 'external', 'internal', 'parent', 'sibling', 'index'],
|
||||
'newlines-between': 'never',
|
||||
alphabetize: { order: 'asc', caseInsensitive: true },
|
||||
},
|
||||
],
|
||||
'import-x/no-duplicates': 'error',
|
||||
'import-x/no-unresolved': 'off', // TypeScript handles this
|
||||
|
||||
// General
|
||||
'no-console': ['warn', { allow: ['warn', 'error'] }],
|
||||
},
|
||||
},
|
||||
|
||||
// NestJS-specific rules for the API app
|
||||
{
|
||||
files: ['apps/api/**/*.ts', 'src/modules/**/*.ts'],
|
||||
rules: {
|
||||
// NestJS uses empty classes for modules, allow them
|
||||
'@typescript-eslint/no-extraneous-class': 'off',
|
||||
// NestJS decorators require this pattern
|
||||
'@typescript-eslint/no-unsafe-declaration-merging': 'off',
|
||||
},
|
||||
},
|
||||
|
||||
// React/Next.js overrides for web app
|
||||
{
|
||||
files: ['apps/web/**/*.ts', 'apps/web/**/*.tsx'],
|
||||
languageOptions: {
|
||||
globals: {
|
||||
...globals.browser,
|
||||
React: 'readonly',
|
||||
},
|
||||
},
|
||||
rules: {
|
||||
'no-console': 'error',
|
||||
},
|
||||
},
|
||||
|
||||
// Test files
|
||||
{
|
||||
files: ['**/*.spec.ts', '**/*.test.ts', '**/__tests__/**/*.ts'],
|
||||
rules: {
|
||||
'@typescript-eslint/no-explicit-any': 'off',
|
||||
'no-console': 'off',
|
||||
},
|
||||
},
|
||||
|
||||
// Script files (seeds, migrations, etc.)
|
||||
{
|
||||
files: ['prisma/**/*.ts'],
|
||||
rules: {
|
||||
'no-console': 'off',
|
||||
'@typescript-eslint/no-unused-vars': 'warn',
|
||||
},
|
||||
},
|
||||
);
|
||||
Reference in New Issue
Block a user