Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
gkfyr opened this issue Feb 18, 2025 · 1 comment · May be fixed by #951
Open

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

gkfyr opened this issue Feb 18, 2025 · 1 comment · May be fixed by #951
Labels

Comments

@gkfyr
Copy link

gkfyr commented Feb 18, 2025

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, sort imports by the length of the content inside {} (shorter names first).

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 {PoolId} from "../src/types/PoolId.sol";
import {PoolKey} from "../src/types/PoolKey.sol";
import {Currency} from "../src/types/Currency.sol";
import {BalanceDelta} from "../src/types/BalanceDelta.sol";
import {IHooks} from "../src/interfaces/IHooks.sol";
import {IPoolManager} from "../src/interfaces/IPoolManager.sol";
import {IProtocolFees} from "../src/interfaces/IProtocolFees.sol";
import {Hooks} from "../src/libraries/Hooks.sol";
import {FullMath} from "../src/libraries/FullMath.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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant