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
chore: add parseExpect() util function #101
Conversation
Ooooh, awesome! I really like this, it's pretty much how I imagined it. Great start!
Yeah, I think playing around with in in the different rules would be good, to see how it holds up |
I will follow up with a commit or another PR in the next week or two when I
have computer access again. 🙂
…On Mon, Mar 19, 2018 at 3:41 AM Simen Bekkhus ***@***.***> wrote:
Ooooh, awesome! I really like this, it's pretty much how I imagined it.
Great start!
Thoughts on this as a starting point? I haven't integrated this function
into any of the rules, but I'd be happy to explore that refactoring in this
PR if we'd like to see what this API looks like when it's used.
Yeah, I think playing around with in in the different rules would be good,
to see how it holds up
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#101 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ACPEyUZ0ers8Fo8lEFAbI7XAzLgZTrm-ks5tf2EvgaJpZM4Spooy>
.
|
I have a computer set up for programming again, will follow up today or this week on this PR. 👍 |
7820ac6
to
dd4aea6
Compare
@macklinu GitHub doesn't send emails for pushes in this repo for some reason... Is this good to go? |
@SimenB it may have been me rebasing this branch and force-pushing back up (for why you didn't receive a notification). This slipped my mind for a bit - will have some time in the next couple weeks to follow up with integrating this util function into a rule. Shall I close this and reopen when it's ready for another review? |
I don't mind it being open if you don't 🙂 Give me a ping when you think it's ready for review, or have any questions. |
I tried to use this util to implement #103 to see how it would work in practice. I think it handles parsing a function create(context) {
return {
CallExpression(node) {
const expect = parseExpect(node)
if (!expect) return
// do something with the `expect` object
},
}
} However, for the case of #103 and handling a // code to lint
test('my test', () => {
expect(a).toMatchSnapshot('a')
expect(b).toMatchSnapshot('b')
})
// sample rule
const rule = {
create(context) {
return {
CallExpression(node) {
if (util.isTestCase(node)) {
const expectsWithinTestCase = node.arguments[1].body.body.reduce(
(array, node) => {
const expect = parseExpect(node.expression);
return expect ? array.concat(expect) : array;
},
[]
);
console.log(expectsWithinTestCase); // always empty, ideally would be length 2
}
},
};
} There might be a better way to analyze multiple |
dd4aea6
to
a532a25
Compare
Added in #383 |
This is related to #73. I was curious to see what a
parseExpect()
function looked like and to get some feedback on it. Right now it looks like:I can see helper functions being built on top of this parsing function, like:
I can also see this helping simplify some of the logic in the
valid-expect
rule (and the WIP #78).Thoughts on this as a starting point? I haven't integrated this function into any of the rules, but I'd be happy to explore that refactoring in this PR if we'd like to see what this API looks like when it's used.