# @coze-arch/eslint-config A comprehensive ESLint configuration package for the Coze architecture ecosystem, providing standardized linting rules for JavaScript, TypeScript, React, and Node.js projects. ## Features - ๐Ÿ”ง **Multi-environment support**: Separate configurations for web, node, and base environments - ๐ŸŽฏ **TypeScript-first**: Full TypeScript support with advanced rules - โš›๏ธ **React optimized**: Built-in React hooks and XSS protection rules - ๐Ÿ”’ **Security focused**: Integrated security plugins and best practices - ๐ŸŽจ **Prettier integration**: Seamless code formatting with Prettier - ๐Ÿ“ฆ **Workspace-aware**: Import resolution for monorepo environments - ๐Ÿšซ **Dependency control**: Built-in rules to prevent disallowed dependencies - ๐Ÿงช **Test-friendly**: Special configurations for test files ## Get Started ### Installation ```bash # Install the package pnpm add @coze-arch/eslint-config --save-dev # Update workspace dependencies rush update ``` ### Basic Usage Create an `eslint.config.js` file in your project root: ```javascript const { defineConfig } = require('@coze-arch/eslint-config'); module.exports = defineConfig({ packageRoot: __dirname, preset: 'web', // or 'node' or 'base' }); ``` ## API Reference ### `defineConfig(config)` The main function to create ESLint configurations. #### Parameters - `config` (EnhanceESLintConfig): Configuration object #### EnhanceESLintConfig Interface ```typescript interface EnhanceESLintConfig extends ESLintConfig { /** * Project root directory */ packageRoot: string; /** * Configuration preset mode */ preset: 'web' | 'node' | 'base'; /** * Additional configuration overrides */ overrides?: ESLintConfig[]; /** * Custom ignore patterns */ ignores?: string[]; /** * Custom rules */ rules?: Linter.RulesRecord; /** * ESLint settings */ settings?: any; } ``` ### Configuration Presets #### Web Preset (`preset: 'web'`) Optimized for React web applications: ```javascript module.exports = defineConfig({ packageRoot: __dirname, preset: 'web', }); ``` **Includes:** - React and React Hooks rules - XSS protection with `eslint-plugin-risxss` - Browser globals - Restricted imports for architecture compliance #### Node Preset (`preset: 'node'`) Optimized for Node.js applications: ```javascript module.exports = defineConfig({ packageRoot: __dirname, preset: 'node', }); ``` **Includes:** - Node.js globals and environment - Security plugin for Node.js - Server-side specific rules #### Base Preset (`preset: 'base'`) Minimal configuration for libraries: ```javascript module.exports = defineConfig({ packageRoot: __dirname, preset: 'base', }); ``` **Includes:** - Core JavaScript and TypeScript rules - Import resolution - Common code quality rules ### Custom Configuration #### Adding Custom Rules ```javascript module.exports = defineConfig({ packageRoot: __dirname, preset: 'web', rules: { 'no-console': 'warn', '@typescript-eslint/no-unused-vars': 'error', }, }); ``` #### Adding Overrides ```javascript module.exports = defineConfig({ packageRoot: __dirname, preset: 'web', overrides: [ { files: ['**/*.test.ts', '**/*.spec.ts'], rules: { 'max-lines': 'off', }, }, ], }); ``` #### Custom Ignores ```javascript module.exports = defineConfig({ packageRoot: __dirname, preset: 'web', ignores: [ 'custom-build/**', 'temp/**', ], }); ``` ### CLI Scripts The package provides convenient CLI scripts: #### ESLint Script ```bash # Using the built-in eslint script npx eslint ./src # Using the reslint alias npx reslint ./src ``` #### Prettier Script ```bash # Format code with Prettier npx prettier --write ./src ``` ## Development ### Project Structure ``` config/eslint-config/ โ”œโ”€โ”€ src/ โ”‚ โ”œโ”€โ”€ index.js # Main entry point โ”‚ โ””โ”€โ”€ define-config.ts # Configuration function โ”œโ”€โ”€ rules/ # Rule configurations โ”‚ โ”œโ”€โ”€ common-standard.js # Common rules โ”‚ โ”œโ”€โ”€ import.js # Import rules โ”‚ โ”œโ”€โ”€ js-standard.js # JavaScript rules โ”‚ โ”œโ”€โ”€ ts-standard.js # TypeScript rules โ”‚ โ””โ”€โ”€ test-standard.js # Test file rules โ”œโ”€โ”€ scripts/ โ”‚ โ”œโ”€โ”€ reslint.sh # ESLint wrapper script โ”‚ โ””โ”€โ”€ rprettier.sh # Prettier wrapper script โ”œโ”€โ”€ eslint.config.base.js # Base configuration โ”œโ”€โ”€ eslint.config.web.js # Web configuration โ”œโ”€โ”€ eslint.config.node.js # Node.js configuration โ””โ”€โ”€ package.json ``` ### Building ```bash # Build the package rush build --to @coze-arch/eslint-config # Run linting rush lint --to @coze-arch/eslint-config ``` ### Testing ```bash # Run tests rush test --to @coze-arch/eslint-config ``` ## Dependencies ### Main Dependencies - **@typescript-eslint/eslint-plugin**: TypeScript-specific linting rules - **@typescript-eslint/parser**: TypeScript parser for ESLint - **eslint-plugin-react**: React-specific linting rules - **eslint-plugin-react-hooks**: Rules for React Hooks - **eslint-plugin-prettier**: Prettier integration - **eslint-plugin-import**: Import/export syntax validation - **eslint-plugin-security**: Security-focused linting rules - **eslint-plugin-risxss**: XSS prevention for React ### Internal Dependencies - **@coze-arch/eslint-plugin**: Custom rules for Coze architecture - **@coze-arch/ts-config**: TypeScript configuration ### Build Tools - **sucrase**: Fast TypeScript transpilation - **prettier**: Code formatting - **eslint**: Core linting engine ## License Internal package for Coze architecture ecosystem. --- For more information about ESLint configuration, visit the [ESLint documentation](https://eslint.org/docs/user-guide/configuring/).