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

Commit a93376d

Browse files
DavidSniderfacebook-github-bot
authored andcommitted
Format a chunk of the codebase
Summary: https://fb.workplace.com/groups/668453703203248/posts/7137820676266486 the_time_has_come Running the files in this commit through the equivilant of `hackfmt -i <file>` allow-large-files allow_many_files bypass-lint drop-conflicts Reviewed By: ravibhoraskar, shashkambh Differential Revision: D32712845 fbshipit-source-id: 6e195773762601f3ca63b9808f35de5f00fac880
1 parent 89fea22 commit a93376d

File tree

6 files changed

+36
-48
lines changed

6 files changed

+36
-48
lines changed

src/ColoredUnifiedDiff.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,10 @@ final public static function create(
9898
if ($line[0] === '-') {
9999
$next = C\first($lines);
100100
if (
101-
$next !== null
102-
&& $next !== ''
103-
&& $next[0] === '+'
101+
$next !== null && $next !== '' && $next[0] === '+'
104102
// Levenshtein function throws for strings with length > 255
105103
// Don't need intra word diffs for long lines
106-
&& Str\length($line) < 256
107-
&& Str\length($next) < 256
104+
&& Str\length($line) < 256 && Str\length($next) < 256
108105
// -2 to deal with the prefix
109106
/* HH_FIXME[4107] using directly because this is open source */
110107
/* HH_FIXME[2049] using directly because this is open source */
@@ -115,8 +112,18 @@ final public static function create(
115112
$next = Str\slice($next, 1);
116113
$lines = Vec\drop($lines, 1);
117114

118-
$words_line = vec(\preg_split('/([^a-zA-Z0-9_]+)/', $line, -1, \PREG_SPLIT_DELIM_CAPTURE));
119-
$words_next = vec(\preg_split('/([^a-zA-Z0-9_]+)/', $next, -1, \PREG_SPLIT_DELIM_CAPTURE));
115+
$words_line = vec(\preg_split(
116+
'/([^a-zA-Z0-9_]+)/',
117+
$line,
118+
-1,
119+
\PREG_SPLIT_DELIM_CAPTURE,
120+
));
121+
$words_next = vec(\preg_split(
122+
'/([^a-zA-Z0-9_]+)/',
123+
$next,
124+
-1,
125+
\PREG_SPLIT_DELIM_CAPTURE,
126+
));
120127
$intraline = (new StringDiff($words_line, $words_next))->getDiff();
121128
$out[] = $intraline
122129
|> Vec\filter($$, $op ==> !$op->isInsertOp())

src/Diff.php

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -76,27 +76,18 @@ final public function getDiff(): vec<DiffOp<this::TContent>> {
7676
list($x, $y) = $from;
7777
$prev = $to;
7878
if ($to === tuple($x + 1, $y + 1)) {
79-
$diff[] = new DiffKeepOp(
80-
$a[$x]['pos'],
81-
$b[$y]['pos'],
82-
$a[$x]['content'],
83-
);
79+
$diff[] =
80+
new DiffKeepOp($a[$x]['pos'], $b[$y]['pos'], $a[$x]['content']);
8481
continue;
8582
}
8683

8784
if ($to === tuple($x + 1, $y)) {
88-
$diff[] = new DiffDeleteOp(
89-
$a[$x]['pos'],
90-
$a[$x]['content'],
91-
);
85+
$diff[] = new DiffDeleteOp($a[$x]['pos'], $a[$x]['content']);
9286
continue;
9387
}
9488

9589
if ($to === tuple($x, $y + 1)) {
96-
$diff[] = new DiffInsertOp(
97-
$b[$y]['pos'],
98-
$b[$y]['content'],
99-
);
90+
$diff[] = new DiffInsertOp($b[$y]['pos'], $b[$y]['content']);
10091
continue;
10192
}
10293

@@ -206,8 +197,8 @@ private function getMoves(): vec<this::TMove> {
206197
// Decide which option we're taking for this diagonal
207198
if (
208199
// if ===, can't be -1 as $diagonal >= -$cost
209-
$diagonal === -$cost
210-
|| (
200+
$diagonal === -$cost ||
201+
(
211202
// if ===, must be -1 as $diagonal <= $cost
212203
$diagonal !== $cost
213204
// Okay, we can choose.
@@ -218,7 +209,8 @@ private function getMoves(): vec<this::TMove> {
218209
// is generally expected, and considered more readable than:
219210
// +foof
220211
// -foo
221-
&& $best_points[$diagonal - 1] < $best_points[$diagonal + 1]
212+
&&
213+
$best_points[$diagonal - 1] < $best_points[$diagonal + 1]
222214
)
223215
) {
224216
// keep x, increase $y (add a insertion)
@@ -278,10 +270,10 @@ private function backtrackPath(
278270
* diagonal moves. Which?
279271
*/
280272
if (
281-
$diagonal === -$cost
282-
|| (
283-
$diagonal !== $cost
284-
&& $best_points[$diagonal - 1] < $best_points[$diagonal + 1]
273+
$diagonal === -$cost ||
274+
(
275+
$diagonal !== $cost &&
276+
$best_points[$diagonal - 1] < $best_points[$diagonal + 1]
285277
)
286278
) {
287279
$diagonal = $diagonal + 1;

src/DiffDeleteOp.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@
1212

1313
/** An operation representing deleting an element from the original sequence */
1414
final class DiffDeleteOp<TContent> extends DiffOp<TContent> {
15-
public function __construct(
16-
private int $oldPos,
17-
private TContent $content,
18-
) {
15+
public function __construct(private int $oldPos, private TContent $content) {
1916
}
2017

2118
public function getOldPos(): int {

src/DiffInsertOp.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@
1212

1313
/** An operation representing an insertion into the sequence */
1414
final class DiffInsertOp<TContent> extends DiffOp<TContent> {
15-
public function __construct(
16-
private int $newPos,
17-
private TContent $content,
18-
) {
15+
public function __construct(private int $newPos, private TContent $content) {
1916
}
2017

2118
public function getNewPos(): int {
@@ -29,7 +26,7 @@ public function getContent(): TContent {
2926

3027
<<__Override>>
3128
public function isInsertOp(): bool {
32-
return true;
29+
return true;
3330
}
3431

3532
<<__Override>>

src/StringDiff.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,7 @@ public function getUnifiedDiff(int $context = 3): string {
9090
|> Str\join($$, '');
9191
}
9292

93-
private function getUnifiedDiffHunk(
94-
vec<DiffOp<string>> $hunk,
95-
): ?string {
93+
private function getUnifiedDiffHunk(vec<DiffOp<string>> $hunk): ?string {
9694
if (C\is_empty($hunk)) {
9795
return null;
9896
}
@@ -132,10 +130,7 @@ private function getUnifiedDiffHunk(
132130
continue;
133131
}
134132

135-
invariant_violation(
136-
'Unsupported diff op: %s',
137-
\get_class($op),
138-
);
133+
invariant_violation('Unsupported diff op: %s', \get_class($op));
139134
}
140135
invariant($old_start !== null, 'failed to find an old pos');
141136
invariant($new_start !== null, 'failed to find a new pos');
@@ -148,6 +143,8 @@ private function getUnifiedDiffHunk(
148143
"@@ -%s +%s @@\n",
149144
$format($old_start + 1, $old_lines),
150145
$format($new_start + 1, $new_lines),
151-
).Str\join($lines, "\n")."\n";
146+
).
147+
Str\join($lines, "\n").
148+
"\n";
152149
}
153150
}

src/cluster.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@
1717
* For example, `[insert(a), insert(b), keep(c), insert(d), insert(e)]` will
1818
* be transformed to `[insert([a, b]), keep([c]), insert([d, e])`.
1919
*/
20-
function cluster<T>(
21-
vec<DiffOp<T>> $diff,
22-
): vec<DiffOp<vec<T>>> {
20+
function cluster<T>(vec<DiffOp<T>> $diff): vec<DiffOp<vec<T>>> {
2321
$clusters = vec[];
2422
while (!C\is_empty($diff)) {
2523
$class = $diff[0]->getDiffOpClass();
@@ -63,6 +61,6 @@ function cluster<T>(
6361
}
6462

6563
invariant_violation('invalid op kind: %s', \get_class($first));
66-
}
64+
},
6765
);
6866
}

0 commit comments

Comments
 (0)