forked from phewphewb/eslint-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
235 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
Object.defineProperty(exports, "noUnawaitedSkeletons", { | ||
enumerable: true, | ||
get: ()=>_noUnawaitedSkeletons | ||
}); | ||
const _noUnawaitedSkeletons = /*#__PURE__*/ _interopRequireWildcard(require("./noUnawaitedSkeletons")); | ||
function _getRequireWildcardCache(nodeInterop) { | ||
if (typeof WeakMap !== "function") return null; | ||
var cacheBabelInterop = new WeakMap(); | ||
var cacheNodeInterop = new WeakMap(); | ||
return (_getRequireWildcardCache = function(nodeInterop) { | ||
return nodeInterop ? cacheNodeInterop : cacheBabelInterop; | ||
})(nodeInterop); | ||
} | ||
function _interopRequireWildcard(obj, nodeInterop) { | ||
if (!nodeInterop && obj && obj.__esModule) { | ||
return obj; | ||
} | ||
if (obj === null || typeof obj !== "object" && typeof obj !== "function") { | ||
return { | ||
default: obj | ||
}; | ||
} | ||
var cache = _getRequireWildcardCache(nodeInterop); | ||
if (cache && cache.has(obj)) { | ||
return cache.get(obj); | ||
} | ||
var newObj = {}; | ||
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; | ||
for(var key in obj){ | ||
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { | ||
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; | ||
if (desc && (desc.get || desc.set)) { | ||
Object.defineProperty(newObj, key, desc); | ||
} else { | ||
newObj[key] = obj[key]; | ||
} | ||
} | ||
} | ||
newObj.default = obj; | ||
if (cache) { | ||
cache.set(obj, newObj); | ||
} | ||
return newObj; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
function _export(target, all) { | ||
for(var name in all)Object.defineProperty(target, name, { | ||
enumerable: true, | ||
get: all[name] | ||
}); | ||
} | ||
_export(exports, { | ||
meta: ()=>meta, | ||
create: ()=>create | ||
}); | ||
const _utils = require("../utils"); | ||
const meta = { | ||
type: "problem", | ||
docs: { | ||
category: "code", | ||
description: "Enforces skeletons to be wrapped into `waitFor` to avoid `should be wrapped in act(...) error`" | ||
}, | ||
hasSuggestions: false, | ||
fixable: false, | ||
schema: [ | ||
{ | ||
type: "object", | ||
properties: { | ||
testIds: { | ||
type: "array", | ||
items: { | ||
type: "string" | ||
} | ||
} | ||
}, | ||
required: [ | ||
"testIds" | ||
], | ||
additionalProperties: false | ||
} | ||
] | ||
}; | ||
const isWaitFor = (node)=>(0, _utils.isCalleName)(node, "waitFor"); | ||
/** | ||
* @description the below constant array is for the following code examples | ||
* [0] | ||
* await waitFor(() => { | ||
* expect(screen.queryByTestId("aviary-skeleton")).not.toBeInTheDocument(); | ||
* }); | ||
* [1] | ||
* await waitFor(() => { | ||
* expect(screen.getByTestId("aviary-skeleton")).toBeInTheDocument(); | ||
* }); | ||
* [2] | ||
* await waitFor(() => expect(screen.queryAllByTestId("aviary-skeleton")).toHaveLength(0)); | ||
* [3] | ||
* expect(screen.queryByTestId("aviary-skeleton")).not.toBeInTheDocument() | ||
*/ const WAIT_FOR_PATHS = [ | ||
[ | ||
"CallExpression", | ||
"MemberExpression", | ||
"MemberExpression", | ||
"CallExpression", | ||
"ExpressionStatement", | ||
"BlockStatement", | ||
"ArrowFunctionExpression", | ||
"CallExpression" | ||
], | ||
[ | ||
"CallExpression", | ||
"MemberExpression", | ||
"CallExpression", | ||
"ExpressionStatement", | ||
"BlockStatement", | ||
"ArrowFunctionExpression", | ||
"CallExpression" | ||
], | ||
[ | ||
"CallExpression", | ||
"MemberExpression", | ||
"CallExpression", | ||
"ArrowFunctionExpression", | ||
"CallExpression" | ||
], | ||
[ | ||
"CallExpression", | ||
"MemberExpression", | ||
"MemberExpression", | ||
"CallExpression", | ||
"ArrowFunctionExpression", | ||
"CallExpression" | ||
] | ||
]; | ||
const create = (context)=>{ | ||
const [{ testIds }] = context.options; | ||
return { | ||
CallExpression: (node)=>{ | ||
if (!(0, _utils.isExpect)(node)) return; | ||
const [call] = node.arguments; | ||
if (!(0, _utils.isCallExpression)(call)) return; | ||
const [literal] = call.arguments; | ||
if (!(0, _utils.isLiteral)(literal)) return; | ||
const { value } = literal; | ||
if (!testIds.includes(value)) return; | ||
/** | ||
* Taking expect(...) call as the base | ||
* Going up by any of the paths the found node should be `waitFor` expressions | ||
* Report if it is not. | ||
* */ const callExpression = (0, _utils.findByPaths)(WAIT_FOR_PATHS, node); | ||
if (isWaitFor(callExpression)) return; | ||
context.report({ | ||
node, | ||
message: "Checks for loading state should be wrapped in a `waitFor` block to prevent act warnings" | ||
}); | ||
} | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// types | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
function _export(target, all) { | ||
for(var name in all)Object.defineProperty(target, name, { | ||
enumerable: true, | ||
get: all[name] | ||
}); | ||
} | ||
_export(exports, { | ||
isCallExpression: ()=>isCallExpression, | ||
isLiteral: ()=>isLiteral, | ||
isAwaitExpression: ()=>isAwaitExpression, | ||
isCalleName: ()=>isCalleName, | ||
isExpect: ()=>isExpect, | ||
findByPaths: ()=>findByPaths | ||
}); | ||
const isType = (node, type)=>{ | ||
return (node === null || node === void 0 ? void 0 : node.type) === type; | ||
}; | ||
const isCallExpression = (node)=>isType(node, "CallExpression"); | ||
const isLiteral = (node)=>isType(node, "Literal"); | ||
const isAwaitExpression = (node)=>isType(node, "AwaitExpression"); | ||
// calee | ||
const isCalleName = (node, name)=>{ | ||
var _node_callee; | ||
return (node === null || node === void 0 ? void 0 : (_node_callee = node.callee) === null || _node_callee === void 0 ? void 0 : _node_callee.name) === name; | ||
}; | ||
const isExpect = (node)=>isCalleName(node, "expect"); | ||
// finder | ||
const findNode = (path, tree)=>{ | ||
if (!tree || !path) return null; | ||
const current = path.shift(); | ||
if (!isType(tree, current)) return null; | ||
else if (path.length === 0) return tree; | ||
return findNode(path, tree.parent); | ||
}; | ||
const findByPaths = (paths, tree)=>{ | ||
for (const path of paths){ | ||
const found = findNode([ | ||
...path | ||
], tree); | ||
if (found) return found; | ||
} | ||
return null; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
_exportStar(require("./astUtils"), exports); | ||
function _exportStar(from, to) { | ||
Object.keys(from).forEach(function(k) { | ||
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, { | ||
enumerable: true, | ||
get: function() { | ||
return from[k]; | ||
} | ||
}); | ||
}); | ||
return from; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
{ | ||
"name": "@fullscript/eslint-plugin", | ||
"version": "1.3.0", | ||
"version": "1.4.0", | ||
"description": "Fullscript custom eslint rules", | ||
"main": "dist/index.js", | ||
"contributors": [ | ||
"Hossam Mourad", | ||
"Ryan O'Connor <[email protected]>", | ||
"Aidan Feuerherm <[email protected]>" | ||
"Aidan Feuerherm <[email protected]>", | ||
"Valentyn Patsera <[email protected]>" | ||
], | ||
"license": "MIT", | ||
"private": false, | ||
|