From d1ffd3966fc724f439201e7a64def9da0f31338b Mon Sep 17 00:00:00 2001 From: Milos Djermanovic Date: Fri, 2 Aug 2019 21:47:34 +0200 Subject: [PATCH 1/2] Docs: Remove readonly/writable global logic from no-undef (fixes #11963) --- docs/rules/no-undef.md | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/docs/rules/no-undef.md b/docs/rules/no-undef.md index f5dc5a280c5..f0fdf3a1e08 100644 --- a/docs/rules/no-undef.md +++ b/docs/rules/no-undef.md @@ -11,33 +11,20 @@ Examples of **incorrect** code for this rule: ```js /*eslint no-undef: "error"*/ -var a = someFunction(); -b = 10; +var foo = someFunction(); +var bar = a + 1; ``` Examples of **correct** code for this rule with `global` declaration: ```js -/*global someFunction b:writable*/ +/*global someFunction, a*/ /*eslint no-undef: "error"*/ -var a = someFunction(); -b = 10; +var foo = someFunction(); +var bar = a + 1; ``` -The `b:writable` syntax in `/*global */` indicates that assignment to `b` is correct. - -Examples of **incorrect** code for this rule with `global` declaration: - -```js -/*global b*/ -/*eslint no-undef: "error"*/ - -b = 10; -``` - -By default, variables declared in `/*global */` are read-only, therefore assignment is incorrect. - ## Options * `typeof` set to true will warn for variables used inside typeof check (Default false). From cb2cc9265fdeecac297aa7fa125b654571fbf5e0 Mon Sep 17 00:00:00 2001 From: Milos Djermanovic Date: Mon, 5 Aug 2019 17:51:26 +0200 Subject: [PATCH 2/2] Add references to other rules --- docs/rules/no-undef.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/docs/rules/no-undef.md b/docs/rules/no-undef.md index f0fdf3a1e08..faaf978cc8d 100644 --- a/docs/rules/no-undef.md +++ b/docs/rules/no-undef.md @@ -25,6 +25,12 @@ var foo = someFunction(); var bar = a + 1; ``` +Note that this rule does not disallow assignments to read-only global variables. +See [no-global-assign](no-global-assign.md) if you also want to disallow those assignments. + +This rule also does not disallow redeclarations of global variables. +See [no-redeclare](no-redeclare.md) if you also want to disallow those redeclarations. + ## Options * `typeof` set to true will warn for variables used inside typeof check (Default false). @@ -98,3 +104,8 @@ If explicit declaration of global variables is not to your taste. ## Compatibility This rule provides compatibility with treatment of global variables in [JSHint](http://jshint.com/) and [JSLint](http://www.jslint.com). + +## Related Rules + +* [no-global-assign](no-global-assign.md) +* [no-redeclare](no-redeclare.md)