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

jsx-uses-vars and no-unused-vars causes false warning #2009

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

jsx-uses-vars and no-unused-vars causes false warning #2009

webOS101 opened this issue Oct 5, 2018 · 4 comments
Labels

Comments

@webOS101
Copy link
Contributor

webOS101 commented Oct 5, 2018

I'm filing this one here, though it could be something that will need followup elsewhere.

eslint@5.6.1
eslint-plugin-react@7.11.1

Given the following code:

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

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

And the following .eslintconfig.json:

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

The following warning is given:

  4:44  warning  'config' is defined but never used  no-unused-vars

Expected output: No warning.

The default behavior of eslint is to only warn on unused parameters that come after the last used parameter. jsx-uses-vars flags Wrapped as used but it leaves config marked as unused. Should this be picked up automatically by eslint? Or, will this require some heroics on the part of the react plugin to find these and fix them?

@ljharb
Copy link
Member

ljharb commented Oct 5, 2018

Why on earth is render a class field instead of an instance method?

@ljharb
Copy link
Member

ljharb commented Oct 5, 2018

Separately, I would expect config to be left marked as unused, because it is unused - the default settings for no-unused-vars, for the "args" setting is indeed after-used, but I would assume this is something eslint can figure out.

If it's not figuring it out, then I think that's a bug in no-unused-vars - specifically, it might have to wait to do its checking on program exit to ensure all the variables have time to be marked as used.

@webOS101
Copy link
Contributor Author

webOS101 commented Oct 5, 2018

It was just a minimal sample, that's all. It's not reflective of any actual code. I will cross-file this to eslint.

@webOS101
Copy link
Contributor Author

fwiw, I made a PR with eslint that fixes this issue, so I'll close this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants