Skip to content

Refactor test file imports by removing duplicates and standardizing order #950

@gkfyr

Description

@gkfyr

Component

General design optimization (improving efficiency, cleanliness, or developer experience)

Describe the suggested feature and problem it solves.

Suggested Feature: Reordering and Deduplicating Imports

Problem

Currently, the import statements in the /test contain duplicates and are not consistently ordered. This can lead to:

  • Reduced readability and maintainability of the code.
  • Potential merge conflicts when multiple contributors modify the same files.
  • Difficulty in quickly locating dependencies within the import section.

Proposed Solution

  • Remove duplicate imports to eliminate redundancy.
  • Reorder imports in a structured manner, following a logical grouping such as:
    • External dependencies
    • Utilities
    • Types
    • Interfaces
    • Libraries
    • Contracts
    • Test files
  • Ensure a consistent ordering convention to improve code clarity and prevent future inconsistencies.

Benefits

  • Enhances code readability and maintainability.
  • Reduces the likelihood of unnecessary merge conflicts.
  • Improves the overall structure of import statements, making them easier to manage.

I will open a pull request after creating this issue.

Describe the desired implementation.

Desired Implementation

1. Remove duplicate imports

  • Scan all Solidity files for redundant import statements.
  • Remove any duplicates while ensuring all necessary dependencies remain intact.

2. Standardize import order

  • Follow a structured grouping approach to maintain consistency:

    1. External dependencies (e.g., forge-std, solmate)
    2. Utilities (e.g., ./utils/)
    3. Types (e.g., ../src/types/)
    4. Interfaces (e.g., ../src/interfaces/)
    5. Libraries (e.g., ../src/libraries/)
    6. Contracts (e.g., ../src/PoolManager.sol)
    7. Test files (e.g., ../src/test/)
  • Within each category, imports need to be sorted alphabetically.

Example of the new structure

Before:

import {Test} from "forge-std/Test.sol";
import {Vm} from "forge-std/Vm.sol";

import {PoolId} from "../src/types/PoolId.sol";
import {Hooks} from "../src/libraries/Hooks.sol";
import {IPoolManager} from "../src/interfaces/IPoolManager.sol";
import {IProtocolFees} from "../src/interfaces/IProtocolFees.sol";
import {IHooks} from "../src/interfaces/IHooks.sol";
import {PoolKey} from "../src/types/PoolKey.sol";
import {PoolManager} from "../src/PoolManager.sol";
import {PoolSwapTest} from "../src/test/PoolSwapTest.sol";
import {Deployers} from "./utils/Deployers.sol";
import {Currency} from "../src/types/Currency.sol";
import {MockERC20} from "solmate/src/test/utils/mocks/MockERC20.sol";
import {FullMath} from "../src/libraries/FullMath.sol";
import {BalanceDelta} from "../src/types/BalanceDelta.sol";
import {StateLibrary} from "../src/libraries/StateLibrary.sol";

After (reordered and deduplicated):

import {Test} from "forge-std/Test.sol";
import {Vm} from "forge-std/Vm.sol";
import {MockERC20} from "solmate/src/test/utils/mocks/MockERC20.sol";
import {Deployers} from "./utils/Deployers.sol";
import {BalanceDelta} from "../src/types/BalanceDelta.sol";
import {Currency} from "../src/types/Currency.sol";
import {PoolId} from "../src/types/PoolId.sol";
import {PoolKey} from "../src/types/PoolKey.sol";
import {IHooks} from "../src/interfaces/IHooks.sol";
import {IPoolManager} from "../src/interfaces/IPoolManager.sol";
import {IProtocolFees} from "../src/interfaces/IProtocolFees.sol";
import {FullMath} from "../src/libraries/FullMath.sol";
import {Hooks} from "../src/libraries/Hooks.sol";
import {StateLibrary} from "../src/libraries/StateLibrary.sol";
import {PoolManager} from "../src/PoolManager.sol";
import {PoolSwapTest} from "../src/test/PoolSwapTest.sol";

Describe alternatives.

No response

Additional context.

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions