Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

no-unused-vars errors with parameters when parameter marked used later #10952

Closed
webOS101 opened this issue Oct 10, 2018 · 5 comments

Comments

@webOS101
Copy link
Contributor

commented Oct 10, 2018

Tell us about your environment

  • ESLint Version: 5.6.1
  • Node Version: v9.4.0
  • npm Version: 5.6.0

What parser (default, Babel-ESLint, etc.) are you using? babel-eslint

Please show your full configuration:

Configuration
{
	"parser": "babel-eslint",
	"plugins": [
		"babel",
		"react"
	],
	"extends": ["plugin:react/recommended"],
	"rules": {
		"no-unused-vars": 1
	}
}

What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.

The eslint-plugin-react rule for jsx-uses-vars marks the Wrapped parameter as used. However, no-unused-vars doesn't update the status of config. The default for no-unused-vars should not warn on parameters before the first used parameter.

import React from 'react';
import foo from 'foo';

export const AccessibilityDecorator = foo((config, Wrapped) => {
	return class t extends React.Component {
		render () {
			return <Wrapped />;
		}
	};
});
eslint .

What did you expect to happen?

No warnings.

What actually happened? Please include the actual, raw output from ESLint.

/Users/.../.../test.js
  4:44  warning  'config' is defined but never used  no-unused-vars

✖ 1 problem (0 errors, 1 warning)

Linked issue: yannickcr/eslint-plugin-react#2009

@eslint eslint bot added the triage label Oct 10, 2018

@platinumazure

This comment has been minimized.

Copy link
Member

commented Oct 10, 2018

Hi @webOS101, thanks for the issue.

Would you mind running ESLint with the --print-config option, passing in the path of the file you're trying to lint here? Curious to see if your configuration is being overridden somewhere (either in no-unused-vars, or react/jsx-uses-vars). Thanks!

@platinumazure platinumazure added question and removed triage labels Oct 10, 2018

@webOS101

This comment has been minimized.

Copy link
Contributor Author

commented Oct 10, 2018

It's not that, sadly. I had checked that previously.

{
  "globals": {},
  "env": {},
  "rules": {
    "react/display-name": 2,
    "react/jsx-key": 2,
    "react/jsx-no-comment-textnodes": 2,
    "react/jsx-no-duplicate-props": 2,
    "react/jsx-no-target-blank": 2,
    "react/jsx-no-undef": 2,
    "react/jsx-uses-react": 2,
    "react/jsx-uses-vars": 2,
    "react/no-children-prop": 2,
    "react/no-danger-with-children": 2,
    "react/no-deprecated": 2,
    "react/no-direct-mutation-state": 2,
    "react/no-find-dom-node": 2,
    "react/no-is-mounted": 2,
    "react/no-render-return-value": 2,
    "react/no-string-refs": 2,
    "react/no-unescaped-entities": 2,
    "react/no-unknown-property": 2,
    "react/no-unsafe": 0,
    "react/prop-types": 2,
    "react/react-in-jsx-scope": 2,
    "react/require-render-return": 2,
    "no-unused-vars": 1
  },
  "parserOptions": {
    "ecmaFeatures": {
      "jsx": true
    }
  },
  "plugins": [
    "react",
    "babel"
  ],
  "parser": "/usr/local/lib/node_modules/babel-eslint/lib/index.js",
  "extends": [
    "plugin:react/recommended"
  ]
}
@webOS101

This comment has been minimized.

Copy link
Contributor Author

commented Oct 10, 2018

It may be as simple as checking eslintUsed here:

return !posteriorParams.some(v => v.references.length > 0);

But I didn't actually test that.

@webOS101

This comment has been minimized.

Copy link
Contributor Author

commented Oct 10, 2018

I confirmed that works. I was able to create a test case that fails and passes with that fix. I still have never figured out how to use a locally linked eslint to test with either global or local installs. I guess I'll figure it out someday. I'll create a PR shortly.

@platinumazure

This comment has been minimized.

Copy link
Member

commented Oct 10, 2018

Thanks @webOS101 for digging further! I think I rewrote that code some time ago and this was an oversight on my part.

I've relabeled this as a bug, in accordance with your investigation results.

@eslint eslint bot locked and limited conversation to collaborators Apr 11, 2019

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
2 participants
You can’t perform that action at this time.