You're Invited: Meet the Socket team at BSidesSF and RSAC - April 27 - May 1.RSVP

eslint-plugin-react-web-api

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-react-web-api - npm Package Compare versions

Comparing version

to
1.12.2-beta.1

@@ -12,7 +12,31 @@ 'use strict';

var shared = require('@eslint-react/shared');
var types = require('@typescript-eslint/types');
// package.json
var name = "eslint-plugin-react-web-api";
var version = "1.12.1";
var version = "1.12.2-beta.1";
var createRule = shared.createRuleForPlugin("web-api");
function getTimerID(node, prev) {
switch (true) {
case (node.type === types.AST_NODE_TYPES.VariableDeclarator && node.init === prev):
return tools.O.some(node.id);
case (node.type === types.AST_NODE_TYPES.AssignmentExpression && node.right === prev):
return tools.O.some(node.left);
case (node.type === types.AST_NODE_TYPES.BlockStatement || node.type === types.AST_NODE_TYPES.Program || node.parent === node):
return tools.O.none();
default:
return getTimerID(node.parent, node);
}
}
function isTimerIDEqual(a, b, context) {
const aScope = context.sourceCode.getScope(a);
const bScope = context.sourceCode.getScope(b);
switch (true) {
case (a.type === types.AST_NODE_TYPES.AssignmentExpression && b.type === types.AST_NODE_TYPES.AssignmentExpression): {
return ast.isNodeEqual(a.left, b.left);
}
default:
return _var.isNodeValueEqual(a, b, [aScope, bScope]);
}
}

@@ -33,3 +57,3 @@ // src/rules/no-leaked-event-listener.ts

function getFunctionKind(node) {
return tsPattern.match(node).when(core.isSetupFunction, () => "setup").when(core.isCleanupFunction, () => "cleanup").when(core.isComponentDidMountFunction, () => "mount").when(core.isComponentWillUnmountFunction, () => "unmount").otherwise(() => "other");
return tools.O.getOrElse(core.getPhaseKindOfFunction(node), tools.F.constant("other"));
}

@@ -188,17 +212,2 @@ function getOptions(node, initialScope) {

}
function getFunctionKind2(node) {
return tsPattern.match(node).when(core.isSetupFunction, () => "setup").when(core.isCleanupFunction, () => "cleanup").when(core.isComponentDidMountFunction, () => "mount").when(core.isComponentWillUnmountFunction, () => "unmount").otherwise(() => "other");
}
function getIntervalID(node, prev) {
switch (true) {
case (node.type === utils.AST_NODE_TYPES.VariableDeclarator && node.init === prev):
return tools.O.some(node.id);
case (node.type === utils.AST_NODE_TYPES.AssignmentExpression && node.right === prev):
return tools.O.some(node.left);
case (node.type === utils.AST_NODE_TYPES.BlockStatement || node.type === utils.AST_NODE_TYPES.Program || node.parent === node):
return tools.O.none();
default:
return getIntervalID(node.parent, node);
}
}
var no_leaked_interval_default = createRule({

@@ -222,22 +231,9 @@ meta: {

const sEntries = [];
const rEntries = [];
const cEntries = [];
const isInverseEntry = tools.F.dual(2, (a, b) => {
const aIntervalID = a.intervalID;
const bIntervalID = b.intervalID;
const aIntervalIDScope = context.sourceCode.getScope(aIntervalID);
const bIntervalIDScope = context.sourceCode.getScope(bIntervalID);
switch (true) {
case (aIntervalID.type === utils.AST_NODE_TYPES.Identifier && bIntervalID.type === utils.AST_NODE_TYPES.Identifier): {
return _var.isNodeValueEqual(aIntervalID, bIntervalID, [aIntervalIDScope, bIntervalIDScope]);
}
case (aIntervalID.type === utils.AST_NODE_TYPES.AssignmentExpression && bIntervalID.type === utils.AST_NODE_TYPES.AssignmentExpression): {
return ast.isNodeEqual(aIntervalID.left, bIntervalID.left);
}
default:
return _var.isNodeValueEqual(aIntervalID, bIntervalID, [aIntervalIDScope, bIntervalIDScope]);
}
return isTimerIDEqual(a.timerID, b.timerID, context);
});
return {
[":function"](node) {
const fKind = getFunctionKind2(node);
const fKind = tools.O.getOrElse(core.getPhaseKindOfFunction(node), () => "other");
fStack.push([node, fKind]);

@@ -255,3 +251,3 @@ },

if (!core.PHASE_RELEVANCE.has(fKind)) break;
const intervalIdNode = tools.O.getOrNull(getIntervalID(node));
const intervalIdNode = tools.O.getOrNull(getTimerID(node));
if (!intervalIdNode) {

@@ -268,4 +264,4 @@ context.report({

callee: node.callee,
intervalID: intervalIdNode,
phase: fKind
phase: fKind,
timerID: intervalIdNode
});

@@ -280,8 +276,8 @@ break;

if (!intervalIdNode) break;
rEntries.push({
cEntries.push({
kind: callKind,
node,
callee: node.callee,
intervalID: intervalIdNode,
phase: fKind
phase: fKind,
timerID: intervalIdNode
});

@@ -294,3 +290,3 @@ break;

for (const sEntry of sEntries) {
if (rEntries.some(isInverseEntry(sEntry))) continue;
if (cEntries.some(isInverseEntry(sEntry))) continue;
switch (sEntry.phase) {

@@ -335,17 +331,2 @@ case "setup":

}
function getFunctionKind3(node) {
return tsPattern.match(node).when(core.isSetupFunction, () => "setup").when(core.isCleanupFunction, () => "cleanup").when(core.isComponentDidMountFunction, () => "mount").when(core.isComponentWillUnmountFunction, () => "unmount").otherwise(() => "other");
}
function getTimeoutID(node, prev) {
switch (true) {
case (node.type === utils.AST_NODE_TYPES.VariableDeclarator && node.init === prev):
return tools.O.some(node.id);
case (node.type === utils.AST_NODE_TYPES.AssignmentExpression && node.right === prev):
return tools.O.some(node.left);
case (node.type === utils.AST_NODE_TYPES.BlockStatement || node.type === utils.AST_NODE_TYPES.Program || node.parent === node):
return tools.O.none();
default:
return getTimeoutID(node.parent, node);
}
}
var no_leaked_timeout_default = createRule({

@@ -371,20 +352,7 @@ meta: {

const isInverseEntry = tools.F.dual(2, (a, b) => {
const aTimeoutID = a.timeoutID;
const bTimeoutID = b.timeoutID;
const aTimeoutIDScope = context.sourceCode.getScope(aTimeoutID);
const bTimeoutIDScope = context.sourceCode.getScope(bTimeoutID);
switch (true) {
case (aTimeoutID.type === utils.AST_NODE_TYPES.Identifier && bTimeoutID.type === utils.AST_NODE_TYPES.Identifier): {
return _var.isNodeValueEqual(aTimeoutID, bTimeoutID, [aTimeoutIDScope, bTimeoutIDScope]);
}
case (aTimeoutID.type === utils.AST_NODE_TYPES.AssignmentExpression && bTimeoutID.type === utils.AST_NODE_TYPES.AssignmentExpression): {
return ast.isNodeEqual(aTimeoutID.left, bTimeoutID.left);
}
default:
return _var.isNodeValueEqual(aTimeoutID, bTimeoutID, [aTimeoutIDScope, bTimeoutIDScope]);
}
return isTimerIDEqual(a.timerID, b.timerID, context);
});
return {
[":function"](node) {
const fKind = getFunctionKind3(node);
const fKind = tools.O.getOrElse(core.getPhaseKindOfFunction(node), () => "other");
fStack.push([node, fKind]);

@@ -402,3 +370,3 @@ },

if (!core.PHASE_RELEVANCE.has(fKind)) break;
const timeoutIdNode = tools.O.getOrNull(getTimeoutID(node));
const timeoutIdNode = tools.O.getOrNull(getTimerID(node));
if (!timeoutIdNode) {

@@ -416,3 +384,3 @@ context.report({

phase: fKind,
timeoutID: timeoutIdNode
timerID: timeoutIdNode
});

@@ -432,3 +400,3 @@ break;

phase: fKind,
timeoutID: timeoutIdNode
timerID: timeoutIdNode
});

@@ -435,0 +403,0 @@ break;

{
"name": "eslint-plugin-react-web-api",
"version": "1.12.1",
"version": "1.12.2-beta.1",
"description": "ESLint React's ESLint plugin for interacting with Web APIs",

@@ -50,9 +50,9 @@ "keywords": [

"ts-pattern": "^5.3.1",
"@eslint-react/ast": "1.12.1",
"@eslint-react/core": "1.12.1",
"@eslint-react/shared": "1.12.1",
"@eslint-react/types": "1.12.1",
"@eslint-react/jsx": "1.12.1",
"@eslint-react/tools": "1.12.1",
"@eslint-react/var": "1.12.1"
"@eslint-react/ast": "1.12.2-beta.1",
"@eslint-react/core": "1.12.2-beta.1",
"@eslint-react/jsx": "1.12.2-beta.1",
"@eslint-react/shared": "1.12.2-beta.1",
"@eslint-react/tools": "1.12.2-beta.1",
"@eslint-react/types": "1.12.2-beta.1",
"@eslint-react/var": "1.12.2-beta.1"
},

@@ -59,0 +59,0 @@ "devDependencies": {

@@ -30,2 +30,4 @@ # eslint-plugin-react-web-api

// react-web-api recommended rules
"react-web-api/no-leaked-timeout": "error",
"react-web-api/no-leaked-interval": "error",
"react-web-api/no-leaked-event-listener": "error",

@@ -32,0 +34,0 @@ }

Sorry, the diff of this file is not supported yet