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

CLI Support for multiple targets #220

Closed
GravlLift opened this issue May 18, 2021 · 1 comment
Closed

CLI Support for multiple targets #220

GravlLift opened this issue May 18, 2021 · 1 comment
Labels
type:enhancement New feature or request
Milestone

Comments

@GravlLift
Copy link

GravlLift commented May 18, 2021

Prettier currently supports any number of targets in the same CLI command. For example this command will format file1.ts and file2.ts but ignore anything else that might happen to be in that directory:

prettier --write file1.ts file2.ts

You can add any number of target files or directories this way. This is particularly useful when adding prettier into a precommit hook, so that you can format only files that have been modified in this commit. Take this precommit for example, which only formats staged files:

#!/bin/sh
LC_ALL=C
# Select files to format
FILES=$(git diff --cached --name-only --diff-filter=ACM | sed 's| |\\ |g')
[ -z "$FILES" ] && exit 0

# Prettier format selected files 
# Appends filenames to the end of `npx prettier --write`
echo "$FILES" | cat | xargs npx prettier --write

# Add back the modified files to stage
echo "$FILES" | xargs git add

exit 0

Is there any chance of that being added as a feature for csharpier? It'd be great to add this tool to my precommit hooks.

@belav
Copy link
Owner

belav commented May 19, 2021

I think this is a great idea and shouldn't take too much effort to add.
First pass would probably just support [file/directory] but I think it'll make sense long term to support [file/directory/glob] just like prettier does.

@belav belav added the type:enhancement New feature or request label May 19, 2021
@belav belav added this to the 0.9.4 milestone May 19, 2021
@belav belav mentioned this issue May 19, 2021
8 tasks
@belav belav closed this as completed in 4d26d9b May 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants