Implementing Code Review Processes in JavaScript Teams
Establish effective code review practices to catch bugs early and maintain high code standards within teams.
0 likes
6 views
Rule Content
{ "title": "Implementing Code Review Processes in JavaScript Teams", "description": "Establish effective code review practices to catch bugs early and maintain high code standards within teams.", "category": "JavaScript Cursor Rules", "rules": [ { "name": "Enforce Consistent Code Formatting", "description": "Ensure all JavaScript code adheres to a consistent style guide to improve readability and maintainability.", "implementation": { "tools": ["ESLint", "Prettier"], "configuration": { "extends": ["eslint:recommended", "plugin:prettier/recommended"], "rules": { "indent": ["error", 2], "quotes": ["error", "single"], "semi": ["error", "always"] } } } }, { "name": "Modularize Code", "description": "Break down code into smaller, reusable modules with clear responsibilities to enhance maintainability.", "implementation": { "guidelines": [ "Use ES6 modules with import/export statements.", "Ensure each module has a single responsibility." ], "example": { "file1.js": "export function add(a, b) { return a + b; }", "file2.js": "import { add } from './file1.js'; console.log(add(2, 3));" } } }, { "name": "Implement Robust Error Handling", "description": "Use try-catch blocks and proper error messages to handle exceptions gracefully.", "implementation": { "guidelines": [ "Wrap asynchronous operations in try-catch blocks.", "Provide meaningful error messages and log errors appropriately." ], "example": { "code": "async function fetchData(url) { try { const response = await fetch(url); if (!response.ok) throw new Error('Network response was not ok'); const data = await response.json(); return data; } catch (error) { console.error('Fetch error:', error); } }" } } }, { "name": "Optimize Performance", "description": "Identify and optimize performance bottlenecks to ensure efficient code execution.", "implementation": { "guidelines": [ "Minimize unnecessary loops and function calls.", "Use efficient data structures and algorithms." ], "example": { "code": "const numbers = [1, 2, 3, 4, 5]; const squares = numbers.map(num => num * num);" } } }, { "name": "Ensure Security Best Practices", "description": "Implement security measures to protect against common vulnerabilities.", "implementation": { "guidelines": [ "Sanitize user inputs to prevent XSS and SQL injection attacks.", "Validate and sanitize data before processing or storing it." ], "example": { "code": "import DOMPurify from 'dompurify'; const userInput = '<script>alert(\"XSS!\");</script>'; const sanitizedInput = DOMPurify.sanitize(userInput);" } } }, { "name": "Write Clear Comments and Documentation", "description": "Provide clear and concise comments to explain complex code sections and document functions.", "implementation": { "guidelines": [ "Use JSDoc-style comments for functions.", "Explain the purpose and usage of complex code blocks." ], "example": { "code": "/** * Calculates the total price with tax. * @param {number} price - Price before tax. * @param {number} taxRate - Tax rate as a percentage. * @returns {number} Total price after adding tax. */ function getTotal(price, taxRate) { return price + (price * taxRate / 100); }" } } }, { "name": "Implement Comprehensive Testing", "description": "Ensure code reliability through unit and integration tests.", "implementation": { "tools": ["Jest", "Mocha"], "guidelines": [ "Write tests for all functions and modules.", "Use test-driven development (TDD) practices." ], "example": { "code": "test('adds 1 + 2 to equal 3', () => { expect(add(1, 2)).toBe(3); });" } } }, { "name": "Utilize Version Control Effectively", "description": "Use version control systems to manage code changes and facilitate collaboration.", "implementation": { "tools": ["Git"], "guidelines": [ "Commit changes with clear and descriptive messages.", "Use branching strategies like Git Flow for feature development." ], "example": { "command": "git commit -m 'Add function to calculate total price with tax'" } } } ] }