import js from '@eslint/js';
import tseslint from '@typescript-eslint/eslint-plugin';
import tsparser from '@typescript-eslint/parser';
import react from 'eslint-plugin-react';
import reactHooks from 'eslint-plugin-react-hooks';
export default [
// Base JavaScript recommended rules
js.configs.recommended,
// TypeScript and React files configuration
{
files: ['src/**/*.{ts,tsx}', 'tests/**/*.{ts,tsx}'],
languageOptions: {
parser: tsparser,
parserOptions: {
ecmaVersion: 2020,
sourceType: 'module',
project: './tsconfig.json',
ecmaFeatures: {
jsx: true,
},
},
globals: {
console: 'readonly',
process: 'readonly',
Buffer: 'readonly',
__dirname: 'readonly',
__filename: 'readonly',
global: 'readonly',
setImmediate: 'readonly',
clearImmediate: 'readonly',
setTimeout: 'readonly',
clearTimeout: 'readonly',
setInterval: 'readonly',
clearInterval: 'readonly',
},
},
plugins: {
'@typescript-eslint': tseslint,
'react': react,
'react-hooks': reactHooks,
},
rules: {
// TypeScript rules
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
'@typescript-eslint/no-explicit-any': 'warn',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-non-null-assertion': 'warn',
'@typescript-eslint/prefer-optional-chain': 'error',
'@typescript-eslint/prefer-nullish-coalescing': 'error',
'@typescript-eslint/no-unnecessary-type-assertion': 'error',
'@typescript-eslint/no-inferrable-types': 'error',
// React rules
'react/react-in-jsx-scope': 'off', // Not needed with React 17+
'react/prop-types': 'off', // Using TypeScript for prop validation
'react/jsx-uses-react': 'error',
'react/jsx-uses-vars': 'error',
'react/no-unescaped-entities': 'warn',
// React Hooks rules
'react-hooks/rules-of-hooks': 'error',
'react-hooks/exhaustive-deps': 'warn',
// General JavaScript/Node.js rules
'no-console': 'off', // Allow console in Node.js applications
'no-unused-vars': 'off', // Using TypeScript version instead
'prefer-const': 'error',
'no-var': 'error',
'object-shorthand': 'error',
'prefer-template': 'error',
'eqeqeq': ['error', 'always'],
'curly': ['error', 'all'],
'brace-style': ['error', '1tbs'],
'comma-dangle': ['error', 'always-multiline'],
'quotes': ['error', 'single', { avoidEscape: true }],
'semi': ['error', 'always'],
},
settings: {
react: {
version: 'detect',
},
},
},
// Test files specific configuration
{
files: ['tests/**/*.{ts,tsx}'],
rules: {
'@typescript-eslint/no-explicit-any': 'off', // Allow any in tests
'no-console': 'off', // Allow console in tests
},
},
// Ignore patterns
{
ignores: [
'dist/**',
'node_modules/**',
'src/interfaces/tui-ink-old/**',
'src/interfaces/tui/**',
'*.js', // Ignore root JS files like this config
'coverage/**',
'.cache/**',
'test-results.xml',
],
},
];