prettier-plugin-svelte icon indicating copy to clipboard operation
prettier-plugin-svelte copied to clipboard

Success exit code is given even if there is an error

Open zakkor opened this issue 2 years ago • 0 comments

echo '<script>function x() { 2 + 2 }</script>' | prettier --plugin-search-dir <some-dir-with-prettier-plugin-svelte-installed> --parser svelte; echo $?

We get the formatted output and a 0 (success) exit code, as expected:

<script>
  function x() {
    2 + 2;
  }
</script>
0

Now we introduce a syntax error in the code, and try again:

echo '<script>function x() { 2 + 2###}</script>' | prettier --plugin-search-dir <some-dir-with-prettier-plugin-svelte-installed> --parser svelte; echo $?

Now we get the error output, but still a 0 (success) exit code:

SyntaxError: Unexpected token (1:22)
> 1 | function x() { 2 + 2 ###}
    |                      ^
    at ....
  loc: { start: { line: 1, column: 22 } },
  codeFrame: '> 1 | function x() { 2 + 2 ###}\n    |                      ^'
}
<script>
function x() { 2 + 2 ###}
</script>
0 # <------------------- Here

Contrast this to what happens in the typescript parser:

echo 'function x() { 2 + 2 ###}' | prettier --parser typescript; echo $?

[error] stdin: SyntaxError: Invalid character. (1:22)
[error] > 1 | function x() { 2 + 2 ###}
[error]     |                      ^
[error]   2 |
2 # <---------- error exit code as expected

zakkor avatar Jul 26 '22 13:07 zakkor