From fb3a4162093d0082bddfaa92f1e3f6394b9019b6 Mon Sep 17 00:00:00 2001 From: Siddharth Doshi Date: Sat, 20 May 2017 17:09:25 +0530 Subject: [PATCH 01/10] Add restricted globals package --- packages/eslint-restricted-globals/.gitignore | 1 + packages/eslint-restricted-globals/README.md | 44 +++++ packages/eslint-restricted-globals/index.js | 60 ++++++ .../eslint-restricted-globals/package.json | 21 ++ packages/eslint-restricted-globals/test.js | 6 + packages/eslint-restricted-globals/yarn.lock | 187 ++++++++++++++++++ 6 files changed, 319 insertions(+) create mode 100644 packages/eslint-restricted-globals/.gitignore create mode 100644 packages/eslint-restricted-globals/README.md create mode 100644 packages/eslint-restricted-globals/index.js create mode 100644 packages/eslint-restricted-globals/package.json create mode 100644 packages/eslint-restricted-globals/test.js create mode 100644 packages/eslint-restricted-globals/yarn.lock diff --git a/packages/eslint-restricted-globals/.gitignore b/packages/eslint-restricted-globals/.gitignore new file mode 100644 index 00000000000..b512c09d476 --- /dev/null +++ b/packages/eslint-restricted-globals/.gitignore @@ -0,0 +1 @@ +node_modules \ No newline at end of file diff --git a/packages/eslint-restricted-globals/README.md b/packages/eslint-restricted-globals/README.md new file mode 100644 index 00000000000..ab50977f379 --- /dev/null +++ b/packages/eslint-restricted-globals/README.md @@ -0,0 +1,44 @@ +# eslint-restricted-globals [![npm](https://img.shields.io/npm/v/eslint-restricted-globals.svg?style=plastic)](https://www.npmjs.com/package/eslint-restricted-globals) [![npm](https://img.shields.io/npm/l/eslint-restricted-globals.svg?style=plastic)](https://www.npmjs.com/package/eslint-restricted-globals) + +> A list of confusing globals that should be restricted to be used as globals + +## Install + +``` +$ npm install --save eslint-restricted-globals +``` + +Some global variables in browser are likely to be used by people without the intent of using them as globals, such as `status`, `name` etc. +And because eslint thinks of them as valid global variables, it does not warn in case of bugs. + +For eg: +```js +function foo(nama) { + if (nama) { + console.log(name) + } +} +``` + +Here we try to log variable `nama` if it is truthy, but by mistake we are logging `name` and as `name` is a valid global, no eslint warning is shown. + +To avoid this, we blacklist such confusing globals which are exported from this package. It contains the list of variables that we think should not be used without `window.` qualifier. But as this is just a javascript array you can add, remove variables or even make your own list of variables. + +## Usage + +Add this in your eslint config in rules property: + +```js +var restrictedGlobals = require('eslint-restricted-globals') + +module.exports = { + rules: { + 'no-restricted-globals': ['error'].concat(restrictedGlobals), + } +} +``` + + +## License + +MIT \ No newline at end of file diff --git a/packages/eslint-restricted-globals/index.js b/packages/eslint-restricted-globals/index.js new file mode 100644 index 00000000000..5ad338bddb6 --- /dev/null +++ b/packages/eslint-restricted-globals/index.js @@ -0,0 +1,60 @@ +module.exports = [ + 'addEventListener', + 'blur', + 'close', + 'closed', + 'confirm', + 'defaultStatus', + 'event', + 'external', + 'defaultstatus', + 'find', + 'focus', + 'frameElement', + 'frames', + 'history', + 'innerHeight', + 'innerWidth', + 'length', + 'location', + 'locationbar', + 'menubar', + 'moveBy', + 'moveTo', + 'name', + 'onblur', + 'onerror', + 'onfocus', + 'onload', + 'onresize', + 'onunload', + 'open', + 'opener', + 'opera', + 'outerHeight', + 'outerWidth', + 'pageXOffset', + 'pageYOffset', + 'parent', + 'print', + 'removeEventListener', + 'resizeBy', + 'resizeTo', + 'screen', + 'screenLeft', + 'screenTop', + 'screenX', + 'screenY', + 'scroll', + 'scrollbars', + 'scrollBy', + 'scrollTo', + 'scrollX', + 'scrollY', + 'self', + 'status', + 'statusbar', + 'stop', + 'toolbar', + 'top', +]; diff --git a/packages/eslint-restricted-globals/package.json b/packages/eslint-restricted-globals/package.json new file mode 100644 index 00000000000..c58ac573dbf --- /dev/null +++ b/packages/eslint-restricted-globals/package.json @@ -0,0 +1,21 @@ +{ + "name": "eslint-restricted-globals", + "version": "0.1.1", + "description": "A list of confusing globals that should be restricted to be used as globals", + "main": "index.js", + "scripts": { + "test": "mocha" + }, + "repository": "facebookincubator/create-react-app", + "keywords": [ + "eslint", + "globals" + ], + "files": [ + "index.js" + ], + "license": "BSD-3-Clause", + "devDependencies": { + "mocha": "^3.4.1" + } +} diff --git a/packages/eslint-restricted-globals/test.js b/packages/eslint-restricted-globals/test.js new file mode 100644 index 00000000000..49d72b07b82 --- /dev/null +++ b/packages/eslint-restricted-globals/test.js @@ -0,0 +1,6 @@ +let assert = require('assert'); +let globals = require('./'); + +it('should return an Array of globals', function() { + assert.strictEqual(globals.constructor, Array); +}); diff --git a/packages/eslint-restricted-globals/yarn.lock b/packages/eslint-restricted-globals/yarn.lock new file mode 100644 index 00000000000..c9456e5295d --- /dev/null +++ b/packages/eslint-restricted-globals/yarn.lock @@ -0,0 +1,187 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +balanced-match@^0.4.1: + version "0.4.2" + resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-0.4.2.tgz#cb3f3e3c732dc0f01ee70b403f302e61d7709838" + +brace-expansion@^1.1.7: + version "1.1.7" + resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.7.tgz#3effc3c50e000531fb720eaff80f0ae8ef23cf59" + dependencies: + balanced-match "^0.4.1" + concat-map "0.0.1" + +browser-stdout@1.3.0: + version "1.3.0" + resolved "https://registry.yarnpkg.com/browser-stdout/-/browser-stdout-1.3.0.tgz#f351d32969d32fa5d7a5567154263d928ae3bd1f" + +commander@2.9.0: + version "2.9.0" + resolved "https://registry.yarnpkg.com/commander/-/commander-2.9.0.tgz#9c99094176e12240cb22d6c5146098400fe0f7d4" + dependencies: + graceful-readlink ">= 1.0.0" + +concat-map@0.0.1: + version "0.0.1" + resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b" + +debug@2.6.0: + version "2.6.0" + resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.0.tgz#bc596bcabe7617f11d9fa15361eded5608b8499b" + dependencies: + ms "0.7.2" + +diff@3.2.0: + version "3.2.0" + resolved "https://registry.yarnpkg.com/diff/-/diff-3.2.0.tgz#c9ce393a4b7cbd0b058a725c93df299027868ff9" + +escape-string-regexp@1.0.5: + version "1.0.5" + resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4" + +fs.realpath@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f" + +glob@7.1.1: + version "7.1.1" + resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.1.tgz#805211df04faaf1c63a3600306cdf5ade50b2ec8" + dependencies: + fs.realpath "^1.0.0" + inflight "^1.0.4" + inherits "2" + minimatch "^3.0.2" + once "^1.3.0" + path-is-absolute "^1.0.0" + +"graceful-readlink@>= 1.0.0": + version "1.0.1" + resolved "https://registry.yarnpkg.com/graceful-readlink/-/graceful-readlink-1.0.1.tgz#4cafad76bc62f02fa039b2f94e9a3dd3a391a725" + +growl@1.9.2: + version "1.9.2" + resolved "https://registry.yarnpkg.com/growl/-/growl-1.9.2.tgz#0ea7743715db8d8de2c5ede1775e1b45ac85c02f" + +has-flag@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-1.0.0.tgz#9d9e793165ce017a00f00418c43f942a7b1d11fa" + +inflight@^1.0.4: + version "1.0.6" + resolved "https://registry.yarnpkg.com/inflight/-/inflight-1.0.6.tgz#49bd6331d7d02d0c09bc910a1075ba8165b56df9" + dependencies: + once "^1.3.0" + wrappy "1" + +inherits@2: + version "2.0.3" + resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de" + +json3@3.3.2: + version "3.3.2" + resolved "https://registry.yarnpkg.com/json3/-/json3-3.3.2.tgz#3c0434743df93e2f5c42aee7b19bcb483575f4e1" + +lodash._baseassign@^3.0.0: + version "3.2.0" + resolved "https://registry.yarnpkg.com/lodash._baseassign/-/lodash._baseassign-3.2.0.tgz#8c38a099500f215ad09e59f1722fd0c52bfe0a4e" + dependencies: + lodash._basecopy "^3.0.0" + lodash.keys "^3.0.0" + +lodash._basecopy@^3.0.0: + version "3.0.1" + resolved "https://registry.yarnpkg.com/lodash._basecopy/-/lodash._basecopy-3.0.1.tgz#8da0e6a876cf344c0ad8a54882111dd3c5c7ca36" + +lodash._basecreate@^3.0.0: + version "3.0.3" + resolved "https://registry.yarnpkg.com/lodash._basecreate/-/lodash._basecreate-3.0.3.tgz#1bc661614daa7fc311b7d03bf16806a0213cf821" + +lodash._getnative@^3.0.0: + version "3.9.1" + resolved "https://registry.yarnpkg.com/lodash._getnative/-/lodash._getnative-3.9.1.tgz#570bc7dede46d61cdcde687d65d3eecbaa3aaff5" + +lodash._isiterateecall@^3.0.0: + version "3.0.9" + resolved "https://registry.yarnpkg.com/lodash._isiterateecall/-/lodash._isiterateecall-3.0.9.tgz#5203ad7ba425fae842460e696db9cf3e6aac057c" + +lodash.create@3.1.1: + version "3.1.1" + resolved "https://registry.yarnpkg.com/lodash.create/-/lodash.create-3.1.1.tgz#d7f2849f0dbda7e04682bb8cd72ab022461debe7" + dependencies: + lodash._baseassign "^3.0.0" + lodash._basecreate "^3.0.0" + lodash._isiterateecall "^3.0.0" + +lodash.isarguments@^3.0.0: + version "3.1.0" + resolved "https://registry.yarnpkg.com/lodash.isarguments/-/lodash.isarguments-3.1.0.tgz#2f573d85c6a24289ff00663b491c1d338ff3458a" + +lodash.isarray@^3.0.0: + version "3.0.4" + resolved "https://registry.yarnpkg.com/lodash.isarray/-/lodash.isarray-3.0.4.tgz#79e4eb88c36a8122af86f844aa9bcd851b5fbb55" + +lodash.keys@^3.0.0: + version "3.1.2" + resolved "https://registry.yarnpkg.com/lodash.keys/-/lodash.keys-3.1.2.tgz#4dbc0472b156be50a0b286855d1bd0b0c656098a" + dependencies: + lodash._getnative "^3.0.0" + lodash.isarguments "^3.0.0" + lodash.isarray "^3.0.0" + +minimatch@^3.0.2: + version "3.0.4" + resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083" + dependencies: + brace-expansion "^1.1.7" + +minimist@0.0.8: + version "0.0.8" + resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.8.tgz#857fcabfc3397d2625b8228262e86aa7a011b05d" + +mkdirp@0.5.1: + version "0.5.1" + resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.1.tgz#30057438eac6cf7f8c4767f38648d6697d75c903" + dependencies: + minimist "0.0.8" + +mocha@^3.4.1: + version "3.4.1" + resolved "https://registry.yarnpkg.com/mocha/-/mocha-3.4.1.tgz#a3802b4aa381934cacb38de70cf771621da8f9af" + dependencies: + browser-stdout "1.3.0" + commander "2.9.0" + debug "2.6.0" + diff "3.2.0" + escape-string-regexp "1.0.5" + glob "7.1.1" + growl "1.9.2" + json3 "3.3.2" + lodash.create "3.1.1" + mkdirp "0.5.1" + supports-color "3.1.2" + +ms@0.7.2: + version "0.7.2" + resolved "https://registry.yarnpkg.com/ms/-/ms-0.7.2.tgz#ae25cf2512b3885a1d95d7f037868d8431124765" + +once@^1.3.0: + version "1.4.0" + resolved "https://registry.yarnpkg.com/once/-/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1" + dependencies: + wrappy "1" + +path-is-absolute@^1.0.0: + version "1.0.1" + resolved "https://registry.yarnpkg.com/path-is-absolute/-/path-is-absolute-1.0.1.tgz#174b9268735534ffbc7ace6bf53a5a9e1b5c5f5f" + +supports-color@3.1.2: + version "3.1.2" + resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-3.1.2.tgz#72a262894d9d408b956ca05ff37b2ed8a6e2a2d5" + dependencies: + has-flag "^1.0.0" + +wrappy@1: + version "1.0.2" + resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f" From bd813b725a4a2fad63465161835d845d13e8f5e0 Mon Sep 17 00:00:00 2001 From: Siddharth Doshi Date: Sat, 20 May 2017 17:22:55 +0530 Subject: [PATCH 02/10] Use new package in eslint-config --- packages/eslint-config-react-app/index.js | 61 +---------------------- 1 file changed, 1 insertion(+), 60 deletions(-) diff --git a/packages/eslint-config-react-app/index.js b/packages/eslint-config-react-app/index.js index 2912f8ad603..42847156b4b 100644 --- a/packages/eslint-config-react-app/index.js +++ b/packages/eslint-config-react-app/index.js @@ -21,66 +21,7 @@ // This is dangerous as it hides accidentally undefined variables. // We blacklist the globals that we deem potentially confusing. // To use them, explicitly reference them, e.g. `window.name` or `window.status`. -var restrictedGlobals = [ - 'addEventListener', - 'blur', - 'close', - 'closed', - 'confirm', - 'defaultStatus', - 'defaultstatus', - 'event', - 'external', - 'find', - 'focus', - 'frameElement', - 'frames', - 'history', - 'innerHeight', - 'innerWidth', - 'length', - 'location', - 'locationbar', - 'menubar', - 'moveBy', - 'moveTo', - 'name', - 'onblur', - 'onerror', - 'onfocus', - 'onload', - 'onresize', - 'onunload', - 'open', - 'opener', - 'opera', - 'outerHeight', - 'outerWidth', - 'pageXOffset', - 'pageYOffset', - 'parent', - 'print', - 'removeEventListener', - 'resizeBy', - 'resizeTo', - 'screen', - 'screenLeft', - 'screenTop', - 'screenX', - 'screenY', - 'scroll', - 'scrollbars', - 'scrollBy', - 'scrollTo', - 'scrollX', - 'scrollY', - 'self', - 'status', - 'statusbar', - 'stop', - 'toolbar', - 'top', -]; +var restrictedGlobals = require('eslint-restricted-globals'); module.exports = { root: true, From ba89e2b071c26406a0690f283810fd7450d97160 Mon Sep 17 00:00:00 2001 From: Siddharth Doshi Date: Sat, 20 May 2017 17:33:28 +0530 Subject: [PATCH 03/10] Add eslint-restricted-globals dependency --- packages/eslint-config-react-app/package.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/eslint-config-react-app/package.json b/packages/eslint-config-react-app/package.json index 4c7172f8a82..d6c7b573512 100644 --- a/packages/eslint-config-react-app/package.json +++ b/packages/eslint-config-react-app/package.json @@ -17,5 +17,8 @@ "eslint-plugin-import": "^2.6.0", "eslint-plugin-jsx-a11y": "^6.0.2", "eslint-plugin-react": "^7.1.0" + }, + "dependencies": { + "eslint-restricted-globals": "^0.1.1" } } From 0464c488a9a0abb2a4769f9db6c28cecc190d5d0 Mon Sep 17 00:00:00 2001 From: Siddharth Doshi Date: Sat, 20 May 2017 21:20:47 +0530 Subject: [PATCH 04/10] Fixes --- .../README.md | 8 +- .../index.js | 11 ++ .../package.json | 4 +- .../test.js | 5 + packages/eslint-config-react-app/index.js | 2 +- packages/eslint-restricted-globals/.gitignore | 1 - packages/eslint-restricted-globals/yarn.lock | 187 ------------------ 7 files changed, 22 insertions(+), 196 deletions(-) rename packages/{eslint-restricted-globals => confusing-browser-globals}/README.md (85%) rename packages/{eslint-restricted-globals => confusing-browser-globals}/index.js (71%) rename packages/{eslint-restricted-globals => confusing-browser-globals}/package.json (86%) rename packages/{eslint-restricted-globals => confusing-browser-globals}/test.js (57%) delete mode 100644 packages/eslint-restricted-globals/.gitignore delete mode 100644 packages/eslint-restricted-globals/yarn.lock diff --git a/packages/eslint-restricted-globals/README.md b/packages/confusing-browser-globals/README.md similarity index 85% rename from packages/eslint-restricted-globals/README.md rename to packages/confusing-browser-globals/README.md index ab50977f379..76a82562990 100644 --- a/packages/eslint-restricted-globals/README.md +++ b/packages/confusing-browser-globals/README.md @@ -13,14 +13,12 @@ And because eslint thinks of them as valid global variables, it does not warn in For eg: ```js -function foo(nama) { - if (nama) { - console.log(name) - } +function logStats(stats) { + console.log(status) } ``` -Here we try to log variable `nama` if it is truthy, but by mistake we are logging `name` and as `name` is a valid global, no eslint warning is shown. +Here we try to log variable `stats`, but by mistake we are logging `status` and as `status` is a valid global, no eslint warning is shown. To avoid this, we blacklist such confusing globals which are exported from this package. It contains the list of variables that we think should not be used without `window.` qualifier. But as this is just a javascript array you can add, remove variables or even make your own list of variables. diff --git a/packages/eslint-restricted-globals/index.js b/packages/confusing-browser-globals/index.js similarity index 71% rename from packages/eslint-restricted-globals/index.js rename to packages/confusing-browser-globals/index.js index 5ad338bddb6..06c6c8e9c08 100644 --- a/packages/eslint-restricted-globals/index.js +++ b/packages/confusing-browser-globals/index.js @@ -1,3 +1,14 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +'use strict'; + module.exports = [ 'addEventListener', 'blur', diff --git a/packages/eslint-restricted-globals/package.json b/packages/confusing-browser-globals/package.json similarity index 86% rename from packages/eslint-restricted-globals/package.json rename to packages/confusing-browser-globals/package.json index c58ac573dbf..184e7036c3c 100644 --- a/packages/eslint-restricted-globals/package.json +++ b/packages/confusing-browser-globals/package.json @@ -1,6 +1,6 @@ { - "name": "eslint-restricted-globals", - "version": "0.1.1", + "name": "confusing-browser-globals", + "version": "1.0.0", "description": "A list of confusing globals that should be restricted to be used as globals", "main": "index.js", "scripts": { diff --git a/packages/eslint-restricted-globals/test.js b/packages/confusing-browser-globals/test.js similarity index 57% rename from packages/eslint-restricted-globals/test.js rename to packages/confusing-browser-globals/test.js index 49d72b07b82..aceb02079f1 100644 --- a/packages/eslint-restricted-globals/test.js +++ b/packages/confusing-browser-globals/test.js @@ -1,6 +1,11 @@ +'use strict'; + let assert = require('assert'); let globals = require('./'); it('should return an Array of globals', function() { assert.strictEqual(globals.constructor, Array); }); +it('should contain "event" variable', () => { + assert.strictEqual(globals.indexOf('event') >= 0, true); +}); diff --git a/packages/eslint-config-react-app/index.js b/packages/eslint-config-react-app/index.js index 42847156b4b..f029f9626bf 100644 --- a/packages/eslint-config-react-app/index.js +++ b/packages/eslint-config-react-app/index.js @@ -21,7 +21,7 @@ // This is dangerous as it hides accidentally undefined variables. // We blacklist the globals that we deem potentially confusing. // To use them, explicitly reference them, e.g. `window.name` or `window.status`. -var restrictedGlobals = require('eslint-restricted-globals'); +var restrictedGlobals = require('confusing-browser-globals'); module.exports = { root: true, diff --git a/packages/eslint-restricted-globals/.gitignore b/packages/eslint-restricted-globals/.gitignore deleted file mode 100644 index b512c09d476..00000000000 --- a/packages/eslint-restricted-globals/.gitignore +++ /dev/null @@ -1 +0,0 @@ -node_modules \ No newline at end of file diff --git a/packages/eslint-restricted-globals/yarn.lock b/packages/eslint-restricted-globals/yarn.lock deleted file mode 100644 index c9456e5295d..00000000000 --- a/packages/eslint-restricted-globals/yarn.lock +++ /dev/null @@ -1,187 +0,0 @@ -# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. -# yarn lockfile v1 - - -balanced-match@^0.4.1: - version "0.4.2" - resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-0.4.2.tgz#cb3f3e3c732dc0f01ee70b403f302e61d7709838" - -brace-expansion@^1.1.7: - version "1.1.7" - resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.7.tgz#3effc3c50e000531fb720eaff80f0ae8ef23cf59" - dependencies: - balanced-match "^0.4.1" - concat-map "0.0.1" - -browser-stdout@1.3.0: - version "1.3.0" - resolved "https://registry.yarnpkg.com/browser-stdout/-/browser-stdout-1.3.0.tgz#f351d32969d32fa5d7a5567154263d928ae3bd1f" - -commander@2.9.0: - version "2.9.0" - resolved "https://registry.yarnpkg.com/commander/-/commander-2.9.0.tgz#9c99094176e12240cb22d6c5146098400fe0f7d4" - dependencies: - graceful-readlink ">= 1.0.0" - -concat-map@0.0.1: - version "0.0.1" - resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b" - -debug@2.6.0: - version "2.6.0" - resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.0.tgz#bc596bcabe7617f11d9fa15361eded5608b8499b" - dependencies: - ms "0.7.2" - -diff@3.2.0: - version "3.2.0" - resolved "https://registry.yarnpkg.com/diff/-/diff-3.2.0.tgz#c9ce393a4b7cbd0b058a725c93df299027868ff9" - -escape-string-regexp@1.0.5: - version "1.0.5" - resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4" - -fs.realpath@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f" - -glob@7.1.1: - version "7.1.1" - resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.1.tgz#805211df04faaf1c63a3600306cdf5ade50b2ec8" - dependencies: - fs.realpath "^1.0.0" - inflight "^1.0.4" - inherits "2" - minimatch "^3.0.2" - once "^1.3.0" - path-is-absolute "^1.0.0" - -"graceful-readlink@>= 1.0.0": - version "1.0.1" - resolved "https://registry.yarnpkg.com/graceful-readlink/-/graceful-readlink-1.0.1.tgz#4cafad76bc62f02fa039b2f94e9a3dd3a391a725" - -growl@1.9.2: - version "1.9.2" - resolved "https://registry.yarnpkg.com/growl/-/growl-1.9.2.tgz#0ea7743715db8d8de2c5ede1775e1b45ac85c02f" - -has-flag@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-1.0.0.tgz#9d9e793165ce017a00f00418c43f942a7b1d11fa" - -inflight@^1.0.4: - version "1.0.6" - resolved "https://registry.yarnpkg.com/inflight/-/inflight-1.0.6.tgz#49bd6331d7d02d0c09bc910a1075ba8165b56df9" - dependencies: - once "^1.3.0" - wrappy "1" - -inherits@2: - version "2.0.3" - resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de" - -json3@3.3.2: - version "3.3.2" - resolved "https://registry.yarnpkg.com/json3/-/json3-3.3.2.tgz#3c0434743df93e2f5c42aee7b19bcb483575f4e1" - -lodash._baseassign@^3.0.0: - version "3.2.0" - resolved "https://registry.yarnpkg.com/lodash._baseassign/-/lodash._baseassign-3.2.0.tgz#8c38a099500f215ad09e59f1722fd0c52bfe0a4e" - dependencies: - lodash._basecopy "^3.0.0" - lodash.keys "^3.0.0" - -lodash._basecopy@^3.0.0: - version "3.0.1" - resolved "https://registry.yarnpkg.com/lodash._basecopy/-/lodash._basecopy-3.0.1.tgz#8da0e6a876cf344c0ad8a54882111dd3c5c7ca36" - -lodash._basecreate@^3.0.0: - version "3.0.3" - resolved "https://registry.yarnpkg.com/lodash._basecreate/-/lodash._basecreate-3.0.3.tgz#1bc661614daa7fc311b7d03bf16806a0213cf821" - -lodash._getnative@^3.0.0: - version "3.9.1" - resolved "https://registry.yarnpkg.com/lodash._getnative/-/lodash._getnative-3.9.1.tgz#570bc7dede46d61cdcde687d65d3eecbaa3aaff5" - -lodash._isiterateecall@^3.0.0: - version "3.0.9" - resolved "https://registry.yarnpkg.com/lodash._isiterateecall/-/lodash._isiterateecall-3.0.9.tgz#5203ad7ba425fae842460e696db9cf3e6aac057c" - -lodash.create@3.1.1: - version "3.1.1" - resolved "https://registry.yarnpkg.com/lodash.create/-/lodash.create-3.1.1.tgz#d7f2849f0dbda7e04682bb8cd72ab022461debe7" - dependencies: - lodash._baseassign "^3.0.0" - lodash._basecreate "^3.0.0" - lodash._isiterateecall "^3.0.0" - -lodash.isarguments@^3.0.0: - version "3.1.0" - resolved "https://registry.yarnpkg.com/lodash.isarguments/-/lodash.isarguments-3.1.0.tgz#2f573d85c6a24289ff00663b491c1d338ff3458a" - -lodash.isarray@^3.0.0: - version "3.0.4" - resolved "https://registry.yarnpkg.com/lodash.isarray/-/lodash.isarray-3.0.4.tgz#79e4eb88c36a8122af86f844aa9bcd851b5fbb55" - -lodash.keys@^3.0.0: - version "3.1.2" - resolved "https://registry.yarnpkg.com/lodash.keys/-/lodash.keys-3.1.2.tgz#4dbc0472b156be50a0b286855d1bd0b0c656098a" - dependencies: - lodash._getnative "^3.0.0" - lodash.isarguments "^3.0.0" - lodash.isarray "^3.0.0" - -minimatch@^3.0.2: - version "3.0.4" - resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083" - dependencies: - brace-expansion "^1.1.7" - -minimist@0.0.8: - version "0.0.8" - resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.8.tgz#857fcabfc3397d2625b8228262e86aa7a011b05d" - -mkdirp@0.5.1: - version "0.5.1" - resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.1.tgz#30057438eac6cf7f8c4767f38648d6697d75c903" - dependencies: - minimist "0.0.8" - -mocha@^3.4.1: - version "3.4.1" - resolved "https://registry.yarnpkg.com/mocha/-/mocha-3.4.1.tgz#a3802b4aa381934cacb38de70cf771621da8f9af" - dependencies: - browser-stdout "1.3.0" - commander "2.9.0" - debug "2.6.0" - diff "3.2.0" - escape-string-regexp "1.0.5" - glob "7.1.1" - growl "1.9.2" - json3 "3.3.2" - lodash.create "3.1.1" - mkdirp "0.5.1" - supports-color "3.1.2" - -ms@0.7.2: - version "0.7.2" - resolved "https://registry.yarnpkg.com/ms/-/ms-0.7.2.tgz#ae25cf2512b3885a1d95d7f037868d8431124765" - -once@^1.3.0: - version "1.4.0" - resolved "https://registry.yarnpkg.com/once/-/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1" - dependencies: - wrappy "1" - -path-is-absolute@^1.0.0: - version "1.0.1" - resolved "https://registry.yarnpkg.com/path-is-absolute/-/path-is-absolute-1.0.1.tgz#174b9268735534ffbc7ace6bf53a5a9e1b5c5f5f" - -supports-color@3.1.2: - version "3.1.2" - resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-3.1.2.tgz#72a262894d9d408b956ca05ff37b2ed8a6e2a2d5" - dependencies: - has-flag "^1.0.0" - -wrappy@1: - version "1.0.2" - resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f" From 6619ef06c8b6382da9c7870b27aafa608c24449b Mon Sep 17 00:00:00 2001 From: Siddharth Doshi Date: Sat, 20 May 2017 21:36:11 +0530 Subject: [PATCH 05/10] Update dependencies --- packages/eslint-config-react-app/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/eslint-config-react-app/package.json b/packages/eslint-config-react-app/package.json index d6c7b573512..806b05b29a7 100644 --- a/packages/eslint-config-react-app/package.json +++ b/packages/eslint-config-react-app/package.json @@ -19,6 +19,6 @@ "eslint-plugin-react": "^7.1.0" }, "dependencies": { - "eslint-restricted-globals": "^0.1.1" + "confusing-browser-globals": "^1.0.0" } } From 39302124cf7cdd5b927aee654c81cdb29adcc70f Mon Sep 17 00:00:00 2001 From: Siddharth Doshi Date: Sun, 21 May 2017 00:26:55 +0530 Subject: [PATCH 06/10] Update test and README --- packages/confusing-browser-globals/README.md | 16 ++++++++-------- packages/confusing-browser-globals/test.js | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/confusing-browser-globals/README.md b/packages/confusing-browser-globals/README.md index 76a82562990..acbc41e0066 100644 --- a/packages/confusing-browser-globals/README.md +++ b/packages/confusing-browser-globals/README.md @@ -1,11 +1,11 @@ -# eslint-restricted-globals [![npm](https://img.shields.io/npm/v/eslint-restricted-globals.svg?style=plastic)](https://www.npmjs.com/package/eslint-restricted-globals) [![npm](https://img.shields.io/npm/l/eslint-restricted-globals.svg?style=plastic)](https://www.npmjs.com/package/eslint-restricted-globals) +# eslint-restricted-globals > A list of confusing globals that should be restricted to be used as globals ## Install ``` -$ npm install --save eslint-restricted-globals +$ npm install --save confusing-browser-globals ``` Some global variables in browser are likely to be used by people without the intent of using them as globals, such as `status`, `name` etc. @@ -14,7 +14,7 @@ And because eslint thinks of them as valid global variables, it does not warn in For eg: ```js function logStats(stats) { - console.log(status) + console.log(status); } ``` @@ -27,13 +27,13 @@ To avoid this, we blacklist such confusing globals which are exported from this Add this in your eslint config in rules property: ```js -var restrictedGlobals = require('eslint-restricted-globals') +var restrictedGlobals = require('eslint-restricted-globals'); module.exports = { - rules: { - 'no-restricted-globals': ['error'].concat(restrictedGlobals), - } -} + rules: { + 'no-restricted-globals': ['error'].concat(restrictedGlobals), + } +}; ``` diff --git a/packages/confusing-browser-globals/test.js b/packages/confusing-browser-globals/test.js index aceb02079f1..74513d76b11 100644 --- a/packages/confusing-browser-globals/test.js +++ b/packages/confusing-browser-globals/test.js @@ -4,7 +4,7 @@ let assert = require('assert'); let globals = require('./'); it('should return an Array of globals', function() { - assert.strictEqual(globals.constructor, Array); + assert.strictEqual(Array.isArray(globals), true); }); it('should contain "event" variable', () => { assert.strictEqual(globals.indexOf('event') >= 0, true); From 6974150001068020e2397484eee31737a95639d8 Mon Sep 17 00:00:00 2001 From: Siddharth Doshi Date: Sun, 21 May 2017 00:49:17 +0530 Subject: [PATCH 07/10] Use jest --- packages/confusing-browser-globals/README.md | 2 +- packages/confusing-browser-globals/package.json | 4 ++-- packages/confusing-browser-globals/test.js | 5 ++--- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/packages/confusing-browser-globals/README.md b/packages/confusing-browser-globals/README.md index acbc41e0066..7387d3d59dc 100644 --- a/packages/confusing-browser-globals/README.md +++ b/packages/confusing-browser-globals/README.md @@ -1,4 +1,4 @@ -# eslint-restricted-globals +# confusing-browser-globals > A list of confusing globals that should be restricted to be used as globals diff --git a/packages/confusing-browser-globals/package.json b/packages/confusing-browser-globals/package.json index 184e7036c3c..645eba90437 100644 --- a/packages/confusing-browser-globals/package.json +++ b/packages/confusing-browser-globals/package.json @@ -4,7 +4,7 @@ "description": "A list of confusing globals that should be restricted to be used as globals", "main": "index.js", "scripts": { - "test": "mocha" + "test": "jest" }, "repository": "facebookincubator/create-react-app", "keywords": [ @@ -16,6 +16,6 @@ ], "license": "BSD-3-Clause", "devDependencies": { - "mocha": "^3.4.1" + "jest": "^20.0.3" } } diff --git a/packages/confusing-browser-globals/test.js b/packages/confusing-browser-globals/test.js index 74513d76b11..3c16790f693 100644 --- a/packages/confusing-browser-globals/test.js +++ b/packages/confusing-browser-globals/test.js @@ -1,11 +1,10 @@ 'use strict'; -let assert = require('assert'); let globals = require('./'); it('should return an Array of globals', function() { - assert.strictEqual(Array.isArray(globals), true); + expect(Array.isArray(globals)).toBe(true) }); it('should contain "event" variable', () => { - assert.strictEqual(globals.indexOf('event') >= 0, true); + expect(globals).toContain('event') }); From ee337a64f1fc98e9b10cdfb34192d64471786696 Mon Sep 17 00:00:00 2001 From: Dan Date: Sun, 14 Jan 2018 01:16:22 +0000 Subject: [PATCH 08/10] tweaks --- packages/confusing-browser-globals/README.md | 36 +++++++++++-------- packages/confusing-browser-globals/index.js | 8 ++--- .../confusing-browser-globals/package.json | 6 ++-- packages/confusing-browser-globals/test.js | 16 ++++++--- 4 files changed, 39 insertions(+), 27 deletions(-) diff --git a/packages/confusing-browser-globals/README.md b/packages/confusing-browser-globals/README.md index 7387d3d59dc..1f811f71041 100644 --- a/packages/confusing-browser-globals/README.md +++ b/packages/confusing-browser-globals/README.md @@ -1,33 +1,39 @@ # confusing-browser-globals -> A list of confusing globals that should be restricted to be used as globals +A curated list of browser globals that commonly cause confusion and are not recommended to use without an explicit `window.` qualifier. -## Install +## Motivation -``` -$ npm install --save confusing-browser-globals -``` +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. -Some global variables in browser are likely to be used by people without the intent of using them as globals, such as `status`, `name` etc. -And because eslint thinks of them as valid global variables, it does not warn in case of bugs. +For example: -For eg: ```js -function logStats(stats) { - console.log(status); +handleClick() { // missing `event` argument + this.setState({ + text: event.target.value // uses the `event` global: oops! + }); } ``` -Here we try to log variable `stats`, but by mistake we are logging `status` and as `status` is a valid global, no eslint warning is shown. +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. + + +## Installation + +``` +npm install --save confusing-browser-globals +``` -To avoid this, we blacklist such confusing globals which are exported from this package. It contains the list of variables that we think should not be used without `window.` qualifier. But as this is just a javascript array you can add, remove variables or even make your own list of variables. ## Usage -Add this in your eslint config in rules property: +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. + +If you maintain your own ESLint configuration, you can do this: ```js -var restrictedGlobals = require('eslint-restricted-globals'); +var restrictedGlobals = require('confusing-browser-globals'); module.exports = { rules: { @@ -39,4 +45,4 @@ module.exports = { ## License -MIT \ No newline at end of file +MIT diff --git a/packages/confusing-browser-globals/index.js b/packages/confusing-browser-globals/index.js index 06c6c8e9c08..98bf349962e 100644 --- a/packages/confusing-browser-globals/index.js +++ b/packages/confusing-browser-globals/index.js @@ -1,10 +1,8 @@ /** * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. */ 'use strict'; @@ -16,9 +14,9 @@ module.exports = [ 'closed', 'confirm', 'defaultStatus', + 'defaultstatus', 'event', 'external', - 'defaultstatus', 'find', 'focus', 'frameElement', diff --git a/packages/confusing-browser-globals/package.json b/packages/confusing-browser-globals/package.json index 645eba90437..211a2df30a9 100644 --- a/packages/confusing-browser-globals/package.json +++ b/packages/confusing-browser-globals/package.json @@ -1,7 +1,8 @@ { "name": "confusing-browser-globals", "version": "1.0.0", - "description": "A list of confusing globals that should be restricted to be used as globals", + "description": "A list of browser globals that are often used by mistake instead of local variables", + "license": "MIT", "main": "index.js", "scripts": { "test": "jest" @@ -14,8 +15,7 @@ "files": [ "index.js" ], - "license": "BSD-3-Clause", "devDependencies": { - "jest": "^20.0.3" + "jest": "22.0.6" } } diff --git a/packages/confusing-browser-globals/test.js b/packages/confusing-browser-globals/test.js index 3c16790f693..b2256c451b3 100644 --- a/packages/confusing-browser-globals/test.js +++ b/packages/confusing-browser-globals/test.js @@ -1,10 +1,18 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + 'use strict'; -let globals = require('./'); +let globals = require('./index'); -it('should return an Array of globals', function() { - expect(Array.isArray(globals)).toBe(true) +it('should return an Array of globals', () => { + expect(Array.isArray(globals)).toBe(true); }); + it('should contain "event" variable', () => { - expect(globals).toContain('event') + expect(globals).toContain('event'); }); From 4e0e8d380fa413eaf56764d766c1605d554962e9 Mon Sep 17 00:00:00 2001 From: Dan Date: Sun, 14 Jan 2018 01:20:11 +0000 Subject: [PATCH 09/10] Add lint/test to CI --- tasks/e2e-simple.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tasks/e2e-simple.sh b/tasks/e2e-simple.sh index b566ae37a3d..8ea08b55611 100755 --- a/tasks/e2e-simple.sh +++ b/tasks/e2e-simple.sh @@ -100,24 +100,29 @@ npx npm-cli-login@0.0.10 -u user -p password -e user@example.com -r "$custom_reg # Lint own code ./node_modules/.bin/eslint --max-warnings 0 packages/babel-preset-react-app/ +./node_modules/.bin/eslint --max-warnings 0 packages/confusing-browser-globals/ ./node_modules/.bin/eslint --max-warnings 0 packages/create-react-app/ ./node_modules/.bin/eslint --max-warnings 0 packages/eslint-config-react-app/ ./node_modules/.bin/eslint --max-warnings 0 packages/react-dev-utils/ ./node_modules/.bin/eslint --max-warnings 0 packages/react-scripts/ + cd packages/react-error-overlay/ ./node_modules/.bin/eslint --max-warnings 0 src/ yarn test - if [ $APPVEYOR != 'True' ]; then # Flow started hanging on AppVeyor after we moved to Yarn Workspaces :-( yarn flow fi - cd ../.. + cd packages/react-dev-utils/ yarn test cd ../.. +cd packages/confusing-browser-globals/ +yarn test +cd ../.. + # ****************************************************************************** # First, test the create-react-app development environment. # This does not affect our users but makes sure we can develop it. From 6043a08ed657f4a904f132fe8e85d2f3354a5f3a Mon Sep 17 00:00:00 2001 From: Dan Date: Sun, 14 Jan 2018 02:00:14 +0000 Subject: [PATCH 10/10] Fix lint --- packages/confusing-browser-globals/test.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/confusing-browser-globals/test.js b/packages/confusing-browser-globals/test.js index b2256c451b3..bdc26204205 100644 --- a/packages/confusing-browser-globals/test.js +++ b/packages/confusing-browser-globals/test.js @@ -5,6 +5,8 @@ * LICENSE file in the root directory of this source tree. */ +/* eslint-env jest */ + 'use strict'; let globals = require('./index');