Repository: eslint/eslint (js)

Issue:
no-unused-vars doesn't detect destructured variables if the object pads another param
**Tell us about your environment**

* **ESLint Version:** 3.19.0
* **Node Version:** 6
* **npm Version:** 3

**What parser (default, Babel-ESLint, etc.) are you using?** babel-eslint

**Please show your full configuration:**
```
"no-unused-vars" : "warn",
```

**What did you do? Please include the actual source code causing the issue.**

Paste this into the [demo](http://eslint.org/demo/):

```js
(function ({ a }, b ) {
    return b;
})();
```

**What did you expect to happen?**

`a` should be detected as being unused.

**What actually happened? Please include the actual, raw output from ESLint.**

`a` passed, because I think it assumes the first parameter (the `{ a }` object) to be padding the `b` param.


Pull request:
Update: no-unused-vars false negative about destructuring (fixes #8442)
**What is the purpose of this pull request? (put an "X" next to item)**

[X] Bug fix ([template](https://raw.githubusercontent.com/eslint/eslint/master/templates/bug-report.md))

Fixes #8442.

**What changes did you make? (Give an overview)**

The rule should warn the variables which are in destructuring even if those exist in non-last parameters because those can always be removed.
This is semver-minor matter since a bug fix which increases warnings.

**Is there anything you'd like reviewers to focus on?**

Nothing in particular.

Patch:
diff --git a/docs/user-guide/getting-started.md b/docs/user-guide/getting-started.md
index c6682b722..0e5673d25 100644
--- a/docs/user-guide/getting-started.md
+++ b/docs/user-guide/getting-started.md
@@ -29,7 +29,7 @@ You should then setup a configuration file:
 $ ./node_modules/.bin/eslint --init
 ```
 
-After that, you can run ESLint on any file or directory like this:
+After that, you can run ESLint in your project's root directory like this:
 
 ```
 $ ./node_modules/.bin/eslint yourfile.js
diff --git a/lib/rules/no-unused-vars.js b/lib/rules/no-unused-vars.js
index 3ff9bc64f..3ed278d54 100644
--- a/lib/rules/no-unused-vars.js
+++ b/lib/rules/no-unused-vars.js
@@ -513,7 +513,7 @@ module.exports = {
                             }
 
                             // if "args" option is "after-used", skip all but the last parameter
-                            if (config.args === "after-used" && !isLastInNonIgnoredParameters(variable)) {
+                            if (config.args === "after-used" && astUtils.isFunction(def.name.parent) && !isLastInNonIgnoredParameters(variable)) {
                                 continue;
                             }
                         } else {


Test patch:
diff --git a/tests/lib/rules/no-unused-vars.js b/tests/lib/rules/no-unused-vars.js
index a966ebb10..e2ab90b8c 100644
--- a/tests/lib/rules/no-unused-vars.js
+++ b/tests/lib/rules/no-unused-vars.js
@@ -609,6 +609,54 @@ ruleTester.run("no-unused-vars", rule, {
         {
             code: "/*global\rfoo*/",
             errors: [{ message: "'foo' is defined but never used.", line: 2, column: 1 }]
+        },
+
+        // https://github.com/eslint/eslint/issues/8442
+        {
+            code: "(function ({ a }, b ) { return b; })();",
+            parserOptions: { ecmaVersion: 2015 },
+            errors: [
+                "'a' is defined but never used."
+            ]
+        },
+        {
+            code: "(function ({ a }, { b, c } ) { return b; })();",
+            parserOptions: { ecmaVersion: 2015 },
+            errors: [
+                "'a' is defined but never used.",
+                "'c' is defined but never used."
+            ]
+        },
+        {
+            code: "(function ({ a, b }, { c } ) { return b; })();",
+            parserOptions: { ecmaVersion: 2015 },
+            errors: [
+                "'a' is defined but never used.",
+                "'c' is defined but never used."
+            ]
+        },
+        {
+            code: "(function ([ a ], b ) { return b; })();",
+            parserOptions: { ecmaVersion: 2015 },
+            errors: [
+                "'a' is defined but never used."
+            ]
+        },
+        {
+            code: "(function ([ a ], [ b, c ] ) { return b; })();",
+            parserOptions: { ecmaVersion: 2015 },
+            errors: [
+                "'a' is defined but never used.",
+                "'c' is defined but never used."
+            ]
+        },
+        {
+            code: "(function ([ a, b ], [ c ] ) { return b; })();",
+            parserOptions: { ecmaVersion: 2015 },
+            errors: [
+                "'a' is defined but never used.",
+                "'c' is defined but never used."
+            ]
         }
     ]
 });