Socket
Socket
Sign inDemoInstall

eslint-plugin-react-hooks

Package Overview
Dependencies
Maintainers
2
Versions
1827
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-react-hooks - npm Package Compare versions

Comparing version 0.0.0 to 1.0.0

37

cjs/eslint-plugin-react-hooks.development.js

@@ -1,2 +0,2 @@

/** @license React v16.7.0-alpha.0
/** @license React v16.6.1
* eslint-plugin-react-hooks.development.js

@@ -178,3 +178,5 @@ *

cache.set(segment.id, null);
if (segment.prevSegments.length === 0) {
if (codePath.thrownSegments.includes(segment)) {
paths = 0;
} else if (segment.prevSegments.length === 0) {
paths = 1;

@@ -208,4 +210,11 @@ } else {

}
cache.set(segment.id, paths);
// If our segment is reachable then there should be at least one path
// to it from the start of our code path.
if (segment.reachable && paths === 0) {
cache.delete(segment.id);
} else {
cache.set(segment.id, paths);
}
return paths;

@@ -284,3 +293,5 @@ }

cache.set(segment.id, null);
if (segment.nextSegments.length === 0) {
if (codePath.thrownSegments.includes(segment)) {
paths = 0;
} else if (segment.nextSegments.length === 0) {
paths = 1;

@@ -408,3 +419,3 @@ } else {

// expression or our code path is not in a function. In both cases we
// will want to error since neither are React functional components or
// will want to error since neither are React function components or
// hook functions.

@@ -414,3 +425,3 @@ var codePathFunctionName = getFunctionName(codePathNode);

// This is a valid code path for React hooks if we are direcly in a React
// functional component or we are in a hook function.
// function component or we are in a hook function.
var isSomewhereInsideComponentOrHook = isInsideComponentOrHook(codePathNode);

@@ -531,3 +542,6 @@ var isDirectlyInsideComponentOrHook = codePathFunctionName ? isComponentName(codePathFunctionName) || isHook(codePathFunctionName) : false;

if (cycled) {
context.report(hook, 'React Hook "' + context.getSource(hook) + '" may be executed ' + 'more than once. Possibly because it is called in a loop. ' + 'React Hooks must be called in the exact same order in ' + 'every component render.');
context.report({
node: hook,
message: 'React Hook "' + context.getSource(hook) + '" may be executed ' + 'more than once. Possibly because it is called in a loop. ' + 'React Hooks must be called in the exact same order in ' + 'every component render.'
});
}

@@ -546,3 +560,4 @@

if (!cycled && pathsFromStartToEnd !== allPathsFromStartToEnd) {
context.report(hook, 'React Hook "' + context.getSource(hook) + '" is called ' + 'conditionally. React Hooks must be called in the exact ' + 'same order in every component render.' + (possiblyHasEarlyReturn ? ' Did you accidentally call a React Hook after an' + ' early return?' : ''));
var message = 'React Hook "' + context.getSource(hook) + '" is called ' + 'conditionally. React Hooks must be called in the exact ' + 'same order in every component render.' + (possiblyHasEarlyReturn ? ' Did you accidentally call a React Hook after an' + ' early return?' : '');
context.report({ node: hook, message: message });
}

@@ -557,3 +572,4 @@ } else if (codePathNode.parent && (codePathNode.parent.type === 'MethodDefinition' || codePathNode.parent.type === 'ClassProperty') && codePathNode.parent.value === codePathNode) {

// Custom message if we found an invalid function name.
context.report(hook, 'React Hook "' + context.getSource(hook) + '" is called in ' + ('function "' + context.getSource(codePathFunctionName) + '" ') + 'which is neither a React function component or a custom ' + 'React Hook function.');
var _message = 'React Hook "' + context.getSource(hook) + '" is called in ' + ('function "' + context.getSource(codePathFunctionName) + '" ') + 'which is neither a React function component or a custom ' + 'React Hook function.';
context.report({ node: hook, message: _message });
} else if (codePathNode.type === 'Program') {

@@ -570,3 +586,4 @@ // For now, ignore if it's in top level scope.

if (isSomewhereInsideComponentOrHook) {
context.report(hook, 'React Hook "' + context.getSource(hook) + '" cannot be called ' + 'inside a callback. React Hooks must be called in a ' + 'React function component or a custom React Hook function.');
var _message2 = 'React Hook "' + context.getSource(hook) + '" cannot be called ' + 'inside a callback. React Hooks must be called in a ' + 'React function component or a custom React Hook function.';
context.report({ node: hook, message: _message2 });
}

@@ -573,0 +590,0 @@ }

@@ -1,2 +0,2 @@

/** @license React v16.7.0-alpha.0
/** @license React v16.6.1
* eslint-plugin-react-hooks.production.min.js

@@ -10,11 +10,11 @@ *

'use strict';function B(a){return"Identifier"===a.type?/^use[A-Z0-9].*$/.test(a.name):"MemberExpression"===a.type&&!a.computed&&B(a.property)?(a=a.object,"Identifier"===a.type&&"React"===a.name):!1}function F(a){return"Identifier"===a.type?!/^[a-z]/.test(a.name):!1}function G(a){for(;a;){var h=O(a);if(h&&(F(h)||B(h)))return!0;a=a.parent}return!1}
'use strict';function B(a){return"Identifier"===a.type?/^use[A-Z0-9].*$/.test(a.name):"MemberExpression"===a.type&&!a.computed&&B(a.property)?(a=a.object,"Identifier"===a.type&&"React"===a.name):!1}function G(a){return"Identifier"===a.type?!/^[a-z]/.test(a.name):!1}function H(a){for(;a;){var g=O(a);if(g&&(G(g)||B(g)))return!0;a=a.parent}return!1}
function O(a){if("FunctionDeclaration"===a.type||"FunctionExpression"===a.type&&a.id)return a.id;if("FunctionExpression"===a.type||"ArrowFunctionExpression"===a.type)return"VariableDeclarator"===a.parent.type&&a.parent.init===a?a.parent.id:"AssignmentExpression"===a.parent.type&&a.parent.right===a&&"="===a.parent.operator?a.parent.left:"Property"!==a.parent.type||a.parent.value!==a||a.parent.computed?"AssignmentPattern"!==a.parent.type||a.parent.right!==a||a.parent.computed?void 0:a.parent.left:a.parent.key}
module.exports={rules:{"rules-of-hooks":{create:function(a){var h=[],p=[];return{onCodePathSegmentStart:function(a){return p.push(a)},onCodePathSegmentEnd:function(){return p.pop()},onCodePathStart:function(){return h.push(new Map)},onCodePathEnd:function(g,d){function v(a){var c=v.cache,b=c.get(a.id);if(null===b){if(!w.has(a.id)){w.add(a.id);c=!0;b=!1;var k=void 0;try{for(var e=a.prevSegments[Symbol.iterator](),x;!(c=(x=e.next()).done);c=!0)v(x.value)}catch(l){b=!0,k=l}finally{try{!c&&e.return&&
e.return()}finally{if(b)throw k;}}}return 0}if(void 0!==b)return b;c.set(a.id,null);if(0===a.prevSegments.length)b=1;else{b=0;e=!0;x=!1;var d=void 0;try{k=a.prevSegments[Symbol.iterator]();for(var f;!(e=(f=k.next()).done);e=!0)b+=v(f.value)}catch(l){x=!0,d=l}finally{try{!e&&k.return&&k.return()}finally{if(x)throw d;}}}c.set(a.id,b);return b}function f(a){var c=f.cache,b=c.get(a.id);if(null===b){if(!w.has(a.id)){w.add(a.id);c=!0;b=!1;var k=void 0;try{for(var e=a.nextSegments[Symbol.iterator](),d;!(c=
(d=e.next()).done);c=!0)f(d.value)}catch(l){b=!0,k=l}finally{try{!c&&e.return&&e.return()}finally{if(b)throw k;}}}return 0}if(void 0!==b)return b;c.set(a.id,null);if(0===a.nextSegments.length)b=1;else{b=0;e=!0;d=!1;var g=void 0;try{k=a.nextSegments[Symbol.iterator]();for(var h;!(e=(h=k.next()).done);e=!0)b+=f(h.value)}catch(l){d=!0,g=l}finally{try{!e&&k.return&&k.return()}finally{if(d)throw g;}}}c.set(a.id,b);return b}function q(a){var c=q.cache,b=c.get(a.id);if(null===b)return Infinity;if(void 0!==
b)return b;c.set(a.id,null);if(0===a.prevSegments.length)b=1;else{b=Infinity;var d=!0,e=!1,f=void 0;try{for(var g=a.prevSegments[Symbol.iterator](),h;!(d=(h=g.next()).done);d=!0){var l=q(h.value);l<b&&(b=l)}}catch(P){e=!0,f=P}finally{try{!d&&g.return&&g.return()}finally{if(e)throw f;}}b+=1}c.set(a.id,b);return b}var r=h.pop();if(0!==r.size){var w=new Set;v.cache=new Map;f.cache=new Map;q.cache=new Map;var p=f(g.initialSegment),y=O(d),Q=G(d),R=y?F(y)||B(y):!1,C=Infinity,t=!0,z=!1,A=void 0;try{for(var u=
g.finalSegments[Symbol.iterator](),H;!(t=(H=u.next()).done);t=!0){var I=H.value;if(I.reachable){var J=q(I);J<C&&(C=J)}}}catch(c){z=!0,A=c}finally{try{!t&&u.return&&u.return()}finally{if(z)throw A;}}g=!0;t=!1;z=void 0;try{for(var D=r[Symbol.iterator](),K;!(g=(K=D.next()).done);g=!0){var L=K.value,n=L[0],S=L[1];if(n.reachable){var T=0===n.nextSegments.length?C<=q(n):C<q(n),U=v(n)*f(n),M=w.has(n.id);r=!0;A=!1;u=void 0;try{for(var E=S[Symbol.iterator](),N;!(r=(N=E.next()).done);r=!0){var m=N.value;M&&
a.report(m,'React Hook "'+a.getSource(m)+'" may be executed more than once. Possibly because it is called in a loop. React Hooks must be called in the exact same order in every component render.');if(R)M||U===p||a.report(m,'React Hook "'+a.getSource(m)+'" is called conditionally. React Hooks must be called in the exact same order in every component render.'+(T?" Did you accidentally call a React Hook after an early return?":""));else if(!d.parent||"MethodDefinition"!==d.parent.type&&"ClassProperty"!==
d.parent.type||d.parent.value!==d)y?a.report(m,'React Hook "'+a.getSource(m)+'" is called in '+('function "'+a.getSource(y)+'" ')+"which is neither a React function component or a custom React Hook function."):"Program"!==d.type&&Q&&a.report(m,'React Hook "'+a.getSource(m)+'" cannot be called inside a callback. React Hooks must be called in a React function component or a custom React Hook function.')}}catch(c){A=!0,u=c}finally{try{!r&&E.return&&E.return()}finally{if(A)throw u;}}}}}catch(c){t=!0,
z=c}finally{try{!g&&D.return&&D.return()}finally{if(t)throw z;}}}},CallExpression:function(a){if(B(a.callee)){var d=h[h.length-1],g=p[p.length-1],f=d.get(g);f||(f=[],d.set(g,f));f.push(a.callee)}}}}}}};
module.exports={rules:{"rules-of-hooks":{create:function(a){var g=[],q=[];return{onCodePathSegmentStart:function(a){return q.push(a)},onCodePathSegmentEnd:function(){return q.pop()},onCodePathStart:function(){return g.push(new Map)},onCodePathEnd:function(C,d){function h(a){var c=h.cache,b=c.get(a.id);if(null===b){if(!v.has(a.id)){v.add(a.id);c=!0;b=!1;var k=void 0;try{for(var e=a.prevSegments[Symbol.iterator](),w;!(c=(w=e.next()).done);c=!0)h(w.value)}catch(l){b=!0,k=l}finally{try{!c&&e.return&&
e.return()}finally{if(b)throw k;}}}return 0}if(void 0!==b)return b;c.set(a.id,null);if(C.thrownSegments.includes(a))b=0;else if(0===a.prevSegments.length)b=1;else{b=0;e=!0;w=!1;var d=void 0;try{k=a.prevSegments[Symbol.iterator]();for(var f;!(e=(f=k.next()).done);e=!0)b+=h(f.value)}catch(l){w=!0,d=l}finally{try{!e&&k.return&&k.return()}finally{if(w)throw d;}}}a.reachable&&0===b?c.delete(a.id):c.set(a.id,b);return b}function f(a){var c=f.cache,b=c.get(a.id);if(null===b){if(!v.has(a.id)){v.add(a.id);
c=!0;b=!1;var k=void 0;try{for(var e=a.nextSegments[Symbol.iterator](),d;!(c=(d=e.next()).done);c=!0)f(d.value)}catch(l){b=!0,k=l}finally{try{!c&&e.return&&e.return()}finally{if(b)throw k;}}}return 0}if(void 0!==b)return b;c.set(a.id,null);if(C.thrownSegments.includes(a))b=0;else if(0===a.nextSegments.length)b=1;else{b=0;e=!0;d=!1;var g=void 0;try{k=a.nextSegments[Symbol.iterator]();for(var h;!(e=(h=k.next()).done);e=!0)b+=f(h.value)}catch(l){d=!0,g=l}finally{try{!e&&k.return&&k.return()}finally{if(d)throw g;
}}}c.set(a.id,b);return b}function r(a){var c=r.cache,b=c.get(a.id);if(null===b)return Infinity;if(void 0!==b)return b;c.set(a.id,null);if(0===a.prevSegments.length)b=1;else{b=Infinity;var d=!0,e=!1,f=void 0;try{for(var g=a.prevSegments[Symbol.iterator](),h;!(d=(h=g.next()).done);d=!0){var l=r(h.value);l<b&&(b=l)}}catch(P){e=!0,f=P}finally{try{!d&&g.return&&g.return()}finally{if(e)throw f;}}b+=1}c.set(a.id,b);return b}var t=g.pop();if(0!==t.size){var v=new Set;h.cache=new Map;f.cache=new Map;r.cache=
new Map;var q=f(C.initialSegment),x=O(d),Q=H(d),R=x?G(x)||B(x):!1,D=Infinity,n=!0,y=!1,z=void 0;try{for(var u=C.finalSegments[Symbol.iterator](),A;!(n=(A=u.next()).done);n=!0){var I=A.value;if(I.reachable){var J=r(I);J<D&&(D=J)}}}catch(c){y=!0,z=c}finally{try{!n&&u.return&&u.return()}finally{if(y)throw z;}}n=!0;y=!1;z=void 0;try{for(var E=t[Symbol.iterator](),K;!(n=(K=E.next()).done);n=!0){var L=K.value,p=L[0],S=L[1];if(p.reachable){var T=0===p.nextSegments.length?D<=r(p):D<r(p),U=h(p)*f(p),M=v.has(p.id);
t=!0;u=!1;A=void 0;try{for(var F=S[Symbol.iterator](),N;!(t=(N=F.next()).done);t=!0){var m=N.value;M&&a.report({node:m,message:'React Hook "'+a.getSource(m)+'" may be executed more than once. Possibly because it is called in a loop. React Hooks must be called in the exact same order in every component render.'});if(R){if(!M&&U!==q){var V='React Hook "'+a.getSource(m)+'" is called conditionally. React Hooks must be called in the exact same order in every component render.'+(T?" Did you accidentally call a React Hook after an early return?":
"");a.report({node:m,message:V})}}else if(!d.parent||"MethodDefinition"!==d.parent.type&&"ClassProperty"!==d.parent.type||d.parent.value!==d)if(x){var W='React Hook "'+a.getSource(m)+'" is called in '+('function "'+a.getSource(x)+'" ')+"which is neither a React function component or a custom React Hook function.";a.report({node:m,message:W})}else if("Program"!==d.type&&Q){var X='React Hook "'+a.getSource(m)+'" cannot be called inside a callback. React Hooks must be called in a React function component or a custom React Hook function.';
a.report({node:m,message:X})}}}catch(c){u=!0,A=c}finally{try{!t&&F.return&&F.return()}finally{if(u)throw A;}}}}}catch(c){y=!0,z=c}finally{try{!n&&E.return&&E.return()}finally{if(y)throw z;}}}},CallExpression:function(a){if(B(a.callee)){var d=g[g.length-1],h=q[q.length-1],f=d.get(h);f||(f=[],d.set(h,f));f.push(a.callee)}}}}}}};
{
"name": "eslint-plugin-react-hooks",
"description": "ESLint rules for React Hooks",
"version": "0.0.0",
"repository": "facebook/react",
"version": "1.0.0",
"repository": {
"type" : "git",
"url" : "https://github.com/facebook/react.git",
"directory": "packages/eslint-plugin-react-hooks"
},
"files": [
"LICENSE",
"README.md",
"build-info.json",
"index.js",

@@ -10,0 +15,0 @@ "cjs"

@@ -5,13 +5,7 @@ # `eslint-plugin-react-hooks`

It is a part of the [Hooks proposal](https://reactjs.org/docs/hooks-intro.html) for React.
It is a part of the [Hooks API](https://reactjs.org/docs/hooks-intro.html) for React.
## Experimental Status
This is an experimental release and is intended to be used for testing the Hooks proposal with React 16.7 alpha. The exact heuristics it uses may be adjusted.
The [Rules of Hooks](https://reactjs.org/docs/hooks-rules.html) documentation contains a link to the technical RFC. Please leave a comment on the RFC if you have concerns or ideas about how this plugin should work.
## Installation
**Note: If you're using Create React App, please wait for a corresponding experimental release of `react-scripts` that includes this rule instead of adding it directly.**
**Note: If you're using Create React App, please wait for a corresponding release of `react-scripts` that includes this rule instead of adding it directly.**

@@ -22,6 +16,6 @@ Assuming you already have ESLint installed, run:

# npm
npm install eslint-plugin-react-hooks@next --save-dev
npm install eslint-plugin-react-hooks --save-dev
# yarn
yarn add eslint-plugin-react-hooks@next --dev
yarn add eslint-plugin-react-hooks --dev
```

@@ -28,0 +22,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc