# Import organization is consistent

- **Pattern:** `ab-000667` (`code-maintainability.code-organization.import-organization`)
- **Severity:** low
- **Lifecycle:** active
- **Last modified:** 2026-04-18
- **Canonical URL:** https://auditbuffet.com/patterns/ab-000667
- **License:** CC-BY-4.0 — attribute to AuditBuffet Pattern Catalog (https://auditbuffet.com/patterns/ab-000667)

## Why it matters

Inconsistent import ordering is a low-stakes signal with a real cost: it generates unnecessary merge conflicts when two developers touch the same file, and it slows down code review because readers must mentally parse which dependencies are third-party versus internal. ISO 25010 maintainability.analysability degrades when every file has a different ordering convention. Projects assembled across multiple AI sessions are especially prone to this because each session may apply a different implicit convention.

## Severity rationale

Low because inconsistent imports cause friction and merge conflicts but do not break functionality or introduce security risk.

## Remediation

Let tooling enforce ordering automatically so no human has to think about it. Add the `import/order` rule to your ESLint config:

```json
"import/order": ["warn", {
  "groups": ["builtin", "external", "internal", "parent", "sibling", "index"]
}]
```

Alternatively, configure `@trivago/prettier-plugin-sort-imports`. Run once across the codebase to reformat all existing files, then every future file auto-conforms on save.

## Detection

- **ID:** `import-organization`
- **Severity:** `low`
- **What to look for:** Examine import blocks at the top of 5-10 representative source files. Check whether imports are organized in a consistent order. Common conventions are: external packages first, then internal absolute imports, then relative imports; or alphabetically within groups; or following the configured `import/order` ESLint rule. Look for: mixed ordering with no discernible pattern, third-party and relative imports interleaved, type imports scattered throughout rather than grouped.
- **Pass criteria:** Count all source files with at least 3 imports and examine at least 5 representative files. Import ordering follows a consistent pattern across at least 80% of examined files. Either an ESLint `import/order` rule is configured that enforces the order, or 80%+ of examined files follow the same informal convention. Report the ratio: "X of Y examined files follow consistent import ordering."
- **Fail criteria:** Imports are in inconsistent or random order in the majority of files examined, and no linting rule enforces order.
- **Cross-reference:** For directory structure conventions that affect import paths, see the file-folder-structure check in this audit.
- **Skip (N/A) when:** The project has fewer than 5 source files with multiple imports. Signal: project has fewer than 5 source files.
- **Detail on fail:** `"Import ordering is inconsistent across components — third-party, internal, and relative imports are mixed without a discernible pattern. No import/order ESLint rule configured."`
- **Remediation:** Consistent import ordering reduces merge conflicts and makes it easy to scan which dependencies a file uses. The easiest fix is to let tooling handle it automatically:

  ```bash
  # Add to your ESLint config:
  # "import/order": ["warn", { "groups": ["builtin", "external", "internal", "parent", "sibling", "index"] }]
  ```

  Or configure Prettier with `@trivago/prettier-plugin-sort-imports`. Once configured, run it once across the codebase and all future files will conform automatically.

---

## External references

- iso-25010 maintainability.analysability

Taxons: code-quality

HTML version: https://auditbuffet.com/patterns/ab-000667
