Skip to content

Commit

Permalink
1.4.0 release
Browse files Browse the repository at this point in the history
  • Loading branch information
charle692 committed Dec 21, 2022
1 parent a3ab48f commit bba2a73
Show file tree
Hide file tree
Showing 7 changed files with 235 additions and 3 deletions.
4 changes: 3 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ const _circularDependency = require("./circularDependency");
const _crossReference = require("./crossReference");
const _gqlRules = require("./gqlRules");
const _noRenamedTranslationImport = require("./noRenamedTranslationImport");
const _noUnawaitedSkeletons = require("./noUnawaitedSkeletons");
const _oneTranslationImport = require("./oneTranslationImport");
const rules = {
"one-translation-import-per-file": _oneTranslationImport.oneTranslationImport,
"no-renamed-translation-import": _noRenamedTranslationImport.noRenamedTranslationImport,
"gql-objects": _gqlRules.gqlObjects,
"gql-operation-name": _gqlRules.gqlOperationName,
"cross-reference": _crossReference.crossReference,
"circular-dependency": _circularDependency.circularDependency
"circular-dependency": _circularDependency.circularDependency,
"no-unawaited-skeletons": _noUnawaitedSkeletons.noUnawaitedSkeletons
};
48 changes: 48 additions & 0 deletions dist/noUnawaitedSkeletons/index.js
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;
}
116 changes: 116 additions & 0 deletions dist/noUnawaitedSkeletons/noUnawaitedSkeletons.js
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"
});
}
};
};
48 changes: 48 additions & 0 deletions dist/utils/ast/astUtils.js
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;
};
16 changes: 16 additions & 0 deletions dist/utils/ast/index.js
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;
}
1 change: 1 addition & 0 deletions dist/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
});
_exportStar(require("./isTranslationSource"), exports);
_exportStar(require("./relativePathToFile"), exports);
_exportStar(require("./ast"), exports);
function _exportStar(from, to) {
Object.keys(from).forEach(function(k) {
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
Expand Down
5 changes: 3 additions & 2 deletions package.json
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,
Expand Down

0 comments on commit bba2a73

Please sign in to comment.