A custom ESLint plugin that enforces consistent naming for useState boolean variables in React.
It ensures that variables initialized with a boolean value follow a readable and conventional pattern like:
✅ const [isOpen, setIsOpen] = useState(false)
✅ const [hasAccess, setHasAccess] = useState(true)
❌ const [open, setOpen] = useState(false)
❌ const [foo, setFoo] = useState(true)
This plugin helps teams write more expressive, readable code by enforcing a rule for common boolean prefixes such as:
is(e.g.,isVisible)has(e.g.,hasPermission)can(e.g.,canSubmit)should,was,will, and more.
- ✅ Checks that
useState<boolean>variables use appropriate prefixes. - ✅ Ensures that the corresponding setter name matches the variable (e.g.,
setIsVisibleforisVisible). - 🔧 Comes with a recommended config for aesy setup.
- 🧠 Helps prevent ambiguous or misleading variable names in React components.
npm install --save-dev eslint-plugin-boolean-stateEnable the plugin in your ESLint config:
// .eslintrc.js
module.exports = {
plugins: ['boolean-state'],
extends: ['plugin:boolean-state/recommended'],
};If you want to develop or test this plugin locally before publishing to npm, use npm link.
From the plugin’s root folder:
npm linkIn your test project or app:
npm link eslint-plugin-boolean-stateIn the consumer project:
npm unlink eslint-plugin-boolean-stateIn the plugin folder (to remove the global link):
npm unlink -gnpm install eslint-plugin-boolean-statenpm version patch/...
npm publish