New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

hooks-checker

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hooks-checker

check whether react hooks such as useEffect missing second argument

  • 0.0.2
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
2
decreased by-33.33%
Maintainers
1
Weekly downloads
 
Created
Source

hooks-checker

现如今 react hooks 的使用已经非常普遍,但在使用过程中还是时常会犯一些低级错误。

就比如在使用 useEffect 的时候未传第二个 dependency 参数,从而造成意想不到的结果(排查半天最后才发现是这个疏忽而导致的)。本工具就是用来检查 useEffect, useLayoutEffect, useMemouseCallback 在使用的时候是否传了第二个参数。

安装

$ npm install hooks-checker

使用

demo

const Checker = require('hooks-checker');

const code = `
  import { useEffect } from 'react';
  const Foo = () => {
    useEffect(() => {});
    return null;
  };
  export default Foo;
`;

const main = () => {
  const checker = new Checker({ code });
  const dangers = checker.check();
  // warn or error with dangers by yourself
};

main();

output of dangers

[
  {
    "line": 4,
    "column": 4,
    "message": "The second argument is not found in useEffect call.",
  }
]

Checker 参数选项

字段类型是否必须默认值描述
codestring''待检查的代码
astt.Filenull待检查代码对应的 ast
libsstring[]['react']引入 hooks 的包,也可以是 rax

注意:codeast 不能同时为空。

License

MIT License

FAQs

Package last updated on 20 Feb 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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