ESLint plugin to disallow variable names that conflict with global window functions.
npm install eslint-plugin-no-window-funcAn ESLint plugin that disallows variable declarations using the names of methods on the window object. This helps prevent potential conflicts and unexpected behaviors in your JavaScript code.
You can install the plugin using npm:
``bash`
npm install eslint-plugin-no-window-func --save-dev
To use this plugin, add it to your ESLint configuration file (.eslintrc.js, .eslintrc.json, etc.).
`javascript`
module.exports = {
"plugins": [
"no-window-func"
],
"rules": {
"no-window-func/no-window-func": "error"
}
};$3
`javascript`
/ eslint no-window-func/no-window-func: "error" /
const alert = "test"; // This will cause an ESLint error
const myVar = "test"; // This is fine
This rule disallows variable names that match any of the methods on the window object. The following is a list of disallowed names:
- alert
- atob
- blur
- btoa
- cancelAnimationFrame
- cancelIdleCallback
- captureEvents
- clearInterval
- clearTimeout
- close
- confirm
- createImageBitmap
- fetch
- focus
- getComputedStyle
- getSelection
- matchMedia
- moveBy
- moveTo
- open
- postMessage
- print
- prompt
- queueMicrotask
- releaseEvents
- reportError
- requestAnimationFrame
- requestIdleCallback
- resizeBy
- resizeTo
- scroll
- scrollBy
- scrollTo
- setInterval
- setTimeout
- stop
Contributions are welcome! Please follow these steps to contribute:
1. Fork the repository.
2. Create a new branch (git checkout -b my-new-feature).git commit -am 'Add some feature'
3. Commit your changes ().git push origin my-new-feature
4. Push to the branch ().
5. Create a new Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
Inspired by the need to maintain clean and conflict-free JavaScript code by preventing the use of window` object method names as variable names.