Skip to content

Commit

Permalink
fix: remove uses of outdated --stdin switch from prettier examples (f…
Browse files Browse the repository at this point in the history
…ixes #57) (#60)
  • Loading branch information
hallettj committed Dec 14, 2021
1 parent 41454c1 commit 8e98ce7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ For detailed information run:
The command expects a shell command to run a formatter, and one or more file
patterns to identify which files should be formatted. For example:

$ git-format-staged --formatter 'prettier --stdin --stdin-filepath "{}"' 'src/*.js'
$ git-format-staged --formatter 'prettier --stdin-filepath "{}"' 'src/*.js'

That will format all files under `src/` and its subdirectories using
`prettier`. The file pattern is tested against staged files using Python's
Expand All @@ -75,7 +75,7 @@ content to `stdout`.

Files can be excluded by prefixing a pattern with `!`. For example:

$ git-format-staged --formatter 'prettier --stdin' '*.js' '!flow-typed/*'
$ git-format-staged --formatter 'prettier --stdin-filepath "{}"' '*.js' '!flow-typed/*'

Patterns are evaluated from left-to-right: if a file matches multiple patterns
the right-most pattern determines whether the file is included or excluded.
Expand All @@ -89,7 +89,7 @@ with the path of the file that is being formatted. This is useful if your
formatter needs to know the file extension to determine how to format or to
lint each file. For example:

$ git-format-staged -f 'prettier --stdin --stdin-filepath "{}"' '*.js' '*.css'
$ git-format-staged -f 'prettier --stdin-filepath "{}"' '*.js' '*.css'

Do not attempt to read or write to `{}` in your formatter command! The
placeholder exists only for referencing the file name and path.
Expand Down
6 changes: 3 additions & 3 deletions git-format-staged
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# ignoring unstaged changes.
#
# Usage: git-format-staged [OPTION]... [FILE]...
# Example: git-format-staged --formatter 'prettier --stdin' '*.js'
# Example: git-format-staged --formatter 'prettier --stdin-filepath "{}"' '*.js'
#
# Tested with Python 3.6 and Python 2.7.
#
Expand Down Expand Up @@ -231,12 +231,12 @@ class CustomArgumentParser(argparse.ArgumentParser):
if __name__ == '__main__':
parser = CustomArgumentParser(
description='Transform staged files using a formatting command that accepts content via stdin and produces a result via stdout.',
epilog='Example: %(prog)s --formatter "prettier --stdin" "src/*.js" "test/*.js"'
epilog='Example: %(prog)s --formatter "prettier --stdin-filepath \'{}\'" "src/*.js" "test/*.js"'
)
parser.add_argument(
'--formatter', '-f',
required=True,
help='Shell command to format files, will run once per file. Occurrences of the placeholder `{}` will be replaced with a path to the file being formatted. (Example: "prettier --stdin --stdin-filepath \'{}\'")'
help='Shell command to format files, will run once per file. Occurrences of the placeholder `{}` will be replaced with a path to the file being formatted. (Example: "prettier --stdin-filepath \'{}\'")'
)
parser.add_argument(
'--no-update-working-tree',
Expand Down
4 changes: 2 additions & 2 deletions test/git-format-staged_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,10 @@ test('fails if formatter command is not quoted', async t => {
const r = repo(t)
const { exitCode, stderr } = await formatStagedCaptureError(
r,
'-f prettier --stdin *.js'
'-f prettier --stdin-filepath "{}" *.js'
)
t.true(exitCode > 0)
t.regex(stderr, /unrecognized arguments: --stdin/)
t.regex(stderr, /unrecognized arguments: --stdin-filepath/)
t.regex(stderr, /Do you need to quote your formatter command\?/)
})

Expand Down

0 comments on commit 8e98ce7

Please sign in to comment.