forked from hhvm/hhast
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DontUseAsioJoinLinter.hack
54 lines (46 loc) · 1.38 KB
/
DontUseAsioJoinLinter.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
51
52
53
54
/*
* 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 namespace HH\Lib\{Str, Vec};
final class DontUseAsioJoinLinter extends AutoFixingASTLinter {
const type TContext = Script;
const type TNode = FunctionCallExpression;
const string F_JOIN = 'HH\\Asio\\join';
<<__Override>>
public function getLintErrorForNode(
Script $context,
this::TNode $node,
): ?ASTLintError {
$name = $node->getReceiver();
if ($name is NameToken) {
$string_name = $name->getText();
} else if ($name is QualifiedName) {
$string_name = $name->getDescendantsByType<NameToken>()
|> Vec\map($$, $n ==> $n->getText())
|> Str\join($$, '\\');
if (qualified_name_is_fully_qualified($name)) {
$string_name = '\\'.$string_name;
}
} else {
return null;
}
// Performance won't suffer from resolving a fully qualified name.
// This is handled very efficiently in resolve_function().
$resolved_name = resolve_function($string_name, $context, $node)['name'];
if ($resolved_name !== self::F_JOIN) {
return null;
}
return new ASTLintError(
$this,
"Don't use ".static::F_JOIN,
$node,
() ==> null,
);
}
}