eslint-plugin-no-window-func
v1.1.0
Published
ESLint plugin to disallow variable names that conflict with global window functions.
Maintainers
Readme
eslint-plugin-no-window-func
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.
Installation
You can install the plugin using npm:
npm install eslint-plugin-no-window-func --save-devUsage
To use this plugin, add it to your ESLint configuration file (.eslintrc.js, .eslintrc.json, etc.).
Example .eslintrc.js Configuration
module.exports = {
"plugins": [
"no-window-func"
],
"rules": {
"no-window-func/no-window-func": "error"
}
};Example Code
/* eslint no-window-func/no-window-func: "error" */
const alert = "test"; // This will cause an ESLint error
const myVar = "test"; // This is fineRule Details
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
- prompt
- queueMicrotask
- releaseEvents
- reportError
- requestAnimationFrame
- requestIdleCallback
- resizeBy
- resizeTo
- scroll
- scrollBy
- scrollTo
- setInterval
- setTimeout
- stop
Contributing
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.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgements
Inspired by the need to maintain clean and conflict-free JavaScript code by preventing the use of window object method names as variable names.
