forked from hhvm/hhast
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPreferRequireOnceLinter.hack
More file actions
46 lines (40 loc) · 1.18 KB
/
Copy pathPreferRequireOnceLinter.hack
File metadata and controls
46 lines (40 loc) · 1.18 KB
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
/*
* 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;
final class PreferRequireOnceLinter extends AutoFixingASTLinter {
const type TConfig = shape();
const type TContext = Script;
const type TNode = InclusionExpression;
<<__Override>>
public function getLintErrorForNode(
Script $_context,
InclusionExpression $node,
): ?ASTLintError {
if ($node->getRequire() is Require_onceToken) {
return null;
}
return new ASTLintError(
$this,
'Prefer "require_once" over "include(_once)" and "require"',
$node,
() ==> $this->getFixedNode($node),
);
}
public function getFixedNode(InclusionExpression $node): ?Node {
$left_trivia = $node->getRequire()->getLeading();
$right_trivia = $node->getRequire()->getTrailing();
return $node->withRequire(
new Require_onceToken($left_trivia, $right_trivia),
);
}
<<__Override>>
protected function getTitleForFix(SingleRuleLintError $_): string {
return 'Change to "require_once"';
}
}