better account for incompatible code block indents

This commit is contained in:
jhauga 2025-11-03 20:59:27 -05:00
parent 73c626d041
commit fb96172b55
2 changed files with 165 additions and 152 deletions

View File

@ -8,9 +8,11 @@ description: Enforces Object Calisthenics principles for business domain code to
> Examples may be added later if needed. > Examples may be added later if needed.
## Objective ## Objective
This rule enforces the principles of Object Calisthenics to ensure clean, maintainable, and robust code in the backend, **primarily for business domain code**. This rule enforces the principles of Object Calisthenics to ensure clean, maintainable, and robust code in the backend, **primarily for business domain code**.
## Scope and Application ## Scope and Application
- **Primary focus**: Business domain classes (aggregates, entities, value objects, domain services) - **Primary focus**: Business domain classes (aggregates, entities, value objects, domain services)
- **Secondary focus**: Application layer services and use case handlers - **Secondary focus**: Application layer services and use case handlers
- **Exemptions**: - **Exemptions**:
@ -22,7 +24,6 @@ This rule enforces the principles of Object Calisthenics to ensure clean, mainta
## Key Principles ## Key Principles
1. **One Level of Indentation per Method**: 1. **One Level of Indentation per Method**:
- Ensure methods are simple and do not exceed one level of indentation. - Ensure methods are simple and do not exceed one level of indentation.
@ -57,6 +58,7 @@ This rule enforces the principles of Object Calisthenics to ensure clean, mainta
} }
} }
``` ```
2. **Don't Use the ELSE Keyword**: 2. **Don't Use the ELSE Keyword**:
- Avoid using the `else` keyword to reduce complexity and improve readability. - Avoid using the `else` keyword to reduce complexity and improve readability.
@ -81,6 +83,7 @@ This rule enforces the principles of Object Calisthenics to ensure clean, mainta
``` ```
Sample Fail fast principle: Sample Fail fast principle:
```csharp ```csharp
public void ProcessOrder(Order order) { public void ProcessOrder(Order order) {
if (order == null) throw new ArgumentNullException(nameof(order)); if (order == null) throw new ArgumentNullException(nameof(order));
@ -213,7 +216,6 @@ First Class Collections: a class that contains an array as an attribute should n
} }
``` ```
8. **No Classes with More Than Two Instance Variables**: 8. **No Classes with More Than Two Instance Variables**:
- Encourage classes to have a single responsibility by limiting the number of instance variables. - Encourage classes to have a single responsibility by limiting the number of instance variables.
- Limit the number of instance variables to two to maintain simplicity. - Limit the number of instance variables to two to maintain simplicity.
@ -275,6 +277,7 @@ First Class Collections: a class that contains an array as an attribute should n
``` ```
## Implementation Guidelines ## Implementation Guidelines
- **Domain Classes**: - **Domain Classes**:
- Use private constructors and static factory methods for creating instances. - Use private constructors and static factory methods for creating instances.
- Avoid exposing setters for properties. - Avoid exposing setters for properties.
@ -297,7 +300,7 @@ First Class Collections: a class that contains an array as an attribute should n
- Be pragmatic about infrastructure and DTO code. - Be pragmatic about infrastructure and DTO code.
## References ## References
- [Object Calisthenics - Original 9 Rules by Jeff Bay](https://www.cs.helsinki.fi/u/luontola/tdd-2009/ext/ObjectCalisthenics.pdf) - [Object Calisthenics - Original 9 Rules by Jeff Bay](https://www.cs.helsinki.fi/u/luontola/tdd-2009/ext/ObjectCalisthenics.pdf)
- [ThoughtWorks - Object Calisthenics](https://www.thoughtworks.com/insights/blog/object-calisthenics) - [ThoughtWorks - Object Calisthenics](https://www.thoughtworks.com/insights/blog/object-calisthenics)
- [Clean Code: A Handbook of Agile Software Craftsmanship - Robert C. Martin](https://www.oreilly.com/library/view/clean-code-a/9780136083238/) - [Clean Code: A Handbook of Agile Software Craftsmanship - Robert C. Martin](https://www.oreilly.com/library/view/clean-code-a/9780136083238/)

View File

@ -104,7 +104,17 @@ function processFile(filePath) {
continue; continue;
} }
// Otherwise, treat as nested inner fence start; indent til matching inner fence (inclusive) // Potential nested fence - check if it has language info (opening fence)
// If rest is empty or just whitespace, it's likely a sloppy closing fence, not a nested opening
const hasLangInfo = restTrim.length > 0;
if (!hasLangInfo) {
// Sloppy closing fence without nested content - don't indent, just skip
i++;
continue;
}
// This is an actual nested opening fence; indent til matching inner fence (inclusive)
changed = true; changed = true;
const innerTicksLen = ticksLen; const innerTicksLen = ticksLen;
lines[i] = ' ' + lines[i]; lines[i] = ' ' + lines[i];