[no-unused-vars] Incorrect code location when self referencing
See original GitHub issueBTW, https://github.com/typescript-eslint/typescript-eslint/issues/2353#issuecomment-668150529 pointed me here.
Tell us about your environment
Node version: v10.20.0 npm version: v6.14.4 Local ESLint version: v7.5.0 (Currently used) Global ESLint version: Not found
What parser (default, Babel-ESLint, etc.) are you using?
@typescript-eslint/parser
.
Please show your full configuration:
Configuration
module.exports = {
env: {
browser: true,
// Parcel can shim node apis.
node: true,
es2020: true
},
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:react/recommended',
'plugin:react-hooks/recommended',
// Prettier needs to be the last.
'prettier',
'prettier/@typescript-eslint',
'prettier/babel',
'prettier/react'
],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaFeatures: {
jsx: true
},
ecmaVersion: 11,
sourceType: 'module'
},
plugins: ['react', 'react-hooks', '@typescript-eslint'],
rules: {
'@typescript-eslint/no-unused-vars': [
'warn',
{ ignoreRestSiblings: true }
],
'@typescript-eslint/no-use-before-define': [
'error',
{ functions: false }
],
'@typescript-eslint/no-inferrable-types': 'off',
'newline-after-var': ['error', 'always'],
'no-console': 'warn',
'no-undef': 'error',
'react/display-name': 'off',
'react/jsx-fragments': ['error', 'element'],
'react/prop-types': ['error', { skipUndeclared: true }]
},
overrides: [
{
files: ['*.js'],
rules: {
// Don't check function types for `.js` files.
'@typescript-eslint/explicit-module-boundary-types': 'off'
}
},
{
files: ['*.test.js', '*.test.ts', '*.test.tsx'],
env: {
jest: true
},
rules: {
'@typescript-eslint/no-namespace': 'off',
// Don't care about using type `any` in tests.
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
// Don't care about using `console` in tests.
'no-console': 'off'
}
},
{
files: ['*.stories.js', '*.stories.ts', '*.stories.tsx'],
env: {
node: true
},
rules: {
// Don't care about using type `any` in Storybook.
'@typescript-eslint/no-explicit-any': 'off',
// Don't care about using `console` in Storybook.
'no-console': 'off'
}
},
{
files: ['maintenance/**/*.ts'],
rules: {
'@typescript-eslint/no-var-requires': 'off',
'no-console': 'off'
}
}
],
settings: {
react: {
version: 'detect'
}
}
};
What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.
const foobar = () => ({
getFoobar: () => foobar() //<-- 'foobar' is assigned a value but never used.
});
npx eslint src/test.ts
What did you expect to happen?
The foobar
on line 1 should be labeled as not used.
What actually happened? Please include the actual, raw output from ESLint.
src/test.ts
2:22 warning 'foobar' is assigned a value but never used @typescript-eslint/no-unused-vars
Are you willing to submit a pull request to fix this bug? Sorry but my boss is already going to kill me for wasting time on things like this (reporting bugs).
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (5 by maintainers)
Top GitHub Comments
@anikethsaha I’d prefer not to go down that route, as that opens up a whole new can of words around configuration. I would also argue that this is a stylistic choice. I do think it makes the most sense to report the last assignment, however, and not the last occurrence.
@Zodiase I agree that reporting the last assignment would make sense. We’ve gone through a few iterations of the reported location at this point, so we’d want to make sure we have really ironed out what it is we want if we want to consider changing it again.