# @thalorlabs/eslint-plugin-dev-config

A comprehensive development configuration package for ThalorLabs projects, providing standardized ESLint, Prettier, Jest, and TypeScript configurations.

## Installation

```bash
npm install --save-dev @thalorlabs/eslint-plugin-dev-config
```

## Features

- **ESLint Configurations** - TypeScript and React-specific linting rules
- **Prettier Integration** - Code formatting with ESLint integration
- **Jest Configuration** - Testing setup with TypeScript support
- **TypeScript Configs** - Strict TypeScript configurations for different project types
- **Consistent Standards** - Enforced code quality and style across all ThalorLabs projects
- **Zero Configuration** - Works out of the box with sensible defaults

## Quick Start

### 1. Install the Package

```bash
npm install --save-dev @thalorlabs/eslint-plugin-dev-config
```

### 2. Configure ESLint

Create an `.eslintrc.json` file in your project root:

```json
{
  "extends": [
    "plugin:@thalorlabs/eslint-plugin-dev-config/recommended"
  ]
}
```

**Note**: This follows the proper ESLint plugin naming convention and works correctly with ESLint's module resolution system.

### 3. Configure Jest

Create a `jest.config.js` file:

```javascript
module.exports = require('@thalorlabs/eslint-plugin-dev-config/configs/jest.config.js');
```

Or if you need the setup file as well:

```javascript
module.exports = {
  ...require('@thalorlabs/eslint-plugin-dev-config/jest'),
  setupFilesAfterEnv: ['<rootDir>/jest.setup.js']
};
```

Then create a `jest.setup.js` file:

```javascript
require('@thalorlabs/eslint-plugin-dev-config/configs/jest.setup.js');
```

## Available Configurations

### ESLint Configuration

#### `plugin:@thalorlabs/eslint-plugin-dev-config/recommended`
ESLint configuration for TypeScript projects with:
- TypeScript-specific rules
- Code quality rules
- Security rules
- Performance rules
- Import sorting
- Unused imports detection
- Complexity limits

### Jest Configuration

#### `@thalorlabs/eslint-plugin-dev-config/jest`
Jest configuration with:
- TypeScript support via ts-jest
- Coverage reporting (100% threshold)
- Test environment setup
- Module resolution with path mapping
- Mock utilities

#### `@thalorlabs/eslint-plugin-dev-config/jest-setup`
Jest setup file with:
- Global test utilities
- Mock helpers for MongoDB/Mongoose
- Console mocking
- Test environment configuration

## Usage Examples

### Basic TypeScript Project

```javascript
// .eslintrc.js
module.exports = {
  extends: ['plugin:@thalorlabs/eslint-plugin-dev-config/recommended'],
};

// jest.config.js
module.exports = require('@thalorlabs/eslint-plugin-dev-config/configs/jest.config.js');

// jest.setup.js (optional)
require('@thalorlabs/eslint-plugin-dev-config/configs/jest.setup.js');
```

### Custom Overrides

You can extend and override any configuration:

```javascript
// .eslintrc.js
module.exports = {
  extends: ['plugin:@thalorlabs/eslint-plugin-dev-config/recommended'],
  rules: {
    // Override specific rules
    '@typescript-eslint/no-explicit-any': 'off',
    'no-console': 'off',
  },
  overrides: [
    {
      files: ['**/*.test.ts'],
      rules: {
        // Test-specific overrides
        '@typescript-eslint/no-explicit-any': 'off',
      },
    },
  ],
};
```

## Package Scripts

Add these scripts to your `package.json`:

```json
{
  "scripts": {
    "lint": "eslint . --ext .ts,.js,.tsx,.jsx",
    "lint:fix": "eslint . --ext .ts,.js,.tsx,.jsx --fix",
    "format": "prettier --write .",
    "format:check": "prettier --check .",
    "test": "jest",
    "test:watch": "jest --watch",
    "test:coverage": "jest --coverage",
    "type-check": "tsc --noEmit"
  }
}
```

## Configuration Details

### ESLint Rules

The ESLint configurations include:

- **TypeScript Rules**: Strict type checking and best practices
- **Code Quality**: Complexity limits, function length limits
- **Import/Export**: Consistent import/export patterns
- **Prettier Integration**: Automatic formatting on save
- **Accessibility**: JSX accessibility rules (React config)

### Prettier Settings

- **Semi-colons**: Always required
- **Quotes**: Single quotes for strings
- **Trailing Commas**: ES5 compatible
- **Tab Width**: 2 spaces
- **Print Width**: 80 characters

### Jest Settings

- **TypeScript Support**: Via ts-jest transformer
- **Coverage**: HTML and text coverage reports
- **Test Environment**: Node.js environment
- **Module Resolution**: Supports path mapping

### TypeScript Settings

- **Strict Mode**: All strict checks enabled
- **Target**: ES2020
- **Module**: CommonJS (configurable)
- **Declaration Files**: Generated for library projects
- **Source Maps**: Enabled for debugging

## IDE Integration

### VS Code

Install these extensions for the best experience:

```json
{
  "recommendations": [
    "esbenp.prettier-vscode",
    "dbaeumer.vscode-eslint",
    "ms-vscode.vscode-typescript-next"
  ]
}
```

Add to your VS Code settings:

```json
{
  "editor.formatOnSave": true,
  "editor.codeActionsOnSave": {
    "source.fixAll.eslint": true
  },
  "eslint.validate": ["javascript", "typescript", "javascriptreact", "typescriptreact"]
}
```

## Migration Guide

### From Existing Configurations

1. **Backup** your current configuration files
2. **Install** the dev-config package
3. **Replace** your config files with the new ones
4. **Test** your build and lint processes
5. **Adjust** any project-specific overrides

### From Old Import Syntax

The package has been renamed to follow ESLint plugin naming conventions:

```json
// OLD - Don't use this anymore
{
  "extends": [
    "./node_modules/@thalorlabs/dev-config/configs/.eslintrc.json"
  ]
}

// NEW - Use this instead
{
  "extends": [
    "plugin:@thalorlabs/eslint-plugin-dev-config/recommended"
  ]
}
```

**Important**: The package is now properly structured as an ESLint plugin following the official naming conventions from the [ESLint plugin documentation](https://eslint.org/docs/latest/extend/plugins).

### Common Migrations

#### ESLint Migration
```javascript
// Old .eslintrc.js
module.exports = {
  extends: ['@typescript-eslint/recommended'],
  // ... many custom rules
};

// New .eslintrc.js
module.exports = {
  extends: ['@thalorlabs/dev-config/eslint'],
  // Only project-specific overrides
};
```

#### Prettier Migration
```javascript
// Old .prettierrc.js
module.exports = {
  semi: true,
  singleQuote: true,
  // ... many custom settings
};

// New .prettierrc.js
module.exports = require('@thalorlabs/dev-config/prettier');
```

## Contributing

### Adding New Rules

1. **Test** the rule in multiple projects
2. **Document** the reasoning behind the rule
3. **Update** this README with examples
4. **Version** the change appropriately

### Configuration Updates

1. **Backward Compatibility**: Maintain compatibility when possible
2. **Breaking Changes**: Use semantic versioning
3. **Documentation**: Update all relevant documentation
4. **Testing**: Test across different project types

## Troubleshooting

### Common Issues

#### ESLint Errors
```bash
# Clear ESLint cache
npx eslint --cache-location .eslintcache --clear-cache
```

#### TypeScript Errors
```bash
# Clear TypeScript cache
npx tsc --build --clean
```

#### Prettier Conflicts
```bash
# Check for conflicting rules
npx eslint-config-prettier .eslintrc.js
```

### Getting Help

- **Issues**: [GitHub Issues](https://github.com/ThalorLabs/dev-config/issues)
- **Documentation**: Check this README and inline comments
- **Support**: Contact the ThalorLabs development team

## License

ISC

## Changelog

### v1.2.0
- **FIXED**: Proper ESLint plugin naming convention - package renamed to `@thalorlabs/eslint-plugin-dev-config`
- **WORKING**: ESLint configuration now works with `plugin:@thalorlabs/eslint-plugin-dev-config/recommended`
- **CLEANED**: Removed duplicate wrapper files and organized directory structure
- **UPDATED**: Documentation reflects correct package name and usage patterns

### v1.1.7
- **BREAKING**: Simplified import syntax - use `@thalorlabs/dev-config/eslint` instead of verbose paths
- Updated documentation with migration guide
- Improved package exports for cleaner imports

### v1.0.0
- Initial release with ESLint, Prettier, Jest, and TypeScript configurations
- Support for both TypeScript and React projects
- Comprehensive documentation and examples