-
Notifications
You must be signed in to change notification settings - Fork 49
Make writing "within a test" and "t.XXX" matchers easier: #72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Err wait - this is the linter, not codemods. Can't keep all the AVA related AST projects straight. |
// @twada |
Agree with the idea, but I'm not sure it's a good idea. I noticed that we don't handle cases like this function implementation(t) {
t.doWhatever();
}
test(implementation); though we might want to, especially with the talk about "macros" in avajs/ava#695. In this case, the "in test" part will pretty much always be wrong. Otherwise, I think we don't need to add the We can definitely add the |
Hmm, I think that's out of scope of static analysis tool, it's better and easier to detect and report at runtime. |
@twada What specifically is out of scope? |
Chasing some kind of macros, renamed variables, destructuring, etc. |
What do you guys think of specifying a simple filter function instead? From CallExpression: function (node) {
// only check if we are within a test file, and if this CallExpression is within a test.
if (!ava.isTestFile || !ava.currentTestNode) {
return;
}
} to // exported by create-ava-rule for instance
function ifInAVATest(fn) {
return function(node) {
if (ava.isTestFile && ava.currentTestNode) {
return fn(node);
}
};
}
// test file
CallExpression: ifInAVATest(function (node) {
// do stuff
}) No new sugar, just explicit functions, and they're chainable too if needed. |
Even better: just have some predicate functions and a visitor filter function // create-ava-rule.js
function isAssertion(node) {
return node.type === 'CallExpression' && ...
}
function callIf(...fns) {
return function(visitor) {
return function (node) {
// some kind of
if (fns.every((fn) => fn(node)) {
visitor(node);
}
};
};
}
// test file
CallExpression: callIf(ava.isAssertion, ava.fooBar)(function (node) {
// do stuff
// I can still use ava.isAssertion programmatically
}) |
@jfmengels I like it. @jamestalmage ? |
@jfmengels Wow it looks nice :) |
👍 |
We have this code construct everywhere:
I propose we add some sugar to
ava.merge()
that allows something like this:While we are at it, we should define one (specifically for CallExpression), that checks the callee is a
MemberExpression
of the formt.XXX
:The text was updated successfully, but these errors were encountered: