Closed greg-1-anderson closed 4 years ago
Other tools do include a newline after machine-readable output, e.g. composer show -n --format=json
and git status --porcelain
, so we'll leave this as-is.
It's common for clients to expect to have strip off the newline if they don't want it.
Overview
This pull request:
Summary
Do not print a newline after input
Description
It is inconvenient for scripts if formatters always add an eol at the end of all output, as this extra character might sometimes be significant. Omitting this character relieves the caller from the need to trim the output.
Note that some formatters (typically the table formatters) still print an implicit newline. We take care not to print two newlines, though.
All of the existing tests pass, but the existing tests tend to trim the output before comparing, in order to be agnostic about whether a final newline appears or not. We should add additional tests to confirm that the eol is missing when it should be missing, and is present when it is expected to be.
Note that the caller may strongly stipulate whether of not the eol should always, never or sometimes be printed. If the answer is "sometimes", then it is printed when output is going to the console, and it is not printed when output is being redirected. We could restore backwards compatibility here by initializiing this flag to
true
by default. If we did this, then clients that want the new behavior (e.g. drus) would have to clear this value in an appropriate hook.We could also just bump the major version number of this library and let the b/c break remain.