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
Closed
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly rule Relates to ESLint's core rules

Comments

@webOS101
Copy link
Contributor

webOS101 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: jsx-eslint/eslint-plugin-react#2009

@eslint-deprecated eslint-deprecated bot added the triage An ESLint team member will look at this issue soon label Oct 10, 2018
@platinumazure
Copy link
Member

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 This issue asks a question about ESLint and removed triage An ESLint team member will look at this issue soon labels Oct 10, 2018
@webOS101
Copy link
Contributor Author

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
Copy link
Contributor Author

webOS101 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
Copy link
Contributor Author

webOS101 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.

webOS101 pushed a commit to webOS101/eslint that referenced this issue Oct 10, 2018
webOS101 pushed a commit to webOS101/eslint that referenced this issue Oct 10, 2018
webOS101 pushed a commit to webOS101/eslint that referenced this issue Oct 10, 2018
@platinumazure platinumazure added bug ESLint is working incorrectly rule Relates to ESLint's core rules accepted There is consensus among the team that this change meets the criteria for inclusion and removed question This issue asks a question about ESLint labels Oct 10, 2018
@platinumazure
Copy link
Member

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-deprecated eslint-deprecated bot locked and limited conversation to collaborators Apr 11, 2019
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Apr 11, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly rule Relates to ESLint's core rules
Projects
None yet
Development

No branches or pull requests

2 participants