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

Sort before flatten #6539

Closed
sakulstra opened this issue Dec 7, 2023 · 0 comments · Fixed by #6936
Closed

Sort before flatten #6539

sakulstra opened this issue Dec 7, 2023 · 0 comments · Fixed by #6936
Assignees
Labels
T-feature Type: feature

Comments

@sakulstra
Copy link
Contributor

sakulstra commented Dec 7, 2023

Component

Forge

Describe the feature you would like

forge flatten should sort interfaces/contracts/lib by name before flattening.

I've had a brief look at how this could be done, but it's non obvious to me:

/// Flattens all file imports into a single string
    pub fn flatten(&self, target: &Path) -> Result<String> {
        tracing::trace!("flattening file");
        let mut input_files = self.input_files();

        // we need to ensure that the target is part of the input set, otherwise it's not
        // part of the graph if it's not imported by any input file
        let flatten_target = target.to_path_buf();
        if !input_files.contains(&flatten_target) {
            input_files.push(flatten_target);
        }

        let sources = Source::read_all_files(input_files)?;
        let graph = Graph::resolve_sources(self, sources)?;
        self.flatten_node(target, &graph, &mut Default::default(), false, false, false).map(|x| {
            format!("{}\n", utils::RE_THREE_OR_MORE_NEWLINES.replace_all(&x, "\n\n").trim())
        })
    }

I don't know rust - potentially it could be as easy as sorting nodes before transforming to a string

Additional context

I'm a heavy user of forge flatten as it's quite nice to compare an upstream deployment of a contract with a local version.
Diffing folders usually is a lot harder then diffing single files.

That said, diffing flattened files can become problematic, when - for whatever reason - the import order on one of the two sides changes. The diff will grow huge and unreadable. If the contracts and interfaces would be sorted alphabetically on the flattened files it would be far easier to understand differences.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-feature Type: feature
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants