|
Last change
on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago |
|
Fix frontend appearance
|
-
Property mode
set to
100644
|
|
File size:
1.2 KB
|
| Rev | Line | |
|---|
| [9af201e] | 1 | # confusing-browser-globals
|
|---|
| 2 |
|
|---|
| 3 | A curated list of browser globals that commonly cause confusion and are not recommended to use without an explicit `window.` qualifier.
|
|---|
| 4 |
|
|---|
| 5 | ## Motivation
|
|---|
| 6 |
|
|---|
| 7 | Some global variables in browser are likely to be used by people without the intent of using them as globals, such as `status`, `name`, `event`, etc.
|
|---|
| 8 |
|
|---|
| 9 | For example:
|
|---|
| 10 |
|
|---|
| 11 | ```js
|
|---|
| 12 | handleClick() { // missing `event` argument
|
|---|
| 13 | this.setState({
|
|---|
| 14 | text: event.target.value // uses the `event` global: oops!
|
|---|
| 15 | });
|
|---|
| 16 | }
|
|---|
| 17 | ```
|
|---|
| 18 |
|
|---|
| 19 | This package exports a list of globals that are often used by mistake. You can feed this list to a static analysis tool like ESLint to prevent their usage without an explicit `window.` qualifier.
|
|---|
| 20 |
|
|---|
| 21 | ## Installation
|
|---|
| 22 |
|
|---|
| 23 | ```sh
|
|---|
| 24 | npm install --save confusing-browser-globals
|
|---|
| 25 | ```
|
|---|
| 26 |
|
|---|
| 27 | ## Usage
|
|---|
| 28 |
|
|---|
| 29 | If you use Create React App, you don't need to configure anything, as this rule is already included in the default `eslint-config-react-app` preset.
|
|---|
| 30 |
|
|---|
| 31 | If you maintain your own ESLint configuration, you can do this:
|
|---|
| 32 |
|
|---|
| 33 | ```js
|
|---|
| 34 | const restrictedGlobals = require('confusing-browser-globals');
|
|---|
| 35 |
|
|---|
| 36 | module.exports = {
|
|---|
| 37 | rules: {
|
|---|
| 38 | 'no-restricted-globals': ['error'].concat(restrictedGlobals),
|
|---|
| 39 | },
|
|---|
| 40 | };
|
|---|
| 41 | ```
|
|---|
| 42 |
|
|---|
| 43 | ## License
|
|---|
| 44 |
|
|---|
| 45 | MIT
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.