Giter Site home page Giter Site logo

eslint-plugin-hooks's Introduction

eslint-plugin-hooks's People

Contributors

hiukky avatar thebarda avatar zanechua avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

eslint-plugin-hooks's Issues

TypeError: Cannot read properties of null (reading 'callee')

'hooks/sort': [
      'error',
      {
        'groups': [
          'useReducer',
          'useState',
          'useContext',
          'useRef',
          'useDispatch',
          'useEffect',
          'useCallback'
        ]
      }
    ],
Oops! Something went wrong! :(

ESLint: 8.5.0

TypeError: Cannot read properties of null (reading 'callee')
Occurred while linting /Users/michael/Documents/app-frontend/src/modules/decisions/components/OpportunitiesContainer/tables/CommissionGrowthTable.tsx:1
Rule: "hooks/sort"
    at /Users/michael/Documents/app-frontend/node_modules/eslint-plugin-hooks/dist/rules/sort/index.js:109:59
    at Array.map (<anonymous>)
    at /Users/michael/Documents/app-frontend/node_modules/eslint-plugin-hooks/dist/rules/sort/index.js:97:72
    at Array.forEach (<anonymous>)
    at Program (/Users/michael/Documents/app-frontend/node_modules/eslint-plugin-hooks/dist/rules/sort/index.js:79:22)
    at ruleErrorHandler (/Users/michael/Documents/app-frontend/node_modules/eslint/lib/linter/linter.js:1076:28)
    at /Users/michael/Documents/app-frontend/node_modules/eslint/lib/linter/safe-emitter.js:45:58
    at Array.forEach (<anonymous>)
    at Object.emit (/Users/michael/Documents/app-frontend/node_modules/eslint/lib/linter/safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector (/Users/michael/Documents/app-frontend/node_modules/eslint/lib/linter/node-event-generator.js:297:26)
error Command failed with exit code 2.

Problem with the last release 0.3.0: Cannot read property 'declarations' of null

I got the last version 0.3.0, but, I have a new several problem... ESLint does not work

TypeError: Cannot read property 'declarations' of null
Occurred while linting {FILES}
    at {PATH}/node_modules/eslint-plugin-hooks/dist/rules/sort/index.js:70:55
    at Array.map (<anonymous>)
    at Program ({PATH}/node_modules/eslint-plugin-hooks/dist/rules/sort/index.js:62:22)

Do you have a idea ?
Thanks

allow certain hooks to be used in before or after certain other hooks, but not at any place

For my program I have made the distinction between hooks that provide state (like useState), that consume state (like useEffect) and ones that do both (useCallback or useMemo).

For the first and second group the order can be static, but for the third one I could need to call useCallback before useMemo or vice versa. Because they can use each other as dependencies:

const memoized = useMemo(() => (/* ... */), []);
const callback = useCallback(() => (/* ... */), [memoized]);
// vs
const callback = useCallback(() => (/* ... */), []);
const memoized = useMemo(() => (/* ... */), [callback]);

For these two hooks it may seem a little constructed, but for other (custom) hooks this will be important.

I would wish I could specify an array inside the groups config so I can order these specific functions as I like, but not at any place in the file. The config could look like this:

'hooks/sort': [2, {
  groups: [
    'useState',
    ['useMemo', 'useCallback'],
    'useEffect'
  ]
];

Multi-component files do not scope order correctly

With the following config:

hooks/sort: ["warn", {
  groups: ["useState", "useNetinfo"]
}]

A file given multiple components:

const Icon = () => {
  // offending line because in the file this hook is used before useState
  const { internetReachable } = useNetInfo();
  return internetReachable ? <Image /> : <Spinner />;
}

const Container = () => {
  const [loading, setLoading] = useState(true);
  const { internetReachable } = useNetInfo();

  useEffect(() => {
    setLoading(internetReachable);
  }, [internetReachable]);
}

Seems the rules are not scoped to the component itself, but rather the whole file.

Support siblings

We need support of siblings hooks, that can be in any order to each other

'hooks-sort/order-hooks': [
      2,
      {
        groups: [
          ['useNavigation', 'useLanguage', 'useTranslation'],
          'useRef',
          ['useIsKeyboardShown', 'useWindowDimensions'],
          'useForm',
          'useState',
          ['useQuery', 'useLazyQuery', 'useMutation'],
          'useToggle',
          ['useCallback', 'useMemo'],
          'useEffect',
        ],
      },
    ],

Like it did in import/order

'import/order': [
      'error',
      {
        groups: ['external', 'internal', 'builtin', ['sibling', 'parent'], 'index'],
        'newlines-between': 'always',
      },
    ],

Enable support for the React prefix on hooks

Hello,

I would like to know if you are working on the possibility to take into account the hooks called by React.{hook}?

Because when we import React like this :
import * as React from 'react';

the useState() doesn't sort correctly, because it is called like this :
React.useState()

I have the feeling that this is not taken into account in the sorting.

Or should it be declared in the configuration like this:

    'hooks/sort': [
      2,
      {
        groups: [
          useState', ==> 'React.useState
          'useRequest',
          useCallback',
          useEffect',
        ],
      },
    ],

Thanks,

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.