Skip to content

bug: forge flatten should ignore intermediary files for imports #7239

Open
@kopy-kat

Description

@kopy-kat

Component

Forge

Have you ensured that all of these are up to date?

  • Foundry
  • Foundryup

What version of Foundry are you on?

0.2.0

What command(s) is the bug in?

forge flatten

Operating System

macOS (Apple Silicon)

Describe the bug

In more complex codebases, you might want to import objects from files other than the file in which an object is originally defined, in order to make the codebase easier to read. A simplified example:

File A:

import {Test} from "./Intermediary";

File Intermediary:

import {Test} from "./Test";
import {Test2} from "./Test2";

File Test:

contract Test {}

However, when running forge flatten (and when using --verify), all files are treated equally, even when they are only used as "intermediary files". This means that the flattened version of file A will also include Test2, which is never imported into A.

Proposed solution

The flattener should determine whether a file is used only as an intermediary and ignore it if it is, jumping to the file from which the used import is exported from.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions