Repository: eslint/eslint (js)

Issue:
ESLint rule no-redeclare is no longer working as expected
<!--
    ESLint adheres to the [JS Foundation Code of Conduct](https://js.foundation/community/code-of-conduct).

    This template is for bug reports. If you are reporting a bug, please continue on. If you are here for another reason, please see below:

    1. To propose a new rule: http://eslint.org/docs/developer-guide/contributing/new-rules
    2. To request a change: http://eslint.org/docs/developer-guide/contributing/changes
    3. If you have any questions, please stop by our chatroom: https://gitter.im/eslint/eslint

    Note that leaving sections blank will make it difficult for us to troubleshoot and we may have to close the issue.
-->

**Tell us about your environment**

* **ESLint Version:** 4.6.0
* **Node Version:** 8.3.0
* **npm Version:** 5.3.0

**What parser (default, Babel-ESLint, etc.) are you using?** default

**Please show your full configuration:**

<details>
<summary>Configuration</summary>

<!-- Paste your configuration below: -->
```js
{
  "root": true,
  "env": {
    "browser": true,
    "node": true,
    "commonjs": true,
    "shared-node-browser": true,
    "es6": true,
    "worker": true,
    "amd": false,
    "mocha": false,
    "jasmine": false,
    "jest": false,
    "phantomjs": false,
    "protractor": false,
    "qunit": false,
    "jquery": false,
    "prototypejs": false,
    "shelljs": false,
    "meteor": false,
    "mongo": false,
    "applescript": false,
    "nashorn": false,
    "serviceworker": false,
    "atomtest": false,
    "embertest": false,
    "webextensions": false,
    "greasemonkey": false
  },
  "rules": {
    "for-direction": "error",
    "no-await-in-loop": "warn",
    "no-compare-neg-zero": "error",
    "no-cond-assign": [
      "error",
      "always"
    ],
    "no-console": "warn",
    "no-constant-condition": [
      "error",
      {
        "checkLoops": false
      }
    ],
    "no-control-regex": "error",
    "no-debugger": "error",
    "no-dupe-args": "error",
    "no-dupe-keys": "error",
    "no-duplicate-case": "error",
    "no-empty-character-class": "error",
    "no-empty": "error",
    "no-ex-assign": "error",
    "no-extra-boolean-cast": "error",
    "no-extra-parens": [
      "error",
      "functions"
    ],
    "no-extra-semi": "error",
    "no-func-assign": "error",
    "no-inner-declarations": [
      "error",
      "both"
    ],
    "no-invalid-regexp": "error",
    "no-irregular-whitespace": "error",
    "no-obj-calls": "error",
    "no-prototype-builtins": "error",
    "no-regex-spaces": "error",
    "no-sparse-arrays": "error",
    "no-template-curly-in-string": "off",
    "no-unexpected-multiline": "error",
    "no-unreachable": "error",
    "no-unsafe-finally": "error",
    "no-unsafe-negation": "error",
    "use-isnan": "error",
    "valid-jsdoc": [
      "error",
      {
        "prefer": {
          "arg": "param",
          "argument": "param",
          "class": "constructor",
          "return": "returns"
        },
        "requireReturn": false,
        "requireReturnType": true,
        "matchDescription": ".+",
        "requireParamDescription": true,
        "requireReturnDescription": true
      }
    ],
    "valid-typeof": [
      "error",
      {
        "requireStringLiterals": true
      }
    ],
    "accessor-pairs": [
      "error",
      {
        "setWithoutGet": true,
        "getWithoutSet": false
      }
    ],
    "array-callback-return": "error",
    "block-scoped-var": "error",
    "class-methods-use-this": "error",
    "complexity": "off",
    "consistent-return": "off",
    "curly": "error",
    "default-case": "error",
    "dot-location": [
      "error",
      "property"
    ],
    "dot-notation": "off",
    "eqeqeq": [
      "error",
      "always"
    ],
    "guard-for-in": "error",
    "no-alert": "error",
    "no-caller": "error",
    "no-case-declarations": "error",
    "no-div-regex": "error",
    "no-else-return": "error",
    "no-empty-function": "error",
    "no-empty-pattern": "error",
    "no-eq-null": "error",
    "no-eval": "error",
    "no-extend-native": "error",
    "no-extra-bind": "error",
    "no-extra-label": "error",
    "no-fallthrough": "error",
    "no-floating-decimal": "error",
    "no-global-assign": "error",
    "no-implicit-coercion": "off",
    "no-implicit-globals": "off",
    "no-implied-eval": "error",
    "no-invalid-this": "error",
    "no-iterator": "error",
    "no-labels": [
      "error",
      {
        "allowLoop": false,
        "allowSwitch": false
      }
    ],
    "no-lone-blocks": "error",
    "no-loop-func": "error",
    "no-magic-numbers": [
      "off",
      {
        "ignoreArrayIndexes": true,
        "enforceConst": false,
        "detectObjects": false
      }
    ],
    "no-multi-spaces": [
      "error",
      {
        "ignoreEOLComments": true
      }
    ],
    "no-multi-str": "error",
    "no-new-func": "error",
    "no-new-wrappers": "error",
    "no-new": "error",
    "no-octal-escape": "error",
    "no-octal": "error",
    "no-param-reassign": "off",
    "no-proto": "error",
    "no-redeclare": [
      "error",
      {
        "builtinGlobals": true
      }
    ],
    "no-restricted-properties": "off",
    "no-return-assign": [
      "error",
      "always"
    ],
    "no-return-await": "error",
    "no-script-url": "error",
    "no-self-assign": [
      "error",
      {
        "props": true
      }
    ],
    "no-self-compare": "off",
    "no-sequences": "error",
    "no-throw-literal": "error",
    "no-unmodified-loop-condition": "off",
    "no-unused-expressions": [
      "error",
      {
        "allowShortCircuit": false,
        "allowTernary": false
      }
    ],
    "no-unused-labels": "error",
    "no-useless-call": "error",
    "no-useless-concat": "error",
    "no-useless-escape": "error",
    "no-useless-return": "error",
    "no-void": "off",
    "no-warning-comments": [
      "warn",
      {
        "terms": [
          "todo",
          "warning",
          "fixme",
          "hack",
          "optimize",
          "xxx"
        ],
        "location": "start"
      }
    ],
    "no-with": "error",
    "radix": [
      "error",
      "always"
    ],
    "require-await": "error",
    "vars-on-top": "error",
    "wrap-iife": [
      "error",
      "inside"
    ],
    "yoda": [
      "error",
      "never",
      {
        "exceptRange": true
      }
    ],
    "strict": [
      "error",
      "global"
    ],
    "init-declarations": "off",
    "no-catch-shadow": "error",
    "no-delete-var": "error",
    "no-label-var": "error",
    "no-restricted-globals": [
      "error",
      "event",
      "fdescribe"
    ],
    "no-shadow-restricted-names": "error",
    "no-shadow": "off",
    "no-undef-init": "error",
    "no-undef": "error",
    "no-undefined": "error",
    "no-unused-vars": [
      "error",
      {
        "vars": "all",
        "args": "after-used",
        "caughtErrors": "all"
      }
    ],
    "no-use-before-define": [
      "error",
      {
        "functions": false,
        "classes": true
      }
    ],
    "callback-return": [
      "warn",
      [
        "callback",
        "clbk",
        "cb",
        "done",
        "next"
      ]
    ],
    "global-require": "off",
    "handle-callback-err": [
      "error",
      "^(err|error)$"
    ],
    "no-buffer-constructor": "warn",
    "no-mixed-requires": [
      "error",
      {
        "grouping": false,
        "allowCall": true
      }
    ],
    "no-new-require": "error",
    "no-path-concat": "error",
    "no-process-env": "error",
    "no-process-exit": "warn",
    "no-restricted-modules": [
      "error",
      {
        "paths": [
          "underscore",
          "lodash",
          "async"
        ],
        "patterns": [
          "lodash*",
          "async/*"
        ]
      }
    ],
    "no-sync": "warn",
    "array-bracket-newline": [
      "off",
      {
        "multiline": true,
        "minItems": null
      }
    ],
    "array-bracket-spacing": [
      "off",
      "always",
      {
        "singleValue": true,
        "objectsInArrays": false,
        "arraysInArrays": false
      }
    ],
    "array-element-newline": [
      "off",
      {
        "multiline": true,
        "minItems": null
      }
    ],
    "block-spacing": [
      "error",
      "always"
    ],
    "brace-style": [
      "off",
      "1tbs",
      {
        "allowSingleLine": false
      }
    ],
    "camelcase": [
      "error",
      {
        "properties": "never"
      }
    ],
    "capitalized-comments": [
      "warn",
      "always",
      {
        "ignoreInlineComments": true
      }
    ],
    "comma-dangle": [
      "error",
      "never"
    ],
    "comma-spacing": [
      "error",
      {
        "before": false,
        "after": true
      }
    ],
    "comma-style": [
      "error",
      "last"
    ],
    "computed-property-spacing": [
      "off",
      "always"
    ],
    "consistent-this": [
      "error",
      "self"
    ],
    "eol-last": [
      "error",
      "always"
    ],
    "func-call-spacing": [
      "error",
      "never"
    ],
    "func-name-matching": "off",
    "func-names": [
      "error",
      "always"
    ],
    "func-style": [
      "error",
      "declaration",
      {
        "allowArrowFunctions": false
      }
    ],
    "id-blacklist": "off",
    "id-length": [
      "warn",
      {
        "min": 1,
        "max": 25,
        "properties": "never"
      }
    ],
    "id-match": "off",
    "indent": [
      "error",
      "tab",
      {
        "SwitchCase": 0,
        "VariableDeclarator": 1,
        "outerIIFEBody": 1,
        "MemberExpression": 1,
        "FunctionDeclaration": {
          "body": 1,
          "parameters": "off"
        },
        "FunctionExpression": {
          "body": 1,
          "parameters": "off"
        },
        "CallExpression": {
          "arguments": "off"
        },
        "ArrayExpression": 1,
        "ObjectExpression": 1,
        "flatTernaryExpressions": true
      }
    ],
    "jsx-quotes": "off",
    "key-spacing": [
      "error",
      {
        "beforeColon": false,
        "afterColon": true,
        "mode": "strict"
      }
    ],
    "keyword-spacing": [
      "error",
      {
        "before": true,
        "after": true
      }
    ],
    "line-comment-position": "off",
    "linebreak-style": [
      "error",
      "unix"
    ],
    "lines-around-comment": [
      "off",
      {
        "beforeBlockComment": true,
        "afterBlockComment": false,
        "beforeLineComment": true,
        "afterLineComment": false,
        "allowBlockStart": true,
        "allowBlockEnd": true,
        "allowObjectStart": true,
        "allowObjectEnd": true,
        "allowArrayStart": true,
        "allowArrayEnd": true
      }
    ],
    "max-depth": [
      "error",
      {
        "max": 5
      }
    ],
    "max-len": [
      "error",
      {
        "code": 80,
        "tabWidth": 4,
        "ignoreComments": true,
        "ignoreUrls": true,
        "ignoreStrings": true,
        "ignoreTemplateLiterals": true,
        "ignoreRegExpLiterals": true
      }
    ],
    "max-lines": [
      "warn",
      {
        "max": 300,
        "skipBlankLines": true,
        "skipComments": true
      }
    ],
    "max-nested-callbacks": [
      "error",
      {
        "max": 3
      }
    ],
    "max-params": [
      "error",
      {
        "max": 10
      }
    ],
    "max-statements-per-line": [
      "error",
      {
        "max": 1
      }
    ],
    "max-statements": [
      "warn",
      {
        "max": 100
      }
    ],
    "multiline-ternary": "off",
    "new-cap": [
      "error",
      {
        "newIsCap": false,
        "capIsNew": true,
        "properties": true
      }
    ],
    "new-parens": "error",
    "newline-per-chained-call": "off",
    "no-array-constructor": "error",
    "no-bitwise": "off",
    "no-continue": "off",
    "no-inline-comments": "off",
    "no-lonely-if": "error",
    "no-mixed-operators": [
      "error",
      {
        "allowSamePrecedence": true
      }
    ],
    "no-mixed-spaces-and-tabs": "error",
    "no-multiple-empty-lines": [
      "error",
      {
        "max": 2,
        "maxEOF": 1,
        "maxBOF": 1
      }
    ],
    "no-negated-condition": "error",
    "no-nested-ternary": "error",
    "no-new-object": "error",
    "no-plusplus": [
      "error",
      {
        "allowForLoopAfterthoughts": true
      }
    ],
    "no-restricted-syntax": [
      "error",
      "ArrowFunctionExpression",
      "ClassBody",
      "ClassDeclaration",
      "ClassExpression",
      "DebuggerStatement",
      "ExperimentalRestProperty",
      "ExperimentalSpreadProperty",
      "FunctionExpression",
      "LabeledStatement",
      "RestElement",
      "SpreadElement",
      "TaggedTemplateExpression",
      "TemplateElement",
      "TemplateLiteral",
      "WithStatement",
      "YieldExpression",
      "JSXIdentifier",
      "JSXNamespacedName",
      "JSXMemberExpression",
      "JSXEmptyExpression",
      "JSXExpressionContainer",
      "JSXElement",
      "JSXClosingElement",
      "JSXOpeningElement",
      "JSXAttribute",
      "JSXSpreadAttribute",
      "JSXText",
      "ExportDefaultDeclaration",
      "ExportNamedDeclaration",
      "ExportAllDeclaration",
      "ExportSpecifier",
      "ImportDeclaration",
      "ImportSpecifier",
      "ImportDefaultSpecifier",
      "ImportNamespaceSpecifier"
    ],
    "no-tabs": "off",
    "no-ternary": "off",
    "no-trailing-spaces": [
      "error",
      {
        "skipBlankLines": false
      }
    ],
    "no-underscore-dangle": [
      "error",
      {
        "allowAfterThis": true,
        "allowAfterSuper": true
      }
    ],
    "no-unneeded-ternary": [
      "error",
      {
        "defaultAssignment": false
      }
    ],
    "no-whitespace-before-property": "error",
    "nonblock-statement-body-position": [
      "error",
      "beside"
    ],
    "object-curly-newline": [
      "error",
      {
        "ObjectExpression": {
          "minProperties": 1,
          "consistent": true
        },
        "ObjectPattern": "never"
      }
    ],
    "object-curly-spacing": [
      "warn",
      "always",
      {
        "objectsInObjects": false,
        "arraysInObjects": false
      }
    ],
    "object-property-newline": [
      "error",
      {
        "allowMultiplePropertiesPerLine": false
      }
    ],
    "one-var-declaration-per-line": "off",
    "one-var": [
      "error",
      {
        "var": "never",
        "let": "never",
        "const": "never"
      }
    ],
    "operator-assignment": [
      "warn",
      "always"
    ],
    "operator-linebreak": [
      "error",
      "after"
    ],
    "padded-blocks": [
      "error",
      "never"
    ],
    "padding-line-between-statements": [
      "error",
      {
        "blankLine": "never",
        "prev": "*",
        "next": "directive"
      },
      {
        "blankLine": "always",
        "prev": "directive",
        "next": "*"
      },
      {
        "blankLine": "any",
        "prev": "directive",
        "next": "directive"
      },
      {
        "blankLine": "any",
        "prev": "var",
        "next": "*"
      },
      {
        "blankLine": "any",
        "prev": "*",
        "next": "return"
      }
    ],
    "quote-props": [
      "error",
      "always"
    ],
    "quotes": [
      "error",
      "single",
      {
        "avoidEscape": true
      }
    ],
    "require-jsdoc": [
      "error",
      {
        "require": {
          "FunctionDeclaration": true,
          "ClassDeclaration": true,
          "MethodDefinition": true,
          "ArrowFunctionExpression": true
        }
      }
    ],
    "semi": [
      "error",
      "always"
    ],
    "semi-spacing": [
      "error",
      {
        "before": false,
        "after": true
      }
    ],
    "semi-style": [
      "error",
      "last"
    ],
    "sort-keys": "off",
    "sort-vars": "off",
    "space-before-blocks": [
      "error",
      {
        "functions": "always",
        "keywords": "always",
        "classes": "always"
      }
    ],
    "space-before-function-paren": [
      "error",
      {
        "anonymous": "always",
        "named": "never",
        "asyncArrow": "always"
      }
    ],
    "space-in-parens": "off",
    "space-infix-ops": "off",
    "space-unary-ops": [
      "error",
      {
        "words": true,
        "nonwords": false
      }
    ],
    "spaced-comment": [
      "error",
      "always",
      {
        "block": {
          "balanced": true
        }
      }
    ],
    "switch-colon-spacing": [
      "error",
      {
        "before": false,
        "after": true
      }
    ],
    "template-tag-spacing": [
      "error",
      "never"
    ],
    "unicode-bom": "off",
    "wrap-regex": "off",
    "arrow-body-style": [
      "error",
      "always"
    ],
    "arrow-parens": [
      "error",
      "always"
    ],
    "arrow-spacing": [
      "error",
      {
        "before": true,
        "after": true
      }
    ],
    "constructor-super": "error",
    "generator-star-spacing": [
      "error",
      {
        "before": false,
        "after": true
      }
    ],
    "no-class-assign": "error",
    "no-confusing-arrow": [
      "error",
      {
        "allowParens": false
      }
    ],
    "no-const-assign": "error",
    "no-dupe-class-members": "error",
    "no-duplicate-imports": [
      "error",
      {
        "includeExports": true
      }
    ],
    "no-new-symbol": "error",
    "no-restricted-imports": [
      "error",
      {
        "paths": [
          "lodash",
          "underscore",
          "async"
        ],
        "patterns": [
          "lodash*",
          "async*"
        ]
      }
    ],
    "no-this-before-super": "error",
    "no-useless-computed-key": "error",
    "no-useless-constructor": "error",
    "no-useless-rename": "error",
    "no-var": "off",
    "object-shorthand": [
      "error",
      "never"
    ],
    "prefer-arrow-callback": "off",
    "prefer-const": [
      "warn",
      {
        "destructuring": "any",
        "ignoreReadBeforeAssign": false
      }
    ],
    "prefer-destructuring": "off",
    "prefer-numeric-literals": "off",
    "prefer-rest-params": "off",
    "prefer-spread": "off",
    "prefer-template": "off",
    "require-yield": "error",
    "rest-spread-spacing": [
      "error",
      "never"
    ],
    "sort-imports": "off",
    "symbol-description": "error",
    "template-curly-spacing": [
      "error",
      "never"
    ],
    "yield-star-spacing": [
      "error",
      {
        "before": false,
        "after": true
      }
    ]
  },
  "parserOptions": {
    "version": 6,
    "sourceType": "script",
    "ecmaFeatures": {
      "globalReturn": false,
      "impliedStrict": false,
      "jsx": false,
      "experimentalObjectRestSpread": false
    }
  }
}
```

</details>

**What did you do? Please include the actual source code causing the issue.**

<!-- Paste the source code below: -->
```js
'use strict';

var resolve = require( 'path' ).resolve;
var join = require( 'path' ).join;

var config = join( __dirname, 'eslint', '.eslintrc.markdown.js' );
var eslint = resolve( __dirname, '..', 'tools', 'remark', 'plugins', 'remark-lint-eslint' );
var opts = {
	'config': config,
	'ignore': false,
	'useEslintrc': false
};

var plugin = [ [ require( eslint ).factory( opts ), [ 'error' ] ] ];

module.exports = plugin;
```

**What did you expect to happen?**

I expected this to pass linting.

**What actually happened? Please include the actual, raw output from ESLint.**

```
/Users/beep/boop/etc/remark/plugins/eslint/index.js
  6:5  error  'config' is already defined  no-redeclare

✖ 1 problem (1 error, 0 warnings)
```

This file was passing linting until the most recent ESLint release (released today).

Pull request description:
Fix: avoid adding globals when an env is used with `false` (fixes #9202)
<!--
    ESLint adheres to the [JS Foundation Code of Conduct](https://js.foundation/community/code-of-conduct).
-->

**What is the purpose of this pull request? (put an "X" next to item)**

[x] Bug fix (https://github.com/eslint/eslint/issues/9202)

<!--
    If the item you've checked above has a template, please paste the template questions below and answer them. (If this pull request is addressing an issue, you can just paste a link to the issue here instead.)
-->

<!--
    Please ensure your pull request is ready:

    - Read the pull request guide (http://eslint.org/docs/developer-guide/contributing/pull-requests)
    - Include tests for this change
    - Update documentation for this change (if appropriate)
-->

<!--
    The following is required for all pull requests:
-->

**What changes did you make? (Give an overview)**

This fixes a regression introduced in f005e2467edda78a6654c4717aa23e99b3289131 (merged as part of 60c51486849c3765ac21fb63e615db2c56b614fd) where globals would get added to environments when the env was set to `false` in a config file. (The globals would not get added if the env was omitted).

I had originally assumed this was a dead code path because it wasn't covered in any tests (and I had thought environments with `env: false` where stripped out of the config beforehand). However, it turns out that we just didn't have tests for this case.

**Is there anything you'd like reviewers to focus on?**

Nothing in particular

Patch:
diff --git a/docs/rules/generator-star-spacing.md b/docs/rules/generator-star-spacing.md
index efa7a5a4e..95af6de80 100644
--- a/docs/rules/generator-star-spacing.md
+++ b/docs/rules/generator-star-spacing.md
@@ -93,7 +93,7 @@ An example of a configuration with overrides:
 ```
 
 In the example configuration above, the top level "before" and "after" options define the default behavior of
-the rule, while the "anonymous", "method", and "static" options override the default behavior.
+the rule, while the "anonymous" and "method" options override the default behavior.
 Overrides can be either an object with "before" and "after", or a shorthand string as above.
 
 ## Examples
diff --git a/lib/linter.js b/lib/linter.js
index 7e32eedb9..b06fb833e 100755
--- a/lib/linter.js
+++ b/lib/linter.js
@@ -178,7 +178,7 @@ function addDeclaredGlobals(program, globalScope, config, envContext) {
 
     Object.assign(declaredGlobals, builtin);
 
-    Object.keys(config.env).forEach(name => {
+    Object.keys(config.env).filter(name => config.env[name]).forEach(name => {
         const env = envContext.get(name),
             environmentGlobals = env && env.globals;
 


Test patch:
diff --git a/tests/lib/rules/no-catch-shadow.js b/tests/lib/rules/no-catch-shadow.js
index a302ae86b..3d1024f9e 100644
--- a/tests/lib/rules/no-catch-shadow.js
+++ b/tests/lib/rules/no-catch-shadow.js
@@ -36,6 +36,10 @@ ruleTester.run("no-catch-shadow", rule, {
                 "module.exports = broken;"
             ].join("\n"),
             parserOptions: { ecmaVersion: 6 }
+        },
+        {
+            code: "try {} catch (error) {}",
+            env: { shelljs: false }
         }
     ],
     invalid: [
diff --git a/tests/lib/rules/no-redeclare.js b/tests/lib/rules/no-redeclare.js
index 3d67961ed..2cd0f8ef5 100644
--- a/tests/lib/rules/no-redeclare.js
+++ b/tests/lib/rules/no-redeclare.js
@@ -35,7 +35,12 @@ ruleTester.run("no-redeclare", rule, {
         { code: "var top = 0;", env: { browser: true } },
         { code: "var top = 0;", options: [{ builtinGlobals: true }] },
         { code: "var top = 0;", options: [{ builtinGlobals: true }], parserOptions: { ecmaFeatures: { globalReturn: true } }, env: { browser: true } },
-        { code: "var top = 0;", options: [{ builtinGlobals: true }], parserOptions: { sourceType: "module" }, env: { browser: true } }
+        { code: "var top = 0;", options: [{ builtinGlobals: true }], parserOptions: { sourceType: "module" }, env: { browser: true } },
+        {
+            code: "var self = 1",
+            options: [{ builtinGlobals: true }],
+            env: { browser: false }
+        }
     ],
     invalid: [
         { code: "var a = 3; var a = 10;", parserOptions: { ecmaVersion: 6 }, errors: [{ message: "'a' is already defined.", type: "Identifier" }] },