Skip to content

'jfmt' tool for the fast formating #50

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

Closed
wants to merge 4 commits into from
Closed

Conversation

pvlbzn
Copy link

@pvlbzn pvlbzn commented May 24, 2016

I wrote a tool, Python script, which is able to format .java files in directory and subdirectories or just a single .java file. I use it like $ jfmt /path/to/project/dir and I find it very convenient way to format my code as a whole.

Script was tested on Linux and Mac.

I hope this tool can be useful for others. Also, I not quite sure about the name. I was inspired by fmt from the Go lang.

@kevinb9n
Copy link
Contributor

Thanks for thinking about how to make this project better!

Question: If google-java-format could take directories as arguments and
process them recursively, would a separate wrapper be necessary?

On Tue, May 24, 2016 at 5:37 AM, Pavel Bazin [email protected]
wrote:

I wrote a tool, Python script, which is able to format .java files in
directory and subdirectories or just a single .java file. I use it like $
jfmt /path/to/project/dir and I find it very convenient way to format my
code as a whole.

Script was tested on Linux and Mac.

I hope this tool can be useful for others. Also, I not quite sure about

the name. I was inspired by fmt from the Go lang.

You can view, comment on, or merge this pull request online at:

#50
Commit Summary

  • Python script 'jfmt' for formatting automatization.
  • Fixed comment in jfmt.
  • Added 'Purpose' description to 'jfmt'.

File Changes

Patch Links:


You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub
#50

Kevin Bourrillion | Java Librarian | Google, Inc. | [email protected]

@sherter
Copy link
Contributor

sherter commented May 24, 2016

Question: If google-java-format could take directories as arguments and
process them recursively, would a separate wrapper be necessary?

I had the idea before, but as you suggest to put more functionality into the executable I think it should be considered now: What do you think about separating library code and executable into two artifacts? This would prevent problems like #42 in the future and tools like dagger could depend on the library only. CLI parsing libraries (jcommander) used in the executable are transitively resolved right now, even if you only want to use the Formatter class directly.

Both library and tool could evolve independently and adding the functionality you suggested would not require a new release of the library.

@pvlbzn
Copy link
Author

pvlbzn commented May 24, 2016

If you ask me, I'll write this kind of a tool in both proposed cases.

If google-java-format will be able to traverse over a tree I'll call its "native method" from the script instead of applying it, google-java-format, to the each file. Because it is a more convenient way to use it as a separate tool.

Consider following use case:

$ git clone some/java/project.git
$ jfmt

Now you are able to read formatted code like it was formatted from the beginning.

Or

$ jfmt
$ git commit -am "comment"

To write code in comfortable style and format it afterwards to common style. I can't say that last example can be considered as a good one, but it shows the point.

Cheers.

@cushon
Copy link
Collaborator

cushon commented Jun 3, 2016

Thanks for the patch! I'm not sure it's worth adding a separate wrapper for this, though. Does find . -type f -name "*.java" | xargs google-java-format -i do what you need?

@sherter good idea, I filed #54 to separate the CLI into its own artifact.

@pvlbzn
Copy link
Author

pvlbzn commented Jun 3, 2016

Thanks for answer @cushon !

This script is aimed on an integration into users shell. The key point is to type 4 characters and format whole project at once, or type 5 characters and drag-n-drop particular .java file into the shell to format it. IDE environments usually have a built-in terminal feature, so it can used out of one programming env.

However, perhaps it will be too much to have two wrappers. I proposed this tool because it serves well to me, with an unix-like idea "one tool for a one job". May be it is a good idea to add this functionality into the existing script? Otherwise lets close this request.

Cheers!

@cushon cushon closed this Oct 10, 2017
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 this pull request may close these issues.

5 participants