Skip to content

Commit

Permalink
feat(cli): add the --stdin-filepath option
Browse files Browse the repository at this point in the history
This option is really usefull when using prettier-eslint-cli inside text
editor plugins, to let prettier-eslint discover the correct eslintrc
configuration for the given file.

Related:
* prettier#95
* sbdchd/neoformat#112
* prettier/prettier-emacs#10 (comment)
  • Loading branch information
BenoitZugmeyer committed Sep 27, 2017
1 parent d28c5ef commit 84911de
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ Options:
--write Edit the file in-place (beware!)
[boolean] [default: false]
--stdin Read input via stdin [boolean] [default: false]
--stdin-filepath Path to the file to pretend that stdin comes from.
--eslint-ignore Only format matching files even if they are not
ignored by .eslintignore. (can use --no-eslint-ignore
to disable this) [boolean] [default: true]
Expand Down
3 changes: 2 additions & 1 deletion src/format-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ function formatFilesFromArgv({
logLevel = logger.getLevel(),
listDifferent,
stdin,
stdinFilepath,
write,
eslintPath,
prettierPath,
Expand Down Expand Up @@ -63,7 +64,7 @@ function formatFilesFromArgv({

const cliOptions = {write, listDifferent}
if (stdin) {
return formatStdin(prettierESLintOptions)
return formatStdin({filePath: stdinFilepath, ...prettierESLintOptions})
} else {
return formatFilesFromGlobs(
fileGlobs,
Expand Down
4 changes: 4 additions & 0 deletions src/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ const parser = yargs
describe: 'Read input via stdin',
type: 'boolean',
},
'stdin-filepath': {
describe: 'Path to the file to pretend that stdin comes from.',
coerce: coercePath,
},
'eslint-ignore': {
default: true,
type: 'boolean',
Expand Down

0 comments on commit 84911de

Please sign in to comment.