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

Implement 'roc format <dir_or_files>' command #2066

Merged
merged 2 commits into from
Nov 23, 2021

Conversation

joshuawarner32
Copy link
Collaborator

I noticed this was conspicuously missing.

Note when trying to format a roc few files in the repo, I immediately ran into missing parts of the formatter, which I'll work on next.

Having this command is both (1) independently useful, and (2) a good stepping stone to #2010, where we'll want to parse, simplify/reduce the ast, then write it out again (invoking the same code this does).

// files,
// roc_builtins::std::standard_stdlib(),
// Path::new("./generated-docs"),
// )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎨 Seems like this comment is no longer needed, yeah?


std::fs::write(&file, buf).unwrap();
}
Err(error) => panic!("Unexpected parse failure when parsing this for module header formatting:\n\n{:?}\n\nParse error was:\n\n{:?}\n\n", src, error)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of panic! can we use one of these? #2046

cli/src/main.rs Outdated
match maybe_values {
None => {
let mut os_string_values: Vec<OsString> = Vec::new();
read_all_roc_files(&OsStr::new("./").to_os_string(), &mut os_string_values)?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think https://doc.rust-lang.org/std/env/fn.current_dir.html is probably more portable than "./"

cli/src/main.rs Outdated
@@ -101,7 +101,7 @@ fn main() -> io::Result<()> {
match maybe_values {
None => {
let mut os_string_values: Vec<OsString> = Vec::new();
read_all_roc_files(&OsStr::new("./").to_os_string(), &mut os_string_values)?;
read_all_roc_files(&std::env::current_dir().unwrap().as_os_str().to_os_string(), &mut os_string_values)?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can

Suggested change
read_all_roc_files(&std::env::current_dir().unwrap().as_os_str().to_os_string(), &mut os_string_values)?;
read_all_roc_files(&std::env::current_dir()?.as_os_str().to_os_string(), &mut os_string_values)?;

be done here instead of an unwrap?

Copy link
Contributor

@rtfeldman rtfeldman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sweet, thanks @joshuawarner32! 🎉

@rtfeldman rtfeldman merged commit 7c39b08 into trunk Nov 23, 2021
@rtfeldman rtfeldman deleted the joshuawarner32/roc-format-cmd branch November 23, 2021 18:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants