An 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:
npm install eslint-plugin-no-window-func --save-devTo use this plugin, add it to your ESLint configuration file (.eslintrc.js, .eslintrc.json, etc.).
module.exports = {
"plugins": [
"no-window-func"
],
"rules": {
"no-window-func/no-window-func": "error"
}
};/* eslint no-window-func/no-window-func: "error" */
const alert = "test"; // This will cause an ESLint error
const myVar = "test"; // This is fineThis 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
- prompt
- queueMicrotask
- releaseEvents
- reportError
- requestAnimationFrame
- requestIdleCallback
- resizeBy
- resizeTo
- scroll
- scrollBy
- scrollTo
- setInterval
- setTimeout
- stop
Contributions are welcome! Please follow these steps to contribute:
- Fork the repository.
- Create a new branch (
git checkout -b my-new-feature). - Commit your changes (
git commit -am 'Add some feature'). - Push to the branch (
git push origin my-new-feature). - 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.