-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Add eslint rule for preventing string literals in select/dispatch/useDispatch #28726
Conversation
Size Change: -12 B (0%) Total Size: 1.37 MB
ℹ️ View Unchanged
|
080ac2d
to
fd5f95f
Compare
Let's downgrade those new rules to warning level and land immediately to simplify the process for remaining hardcoded store references. |
1f4a643
to
ca1cea1
Compare
Found one false report. We use import { text, select } from '@storybook/addon-knobs'; |
Yes, I see this being an issue in more places. It should match the following:
Plus something you listed related to the registry maybe, definitely less common. I don't mind we start small and expand later. It probably should always remind off in the recommended WordPress ESLint config since it's totally fine to reference a store as a string in a small plugin. We should also document this rule and add tests (which is quite simple with the rule tester). Let me know how would you like to split work so I could help you land this PR. |
I'm looking into how to make this more accurate.
If you could take care of documenting and testing that would be great! |
The rule seems to work! Added tests as well. |
packages/eslint-plugin/rules/__tests__/no-store-string-literals.js
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added missing documentation and left two minor comments. In general, this PR is ready to land. It just needs to be aligned in regards to the rule name. You can pick whatever works best for you but make sure you update docs accordingly.
Thank you for working on this rule. It's going to be super helpful ❤️
All the issues reported by CI seem to be unrelated 🤷🏻♂️ |
Description
Follow-up for #26655.
Add warning for these function calls:
select
,dispatch
,useDispatch
,withDispatch
,withSelect
,createRegistrySelector
,controls.select
,controls.dispatch
, andcontrols.resolveSelect
if the first argument is a literal.Examples that will show a warning:
How has this been tested?
npm run lint-js
select
,dispatch
,useDispatch
,withDispatch
,withSelect
,createRegistrySelector
,controls.select
,controls.dispatch
, andcontrols.resolveSelect
.Types of changes
Code quality
Checklist: