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

Commit edc68c9

Browse files
committed
Calculate blame code for the HHClientLinter
1 parent 6707140 commit edc68c9

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

src/Linters/HHClientLinter.hack

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
namespace Facebook\HHAST;
1111

1212
use namespace Facebook\TypeAssert;
13-
use namespace HH\Lib\{C, Vec};
13+
use namespace HH\Lib\{C, Str, Vec};
1414

1515
/**
1616
* A linter as a proxy invoking `hh_client --lint`.
@@ -25,6 +25,20 @@ final class HHClientLinter implements Linter {
2525
'version' => string,
2626
);
2727

28+
private static function blameCode(
29+
vec<string> $file_lines,
30+
HHClientLintError::TJSONError $error,
31+
): string {
32+
$line_number_1base = $error['line'];
33+
$line_index_0base = $line_number_1base - 1;
34+
$line_content = $file_lines[$line_index_0base];
35+
return Str\slice(
36+
$line_content,
37+
$error['start'],
38+
$error['end'] - $error['start'],
39+
);
40+
}
41+
2842
public async function getLintErrorsAsync(
2943
): Awaitable<vec<HHClientLintError>> {
3044
$lines = await __Private\execute_async(
@@ -43,9 +57,14 @@ final class HHClientLinter implements Linter {
4357
\JSON_FB_HACK_ARRAYS,
4458
),
4559
);
60+
$file_lines = Str\split($this->getFile()->getContents(), "\n");
4661
return Vec\map(
4762
$hh_client_lint_result['errors'],
48-
$error ==> new HHClientLintError($this->file, $error),
63+
$error ==> new HHClientLintError(
64+
$this->file,
65+
$error,
66+
$this::blameCode($file_lines, $error),
67+
),
4968
);
5069
}
5170
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[
22
{
3-
"blame": null,
4-
"blame_pretty": null,
3+
"blame": "cannot_be_null is null",
4+
"blame_pretty": "cannot_be_null is null",
55
"description": "Invalid null check: This expression will always return `false`.\nA value of type `int` can never be null."
66
}
77
]

0 commit comments

Comments
 (0)