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
bug no-unused-vars
- is assigned a value but never used
#13172
Comments
no-unused-vars
- is assigned a value but never used`no-unused-vars
- is assigned a value but never used
I am not sure but I think this is intentional. let myArray = [1,2,3,4].filter((x) => x == 0);
foo= myArray.filter((x) => x == 1); it is lint-free.
|
It feels strange, because my example is very trivial but I don't understand the why. |
I would chain them if possible. let myArray = [1,2,3,4].filter((x) => x == 0).filter((x) => x == 1) |
In my real case the two operations are not exactly like this, the 2nd line is in a loop and the condition change. |
@jonathantribouharet thanks for the bug report!
Can you please clarify this issue, it seems that the actual behavior matches the expected behavior? |
@mdjermanovic the issue is I'm actually using the variable The real code look like this:
The error is on |
I agree it would be nice to change the error message in this case.
This would be a bug, but I can't reproduce it. Please let me know if I'm missing something. config: module.exports = {
parser: "@typescript-eslint/parser",
plugins: ["@typescript-eslint"],
rules : {
'no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }]
},
}; code (had to add function's name to make it valid syntax): function foo(items: [OrderItem]) {
let itemsToProcess = items.filter((x) => x.relationships.item.data != null);
let results = items.filter((x) => x.relationships.item.data == null);
results = results.sort((a, b) => b.amountWithVat - a.amountWithVat)
itemsToProcess = itemsToProcess.filter((item) => {
const parentId = item.relationships.item.data.id;
const index = results.findIndex((x) => x.id == parentId);
if (index >= 0) {
results.splice(index + 1, 0, item);
return false;
}
return true;
})
itemsToProcess.filter((item) => {
const parentId = item.relationships.item.data.id;
const index = results.findIndex((x) => x.id == parentId);
if (index >= 0) {
results.splice(index + 1, 0, item);
return false;
}
return true;
})
return results;
} output:
Neither of the two I also tried with Here's also online demo with the default parser. |
Ok it makes sense for the rule
And the problem is line 20 with |
Makes sense 👍 I believe this is the same request as #12871, which unfortunately didn't reach consensus at the time. I think we could at least change the error message. |
Yes, it should report at the last references instead of the declaration if it has references. |
Can someone make a concrete proposal so we can decide on it? |
Unfortunately, it looks like there wasn't enough interest from the team Thanks for contributing to ESLint and we appreciate your understanding. |
Node version: v13.11.0
npm version: v6.13.7
Local ESLint version: v6.8.0 (Currently used)
Global ESLint version: Not found
Typescript Version: 3.8.3
VueJS Version: 2.6.11
What parser (default, Babel-ESLint, etc.) are you using?
Babel-ESLint
Please show your full configuration:
Configuration
What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.
What did you expect to happen?
It should be an error.
What actually happened? Please include the actual, raw output from ESLint.
error 'myArray' is assigned a value but never used no-unused-vars
error 'myArray' is assigned a value but never used @typescript-eslint/no-unused-vars
Are you willing to submit a pull request to fix this bug?
No
The text was updated successfully, but these errors were encountered: