--- description: Code quality thresholds and linting standards for consistent and maintainable code globs: **/*.{ts,tsx,js,jsx,go,css,scss} --- filters: - type: file_extension pattern: "\\.(ts|tsx|js|jsx|go|css|scss)$" actions: - type: suggest message: | # Code Quality Metrics ## Code Complexity 1. Cyclomatic Complexity: - Maximum function/method complexity: 15 - Maximum file complexity: 40 - Strive for functions with complexity < 10 2. Function/Method Size: - Maximum lines per function: 50 - Target average: 15-25 lines - Never exceed 100 lines 3. File Size: - Maximum lines per file: 500 - Target average: 150-300 lines - Split files that grow beyond these limits 4. Nesting Depth: - Maximum nesting depth: 4 levels - Target: 1-3 levels - Refactor deeply nested code blocks ## Code Documentation 1. TypeScript/JavaScript: - Use JSDoc for public API functions/methods - Document complex algorithms - Include @param and @returns tags - Document thrown exceptions with @throws 2. Go: - Document all exported functions, types, and variables - Follow GoDoc conventions - Provide examples for non-obvious functionality ## Linting Standards 1. TypeScript/JavaScript: - Zero ESLint errors - Zero TypeScript errors - Max warnings: 5 per file - Prettier for consistent formatting 2. Go: - Zero golint errors - All go vet checks must pass - gofmt for consistent formatting - Zero golangci-lint errors 3. CSS/SCSS: - Zero stylelint errors - BEM naming convention - Use CSS variables for theming ## Test Coverage 1. Minimum Coverage Requirements: - Overall project: > 70% - Critical paths: > 90% - Business logic: > 85% - UI components: > 60% 2. Test Quality: - Each test case should test one thing - Arrange-Act-Assert pattern - Mock external dependencies - No flaky tests ## Code Review Checklist 1. Readability: - Descriptive variable/function names - Consistent naming conventions - Comments for complex logic 2. Maintainability: - DRY (Don't Repeat Yourself) - SOLID principles - Single responsibility per function 3. Performance: - Avoid N+1 queries - Optimize loops - Avoid unnecessary re-renders ## Automated Checks 1. Run pre-commit checks: ```bash ./scripts/pre-commit.sh ``` 2. Monitor quality metrics: ```bash ./scripts/code-quality.sh ``` 3. Address all issues before merging metadata: priority: high version: 1.0 examples: - input: | // Bad: Complex and nested code function processData(data) { let result = []; for (let i = 0; i < data.length; i++) { if (data[i].active) { for (let j = 0; j < data[i].items.length; j++) { if (data[i].items[j].value > 10) { if (data[i].items[j].type === 'special') { result.push({ id: data[i].id, item: data[i].items[j] }); } } } } } return result; } output: | // Good: Refactored with lower complexity and better readability /** * Extracts special items with values greater than 10 from active data entries * @param {Array} data - Array of data objects to process * @returns {Array} Filtered and processed items */ function processData(data) { return data .filter(entry => entry.active) .flatMap(entry => entry.items .filter(item => item.value > 10 && item.type === 'special') .map(item => ({ id: entry.id, item })) ); } - input: | // Bad: Undocumented function with poor naming function fn(a, b) { return a.filter(i => i > b).map(i => i * 2); } output: | /** * Filters values greater than the threshold and doubles them * @param {number[]} values - Array of numbers to process * @param {number} threshold - Minimum value to include in results * @returns {number[]} Filtered and doubled values */ function filterAndDoubleValues(values, threshold) { return values.filter(value => value > threshold).map(value => value * 2); }