Skip to content

Commit

Permalink
Ensuring --check and --list are handled properly for stdin inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiospampinato committed Sep 13, 2024
1 parent 31dca58 commit 037c956
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,13 @@ async function runStdin(options: Options, pluginsDefaultOptions: PluginsOptions,

try {
const formatted = await prettier.format(fileName, fileContent, options.formatOptions, options.contextOptions, pluginsDefaultOptions, pluginsCustomOptions);
stdout.always(trimFinalNewline(formatted));
if (options.check || options.list) {
if (formatted !== fileContent) {
stdout.warn("(stdin)");
}
} else {
stdout.always(trimFinalNewline(formatted));
}
process.exitCode = options.check && formatted !== fileContent ? 1 : 0;
} catch (error) {
stderr.prefixed.error(String(error));
Expand Down

0 comments on commit 037c956

Please sign in to comment.