8000 [Logs] Highlight inline differences in CLI by Slamdunk · Pull Request #1974 · infection/infection · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[Logs] Highlight inline differences in CLI #1974

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 3, 2024

Conversation

Slamdunk
Copy link
Contributor
@Slamdunk Slamdunk commented Jun 3, 2024

Fix #1810

Why not to use jfcherng/php-diff or diff-so-fancy?

Infection's use case is much more limited: diffs are one-line only, and within the same line only one difference can happen.
Yes the algorithm in this PR needs some time to get understood, but less than tracking and maintaining another dependency.

@@ -1,5 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="5.11.0@c9b192ab8400fdaf04b2b13d110575adc879aa90">
<file src="src/Differ/DiffColorizer.php">
<InvalidArrayOffset>
<code>$lines[$prevIndex]</code>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know why PSalm doesn't get the Assert::greaterThan($index, 0);

8000
@@ -285,7 +285,7 @@ public static function create(): self
$container->getPrinter(),
$container->getMutantCodeFactory(),
),
Differ::class => static fn (): Differ => new Differ(new BaseDiffer(new UnifiedDiffOutputBuilder())),
Differ::class => static fn (): Differ => new Differ(new BaseDiffer(new UnifiedDiffOutputBuilder(''))),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I hope you are ok removing the "--- Original\n+++ New\n" header, which only adds visual clutter to the output

@Slamdunk Slamdunk force-pushed the inline_diff_highlight branch from b7e0208 to 7ba20b6 Compare June 3, 2024 12:20
Copy link
Member
@maks-rafalko maks-rafalko left a comment

Choose a reason for hiding this comment

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

It works just awesome. Thank you very much @Slamdunk

A couple of real-world examples that became very easy to understand:

image

image

or this one

image

@maks-rafalko maks-rafalko merged commit b7e29dd into infection:0.29 Jun 3, 2024
55 checks passed
@Slamdunk Slamdunk deleted the inline_diff_highlight branch June 4, 2024 04:11
github-merge-queue bot referenced this pull request in Lendable/json-serializer Jun 4, 2024
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [infection/infection](https://togithub.com/infection/infection) |
`^0.29.1` -> `^0.29.2` |
[![age](https://developer.mend.io/api/mc/badges/age/packagist/infection%2finfection/0.29.2?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/packagist/infection%2finfection/0.29.2?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/packagist/infection%2finfection/0.29.1/0.29.2?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/packagist/infection%2finfection/0.29.1/0.29.2?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>infection/infection (infection/infection)</summary>

###
[`v0.29.2`](https://togithub.com/infection/infection/releases/tag/0.29.2):
Highlight inline differences in CLI

[Compare
Source](https://togithub.com/infection/infection/compare/0.29.1...0.29.2)

**Added:**

- \[Logs] Highlight inline differences in CLI by
[@&#8203;Slamdunk](https://togithub.com/Slamdunk) in
[https://github.com/infection/infection/pull/1974](https://togithub.com/infection/infection/pull/1974)

**Full Changelog**:
infection/infection@0.29.1...0.29.2

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/Lendable/json-serializer).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4zNzcuOCIsInVwZGF0ZWRJblZlciI6IjM3LjM3Ny44IiwidGFyZ2V0QnJhbmNoIjoibWFzdGVyIiwibGFiZWxzIjpbXX0=-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
@theofidry
Copy link
Member

I'll miss that everyday in PHPUnit now 🤣

maks-rafalko added a commit that referenced this pull request Oct 6, 2024
…ultiline diffs.

We introduced inline highlighter for diffs in #1974 (thanks to @Slamdunk). However, there was an incorrect assumption that we only have one-line diffs. This is not true.

The case which is currently fails is the following:

```diff
@@ @@
      */
     protected function name()
     {
-        return strtolower(get_class($this));
+        strtolower(get_class($this));
+        return null;
     }
 }
```

I check how `diff-so-fancy` works with multiline diffs, and it turned out that it just skips inline diffs, using simple algorithm, see images below.

So, for the cases when we have multiline diffs, I just added fallback - our old algorithm of colorizing diffs.
maks-rafalko added a commit that referenced this pull request Oct 6, 2024
…ultiline diffs.

We introduced inline highlighter for diffs in #1974 (thanks to @Slamdunk). However, there was an incorrect assumption that we only have one-line diffs. This is not true.

The case which is currently fails is the following:

```diff
@@ @@
      */
     protected function name()
     {
-        return strtolower(get_class($this));
+        strtolower(get_class($this));
+        return null;
     }
 }
```

I check how `diff-so-fancy` works with multiline diffs, and it turned out that it just skips inline diffs, using simple algorithm, see images below.

So, for the cases when we have multiline diffs, I just added fallback - our old algorithm of colorizing diffs.
maks-rafalko added a commit that referenced this pull request Oct 6, 2024
…ultiline diffs.

We introduced inline highlighter for diffs in #1974 (thanks to @Slamdunk). However, there was an incorrect assumption that we only have one-line diffs. This is not true.

The case which is currently fails is the following:

```diff
@@ @@
      */
     protected function name()
     {
-        return strtolower(get_class($this));
+        strtolower(get_class($this));
+        return null;
     }
 }
```

I check how `diff-so-fancy` works with multiline diffs, and it turned out that it just skips inline diffs, using simple algorithm, see images below.

So, for the cases when we have multiline diffs, I just added fallback - our old algorithm of colorizing diffs.
maks-rafalko added a commit that referenced this pull request Oct 6, 2024
…ultiline diffs.

We introduced inline highlighter for diffs in #1974 (thanks to @Slamdunk). However, there was an incorrect assumption that we only have one-line diffs. This is not true.

The case which is currently fails is the following:

```diff
@@ @@
      */
     protected function name()
     {
-        return strtolower(get_class($this));
+        strtolower(get_class($this));
+        return null;
     }
 }
```

I check how `diff-so-fancy` works with multiline diffs, and it turned out that it just skips inline diffs, using simple algorithm, see images below.

So, for the cases when we have multiline diffs, I just added fallback - our old algorithm of colorizing diffs.
maks-rafalko added a commit that referenced this pull request Oct 6, 2024
…ultiline diffs. (#2000)

We introduced inline highlighter for diffs in #1974 (thanks to @Slamdunk). However, there was an incorrect assumption that we only have one-line diffs. This is not true.

The case which is currently fails is the following:

```diff
@@ @@
      */
     protected function name()
     {
-        return strtolower(get_class($this));
+        strtolower(get_class($this));
+        return null;
     }
 }
```

I check how `diff-so-fancy` works with multiline diffs, and it turned out that it just skips inline diffs, using simple algorithm, see images below.

So, for the cases when we have multiline diffs, I just added fallback - our old algorithm of colorizing diffs.
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.

3 participants
0