-
Notifications
You must be signed in to change notification settings - Fork 20
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 specified files at the command line #12
Comments
This doesn't work out of the box, mostly because Gradle doesn't have notion of Git and the whole idea behind the tool is to give you tasks that run autoformats for every source sets you have. I have two questions to challenge this:
|
I just want the ability to specify files in the command line. I'll use
I didn't want to use the It automatically registers a Git Hook by using husky and use lint-staged to filter out the files to be committed, as it mentions in the README: Ultimately you only want to lint files that will be committed.
Yes, I've already tried, ktfmt-gradle didn't work. What I want to achieve is to automatically format the committed files, so as I said above, the other three files don't need to be formatted. I'm a Web developer, and since this approach is widely used in the Web space, so I mention this feature request. |
Here is an other example from Facebook's formatting tool prettier |
I see your point. So I'm thinking about an approach that could look like:
You would then call it with:
There are a couple of changes needed to make this possible. |
I understand your intention to customize to achieve flexibility or generality,but I doubt whether to do this, based on the following two reasons:
So maybe a fixed api would be better, but this is just an immature suggestion, I don’t know much about gradle and maven. |
The rationale behind my suggestion is that I expose the
No plan to make this work with Maven, at least from my side |
If just support Gradle, this is a great solution. |
I've done some work on this front but with not much success. Currently Gradle expects that the See: gradle/gradle#15679 |
Yes, It seems that it can only do by include api
|
I'm unsure I follow you. Your script does not compile for me:
|
I got it wrong. Forget it |
#!/bin/sh
# git config core.hooksPath hooks
echo '[git hook] executing gradlew ktfmtFormat:write before commit'
FILES=$(git diff --cached --name-only --diff-filter=ACMR "*.kt" | sed 's| |\\ |g')
[ -z "$FILES" ] && exit 0
# Prettify all selected files
JOIN_FILES=$(echo "$FILES" | sed ':a;N;$!ba;s/\n/:/g')
./gradlew ktfmtPrecommit --include-only="$JOIN_FILES" --daemon
# store the last exit code in a variable
RESULT=$?
# Add back the modified/prettified files to staging
echo "$FILES" | xargs git add
exit $RESULT Share my currently available git hook scripts |
I'm looking into tackling this issue with #16 |
I have updated the git hook script to format only the submitted files. |
So I suppose it's working fine now? :) |
Yes, I've already tested it. Thank you very much for your work. |
💡 Describe the solution you'd like
java -jar /path/to/ktfmt-<VERSION>-jar-with-dependencies.jar [--dropbox-style] [files...]
Ktfmt supports specifying files that need to be formatted. I want this feature when I use the command line, maybe it is:
gradlew ktfmtFormat -Dglob=[files...]
My actual usage scenarios is that I have changed five files, and want to commit two of them. I registered a git hook to format the file to be committed. So I just want to format two files.
You can reference this issue: How to setup spotless for a git pre commit hook that only check changed files
🤚 Do you want to develop this feature yourself?
The text was updated successfully, but these errors were encountered: