Skip to content

fix(tail): preserve trailing newlines across unselected inputs - #1290

Open
sergioperezcheco wants to merge 1 commit into
shelljs:mainfrom
sergioperezcheco:fix/tail-unselected-input-newlines
Open

sergioperezcheco wants to merge 1 commit into
shelljs:mainfrom
sergioperezcheco:fix/tail-unselected-input-newlines

Conversation

@sergioperezcheco

Copy link
Copy Markdown
Contributor

When a later input contributes no selected lines, tail() still replaces the trailing-newline state from earlier inputs. For example, tail({'-n': '+2'}, ['data.csv', 'header-only.csv']) can remove the final newline from the selected data, or add one to otherwise unterminated output. Empty files also affect ordinary counts.

Only update the newline state when an input contributes selected lines. This preserves real blank lines and the existing multi-file concatenation behavior, with regressions for array and separate arguments, both newline directions, and empty final files. The header-removal workflow discussed in #983 is existing functionality; this does not reopen or claim to fix that closed issue.

Validated independently on macOS with Node 22: the new regressions fail against the original implementation and pass with the change; npm test, lint, coverage, generated-documentation checks, Node-support checks, and actual packed-package/public API checks pass. Linux/Windows and the other supported Node versions were not run locally.

AI-assisted implementation and automated independent review; no human review is claimed.

Only let files contributing selected lines control the final newline. Cover empty and header-only trailing inputs and preserve selected blank lines.

Assisted-by: OpenAI GPT-6.1
Signed-off-by: sergioperezcheco <checo520@outlook.com>
@codecov

codecov Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.17%. Comparing base (beb2b1f) to head (47aa36b).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1290   +/-   ##
=======================================
  Coverage   97.17%   97.17%           
=======================================
  Files          36       36           
  Lines        1523     1524    +1     
=======================================
+ Hits         1480     1481    +1     
  Misses         43       43           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant