[go: up one dir, main page]

Component files should appear before their test file in code review

Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.

What

The current view for code review sorts files alphabetically. This means that component files have a chance to appear after their test file, which disrupts the natural reading flow during reviews.

image

Why this matters

When reviewing changes, developers typically want to:

  1. Understand the implementation changes first
  2. Then verify the test coverage

image

Having test files appear before their related components breaks this natural review flow and can make code reviews less efficient.

Proposal

Implement a sorting strategy that ensures implementation files appear before their associated test files.

Assumptions

  • Spec files typically have .spec.js, .spec.ts, .spec.jsx, .spec.tsx, .unit.js, .unit.ts, .unit.jsx, .unit.tsx extensions (or similar test patterns)
  • Implementation files commonly use extensions: .vue, .js, .jsx, .ts, .tsx, .svelte, .astro

Suggested approach

When sorting files, group related files together with this priority:

  1. Implementation file (e.g., component.vue, component.tsx, utils.js)
  2. Test files (e.g., component.spec.js, component.unit.tsx)

Within each group, maintain alphabetical ordering.

Example

Before (current):

  • component.spec.tsx
  • component.tsx
  • utils.js
  • utils.unit.js

After (proposed):

  • component.tsx
  • component.spec.tsx
  • utils.js
  • utils.unit.js

Open questions

  • Should this behavior be configurable or always-on?
  • How should we handle edge cases where multiple test files exist for one implementation file?
Edited by 🤖 GitLab Bot 🤖