+
Skip to content
This repository was archived by the owner on Aug 31, 2023. It is now read-only.

Conversation

leops
Copy link
Contributor

@leops leops commented Oct 28, 2022

Summary

Fixes #3515

This PR changes how line breaks are handled in diffs, and specifically how individual lines get marked as "modified" when a line break is removed or inserted. It fixes an issue with the rendering of diffs from the formatter, but also changes when diffs are allowed to be rendered in short mode as the removal of an entire line is now shown in full mode (with the surrounding lines of context).

Test Plan

I've added an additional test case for this and updated the ellipsis case since it was actually being rendered incorrectly. I've also improved how markup assertion mismatches are displayed in the tests to ensure these kinds of issue are easier to notice in the future, and update a few snapshots related to the short mode changes.

@leops leops requested a review from xunilrj as a code owner October 28, 2022 09:14
@leops leops requested a review from a team October 28, 2022 09:14
@leops leops temporarily deployed to netlify-playground October 28, 2022 09:14 Inactive
@netlify
Copy link

netlify bot commented Oct 28, 2022

Deploy Preview for rometools ready!

Name Link
🔨 Latest commit 77fc22a
🔍 Latest deploy log https://app.netlify.com/sites/rometools/deploys/635bab33e108840009a48d18
😎 Deploy Preview https://deploy-preview-3523--rometools.netlify.app/docs/lint/rules/nounnecessarycontinue
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@github-actions
Copy link

github-actions bot commented Oct 28, 2022

@leops leops temporarily deployed to netlify-playground October 28, 2022 10:13 Inactive

// Get all the lines
let mut parts = text.split('\n').enumerate();
let mut parts = text.split('\n');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: lines? or is it guaranteed for code frames to never contain windows line breaks?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's possible for code frames or diffs to contain windows line breaks but they're handled separately in print_invisibles. The reason this code is using split instead of lines is because the later internally makes use of split_terminator instead and ignores the last line break, meaning "A\n".lines() would return ["A"] while "A\n".split('\n') returns ["A", ""]

│ -----------
7 7 │ function test() {
8 8 │ let a = 3;
9 │ - ··debugger;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the new rendering. The additional context helps to understand which line was deleted.

@leops leops added the A-Diagnostic Area: errors and diagnostics label Oct 28, 2022
@leops leops merged commit 71e716b into main Oct 28, 2022
@leops leops deleted the fix/diff-line-break branch October 28, 2022 14:04
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

A-Diagnostic Area: errors and diagnostics

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐛 Formatter diff not showing removed lines

2 participants

点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载