Skip to content

Quality check: step down rule violations #70

@devill

Description

@devill

Problem

Files that don't follow the step down rule are harder to read and maintain. The step down rule states that high-level functions should appear first, followed by lower-level private functions they call.

This is a follow-up to #46 which implements the sort-methods command. This issue focuses specifically on the quality check component.

Solution

Add a quality check that warns when files violate the step down rule by having functions that call other functions defined later in the file.

Acceptance Criteria

  • Quality check detects step down rule violations using topological analysis
  • Check identifies functions that call other functions defined later in the same file
  • Violations include location information for the calling function
  • Quality check suggests running refakts sort-methods <file> to fix violations
  • Check handles recursive function calls appropriately (entry points should be first)
  • Integration with existing quality system (baseline support, etc.)

Implementation Notes

The check should:

  1. Analyze call relationships within each file to build a dependency graph
  2. Detect violations where functions call other functions defined later
  3. Handle edge cases like recursive calls and mutual recursion
  4. Provide actionable feedback with specific function locations and suggested fix

Example Violation

// ❌ BAD: violates step down rule
function helper() { 
  return "processed"; 
}

function main() {
  return helper(); // calls function defined above
}
// ✅ GOOD: follows step down rule
function main() {
  return helper(); // calls function defined below
}

function helper() {
  return "processed"; 
}

Related to

Metadata

Metadata

Assignees

No one assigned

    Labels

    Quality ChecksTasks that add to post-commit quality check system

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions