-
-
Notifications
You must be signed in to change notification settings - Fork 358
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
Start a related project to parse and format Makefiles #730
Comments
There are quite a lot of languages which are relatively thin wrappers over shell, like Makefile and Dockerfile. I agree it feels like a nice fit for parsing and even formatting. We do something kinda similar for Bats right now; it's an extension of the bash language for testing, and adds Makefile (and by extension Dockerfile etc) are a bit less clear to me, because they are less directly related to developing shell code, and add significantly more syntax of their own. Makefile adds the All that said, I think it would be a very good idea to start a project building on top of this module's syntax package to parse and format Makefiles (or Dockerfiles etc). For example, see jessfraz/dockfmt#2. I'm more than happy to help out where I can, such as by improving the API if that is needed to integrate better at a low level. I personally think that "Makefile parser+formatter" idea belongs in a different repository, simply because I do not have the bandwidth to write and maintain it myself, and do not want to become a bottleneck. I hope that makes sense. We could link these closely related projects in the README, though - see https://github.com/mvdan/sh#related-projects :) |
Thanks for the encouraging response! That sounds like a good plan. I probably won't have time to write a
Line splitting is handled differently in recipes (i.e. embedded shell scripts) and non-recipe parts. It looks like the most obvious strategy for formatting all that is to read in "logical lines" and tokenize each line. Then write out the tokens (space-separated in most case), starting a new line when a token would go over the width limit. Some projects use makefiles where the recipes are written in Windows batch file ( |
Bonus: here's the POSIX |
Sounds good, thanks for the info. I've repurposed the issue to see if anyone would be interested in starting this; we can leave it open for a while and see. |
It has been three years; it's time to close this as there is no interest. I'm still happy to assist here and there if someone wants to take this on, but it doesn't make sense to track it here. |
There now exist dozens of autoformatters covering almost every popular language but I can't find one for makefiles.
Makefiles most declare build targets, with a small shell script written beneath each target. Hence it looks like the problem of makefile formatting boils down to a relatively simple make formatter which calls a complex shell formatter as a subroutine to do most of the actual work.
Given that shfmt already has excellent coverage of shell, would it interest you to try adding a makefile wrapper around it?
The text was updated successfully, but these errors were encountered: