Creating Consistent indentation Guidelines for JavaScript Code
Establish a clear set of indentation rules to improve code readability and maintainability across your JavaScript projects.
0 likes
39 views
Rule Content
{ "title": "Creating Consistent Indentation Guidelines for JavaScript Code", "description": "Establish a clear set of indentation rules to improve code readability and maintainability across your JavaScript projects.", "category": "JavaScript Cursor Rules", "rules": [ { "name": "Use Spaces for Indentation", "description": "Indentation must be accomplished using spaces, not tabs, to ensure consistency across different editors and environments.", "level": "error", "pattern": "\\t", "replacement": " " }, { "name": "Set Indentation Level to 2 Spaces", "description": "Each level of indentation should be exactly 2 spaces to enhance code readability and maintainability.", "level": "error", "pattern": "(?<=^|\\n)( {2})*[^\\n]+", "replacement": " $0" }, { "name": "Consistent Indentation in Control Structures", "description": "Ensure that all control structures (if, else, for, while, switch) have their code blocks indented consistently with 2 spaces.", "level": "error", "pattern": "(?<=\\b(if|else|for|while|switch)\\b.*\\{\\n)( {2})*[^\\n]+", "replacement": " $0" }, { "name": "Indentation for Function Definitions", "description": "Function bodies should be indented with 2 spaces to clearly delineate the function's scope.", "level": "error", "pattern": "(?<=\\bfunction\\b.*\\{\\n)( {2})*[^\\n]+", "replacement": " $0" }, { "name": "Indentation for Object and Array Literals", "description": "Properties and elements within object and array literals should be indented with 2 spaces for clarity.", "level": "error", "pattern": "(?<=\\{\\n)( {2})*[^\\n]+", "replacement": " $0" }, { "name": "Line Continuation Indentation", "description": "When a statement spans multiple lines, the continuation lines should be indented an additional 2 spaces beyond the current indentation level.", "level": "error", "pattern": "(?<=\\n)( {2})*[^\\n]+", "replacement": " $0" } ] }