Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: hook-use-state is not doing what the documentation says it does #3872

Open
2 tasks done
ericmorand-sonarsource opened this issue Jan 6, 2025 · 1 comment
Open
2 tasks done

Comments

@ericmorand-sonarsource
Copy link

ericmorand-sonarsource commented Jan 6, 2025

Is there an existing issue for this?

  • I have searched the existing issues and my issue is unique
  • My issue appears in the command-line and not only in the text editor

Description Overview

hook-use-state documentation says that the rule checks whether the value and setter variables destructured from a React.useState() call are named symmetrically.

It does not say that the rule checks whether the result of a react.useState class is destructured.

Either the description is wrong, or the implementation is wrong.

Expected Behavior

If the rule is actually checking whether the value and setter variables destructured from a React.useState() call are named symmetrically, then the following code sample should be correct.

import React from 'react';
export default function useColor() {
  // useState call is not destructured into value + setter pair
  const useStateResult = React.useState();
  return useStateResult;
}

If it is not, then, the description must be updated to:

This rule checks whether the return value of a React.useState() call is destructured, and the value and setter variables are named symmetrically.

eslint-plugin-react version

every

eslint version

v9

node version

v20

@ljharb
Copy link
Member

ljharb commented Jan 6, 2025

I'm not sure how it could validate the names without it also being destructured, so i think the docs are correct as-is, but your suggested change certainly is more explicit. Feel free to submit a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants