-
Notifications
You must be signed in to change notification settings - Fork 34
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
Support sequence of formatters #77
Comments
What happens is that some developers want to:
In order to support that, we need to find a way to apply these tools in sequence. Maybe a config format change would be: [formatter.ormolu]
pre_command = "import-fixer"
command = "ormolu"
after = "haskell-header"
includes = ["*.hs"] |
I think the usage of [formatter.beancount]
command = "sh"
options = [
"-c",
"for f in $@; do bean-format $f; done",
]
includes = ["*.beancount"] Maybe a slightly friendlier [formatter.beancount]
script = """
for f in $@; do bean-format $f; done
"""
includes = ["*.beancount"] But I probably miss some aspects... |
That's a good idea. If there is tool A and B, we want to encourage calling |
Do you mean to implement a |
I meant that the example for sequencial calls should avoid using a for loop. Overall, I would rather fix upstream formatters than add more config options :) |
Might this issue be even solvable via documentation, clarifying the use of |
Of course, Documentation over existing best practices is always a good first step. |
Hi, I just installed this (0.3.0), and I tried the following [formatter.python]
command = "sh"
options = [
"-c",
"""
isort "$@" && black "$@"
""",
]
includes = ["*.py"] but was wondering why my python file wasn't formatted. Turns out that the first file is passed as $ sh -c 'echo AA $@ BB' xx yy zz
AA yy zz BB I fixed this by adding a dummy argument: [formatter.python]
command = "sh"
options = [
"-c",
"""
isort "$@" && black "$@"
""",
"dummy",
]
includes = ["*.py"] Does this not happen for you? Edit: |
Put a dummy "--" as the first argument, otherwise the first file is always ignored. See #77 (comment)
Put a dummy "--" as the first argument, otherwise the first file is always ignored. See #77 (comment)
Good catch. f440332 includes your fix, and replaces |
Cool. It's easy to miss, so something friendlier would be nice, as suggested above. Perhaps sh = "..." can desugar to command = "/bin/sh"
options = ["-euc", "...", "--"] |
Put a dummy "--" as the first argument, otherwise the first file is always ignored. See numtide#77 (comment)
I think it would be easier for the devs to just have a priority option. All hooks with same priority should run in parallel. Then, the same with next priority. Default priority could be 0. Example: [formatter.isort]
command = "isort"
includes = ["*.py"]
[formatter.black]
command = "black"
priority = 1 # Runs after all formatters with priority 0 (default)
includes = ["*.py"] |
In some cases, developers might want to run a sequence of formatters for the same file type. For example, re-order the import headers with one tool, and then use the main code formatted to fix the output of the first tool.
The text was updated successfully, but these errors were encountered: