eslint-plugin-storybook
Advanced tools
Comparing version 0.6.5 to 0.6.6
@@ -0,1 +1,14 @@ | ||
# v0.6.6 (Tue Oct 11 2022) | ||
#### 🐛 Bug Fix | ||
- fix: await interactions rule scope. [#100](https://github.com/storybookjs/eslint-plugin-storybook/pull/100) ([@zhyd1997](https://github.com/zhyd1997) [@yannbf](https://github.com/yannbf)) | ||
#### Authors: 2 | ||
- Yadong Zhang ([@zhyd1997](https://github.com/zhyd1997)) | ||
- Yann Braga ([@yannbf](https://github.com/yannbf)) | ||
--- | ||
# v0.6.5 (Mon Oct 10 2022) | ||
@@ -2,0 +15,0 @@ |
@@ -89,2 +89,12 @@ "use strict"; | ||
}; | ||
const isUserEventFromStorybookImported = (node) => { | ||
return (node.source.value === '@storybook/testing-library' && | ||
node.specifiers.find((spec) => (0, ast_1.isImportSpecifier)(spec) && | ||
spec.imported.name === 'userEvent' && | ||
spec.local.name === 'userEvent') !== undefined); | ||
}; | ||
const isExpectFromStorybookImported = (node) => { | ||
return (node.source.value === '@storybook/jest' && | ||
node.specifiers.find((spec) => (0, ast_1.isImportSpecifier)(spec) && spec.imported.name === 'expect') !== undefined); | ||
}; | ||
//---------------------------------------------------------------------- | ||
@@ -96,4 +106,13 @@ // Public | ||
*/ | ||
let isImportedFromStorybook = true; | ||
let invocationsThatShouldBeAwaited = []; | ||
return { | ||
ImportDeclaration(node) { | ||
isImportedFromStorybook = | ||
isUserEventFromStorybookImported(node) || isExpectFromStorybookImported(node); | ||
}, | ||
VariableDeclarator(node) { | ||
isImportedFromStorybook = | ||
isImportedFromStorybook && (0, ast_1.isIdentifier)(node.id) && node.id.name !== 'userEvent'; | ||
}, | ||
CallExpression(node) { | ||
@@ -107,3 +126,3 @@ var _a; | ||
'Program:exit': function () { | ||
if (invocationsThatShouldBeAwaited.length) { | ||
if (isImportedFromStorybook && invocationsThatShouldBeAwaited.length) { | ||
invocationsThatShouldBeAwaited.forEach(({ node, method }) => { | ||
@@ -110,0 +129,0 @@ const parentFnNode = getClosestFunctionAncestor(node); |
{ | ||
"name": "eslint-plugin-storybook", | ||
"version": "0.6.5", | ||
"version": "0.6.6", | ||
"description": "Best practice rules for Storybook", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
101502
1572