forked from hhvm/hhast
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTypeErrorMigrationTrait.hack
50 lines (42 loc) · 1.29 KB
/
TypeErrorMigrationTrait.hack
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
* Copyright (c) 2017-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
namespace Facebook\HHAST;
use function Facebook\HHAST\__Private\get_typechecker_errors;
use type Facebook\HHAST\__Private\TTypecheckerError;
use namespace HH\Lib\{C, Keyset, Vec};
trait TypeErrorMigrationTrait implements IMigrationWithFileList {
private string $root;
public function __construct(string $root) {
$this->root = $root;
}
abstract protected static function filterTypecheckerError(
TTypecheckerError $in,
): bool;
<<__Memoize>>
final private function getTypecheckerErrors(): vec<TTypecheckerError> {
return Vec\filter(
get_typechecker_errors($this->root),
$error ==> static::filterTypecheckerError($error),
);
}
final protected function getTypecheckerErrorsForFile(
string $file,
): vec<TTypecheckerError> {
return Vec\filter(
$this->getTypecheckerErrors(),
$error ==> C\firstx($error['message'])['path'] === $file,
);
}
final public function getFilePathsToMigrate(): keyset<string> {
return Keyset\map(
$this->getTypecheckerErrors(),
$error ==> C\firstx($error['message'])['path'],
);
}
}