Comments (2)
Here's the basics of just assertEquals - doesn't handle whitespace, comments, generating nice code etc, but gets the semantics right:
<?hh // strict
/*
* 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\Linters;
use type Facebook\HHAST\{
EditableNode,
EditableList,
FunctionCallExpression,
BinaryExpression,
MemberSelectionExpression,
LeftParenToken,
RightParenToken,
NameToken,
EqualToken,
DelimitedComment,
ListItem,
CommaToken,
WhiteSpace,
};
use function Facebook\HHAST\Missing;
use namespace Facebook\TypeAssert;
use namespace HH\Lib\{C, Str, Vec};
final class NoAssertEqualsLinter
extends AutoFixingASTLinter<FunctionCallExpression> {
<<__Override>>
protected static function getTargetType(): classname<FunctionCallExpression> {
return FunctionCallExpression::class;
}
<<__Override>>
public function getLintErrorForNode(
FunctionCallExpression $node,
vec<EditableNode> $parents,
): ?FixableASTLintError<FunctionCallExpression> {
$rec = $node->getReceiver();
if (!$rec instanceof MemberSelectionExpression) {
return null;
}
$method = $rec->getName()->getCode();
if ($method !== 'assertEquals') {
return null;
}
return new FixableASTLintError($this, "use fbexpect", $node);
}
<<__Override>>
public function getFixedNode(
FunctionCallExpression $node,
): FunctionCallExpression {
$params = vec($node->getArgumentListx()->getChildren());
$expected = $params[0];
$actual = $params[1];
$message = Vec\drop($params, 2);
$rec = $node->getReceiver();
invariant(
$rec instanceof MemberSelectionExpression,
'receiver should be a member selection expression',
);
return $node
->withReceiver(
$rec->withObject(
new FunctionCallExpression(
new NameToken(
$rec->getObject()->getFirstTokenx()->getLeading(),
Missing(),
'expect',
),
new LeftParenToken(Missing(), Missing()),
new EditableList(vec[$actual]),
new RightParenToken(Missing(), Missing()),
),
)
->withName(new NameToken(Missing(), Missing(), 'toBeSame')),
)
->withArgumentList(
new EditableList(Vec\concat(vec[$expected], $message)),
);
}
}
from hhast.
Done in that PR
from hhast.
Related Issues (20)
- UnusedVariable false positive in method signature
- Drop support for the `@` error suppression operator HOT 1
- [ Regression ] Mismatched configuration for a linter should fail the lint run HOT 2
- Suppression comments for HHClientLinter don't mesh well with /**/ comments HOT 3
- Known bad HHClientLinters need to be automatically unconditionally suppressed HOT 5
- Delete HHAST linters that duplicate good HHClientLinters HOT 6
- Support readable aliases for HHClientLinter rules HOT 4
- Linter to check if the result of the new operator is silently discarded
- Support HHAST_IGNORE_ALL for hhclientlinter codes HOT 2
- Disable some lint rules by default HOT 2
- hh_client lints are slow and unreliable in IDE HOT 1
- Overrides are not respected with recent update HOT 1
- [ RFC ] Adding an optional allow list to hhast-lint.json HOT 1
- Fix attribution for schema update commits HOT 4
- HHAST crashes with nightly HHVM
- GitHub Actions are not triggered for the pull request to update schema
- DontSuppressLintErrorsLinter
- DontReassignParametersLinter
- DontReturnFromCloneLinter
- Remove use of the XHProf profiler
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hhast.