Skip to content

[docs] Improve the error message of naming-convention/use-state #980

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

Closed
bhollis opened this issue Mar 10, 2025 · 5 comments
Closed

[docs] Improve the error message of naming-convention/use-state #980

bhollis opened this issue Mar 10, 2025 · 5 comments
Labels
Type: Documentation Improvements or additions to documentation Type: Enhancement Enhancements to existing features

Comments

@bhollis
Copy link

bhollis commented Mar 10, 2025

Describe the bug

const [{ result, processing }, setState] = useState<ProcessState>({
  processing: false,
  resultStoreId: selectedStore.id,
  result: null,
});

This triggers "An useState call is not destructured into value + setter pair @eslint-react/naming-convention/use-state" but it shouldn't.

Reproduction

const [{ result, processing }, setState] = useState<ProcessState>({
  processing: false,
  resultStoreId: selectedStore.id,
  result: null,
});

Expected behavior

No error.

Platform and versions

Node v23.5.0
ESLint 9.19.0
@eslint-react/react-plugin 1.31.0

Stack trace


Additional context

No response

@bhollis
Copy link
Author

bhollis commented Mar 10, 2025

I also get a warning for this code:

const [liveQueryLive, setLiveQuery] = useState(searchQuery ?? '');

@bhollis
Copy link
Author

bhollis commented Mar 10, 2025

And this one:

const [options, setOptionsState] = useState<ItemPickerState>();

@Rel1cx
Copy link
Owner

Rel1cx commented Mar 11, 2025

The rule in the issue title should be use-state, not no-use-context.

@Rel1cx
Copy link
Owner

Rel1cx commented Mar 11, 2025

The main purpose of this rule is to enforce symmetric naming between state and setState. The code in the example above doesn't have a false positive, but the error message here has room for improvement. The current message might mislead users into thinking they're not using destructuring assignment.

@Rel1cx Rel1cx changed the title [bug] False positive from @eslint-react/no-use-context when destructuring results [docs] Improve the error message of naming-convention/use-state Mar 11, 2025
@Rel1cx Rel1cx added Type: Documentation Improvements or additions to documentation Type: Enhancement Enhancements to existing features labels Mar 11, 2025
@jonesmac
Copy link

I'm not sure if this is the same issue @Rel1cx but I have code that also gets flagged that seems like it might be similar. I have a custom hook called useAsyncEffect and this rule seems to flag it similarly.

useAsyncEffect(
    async () => {
...
    },
    [mod],
  )

gets flagged with warning An useState call is not destructured into value + setter pair. @eslint-react/naming-convention/use-state

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Documentation Improvements or additions to documentation Type: Enhancement Enhancements to existing features
Projects
None yet
Development

No branches or pull requests

3 participants