question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[no-unused-vars] Incorrect code location when self referencing

See original GitHub issue

BTW, 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:closed
  • Created 3 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
kaicataldocommented, Aug 6, 2020

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

2reactions
kaicataldocommented, Aug 4, 2020

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting @typescript-eslint/no-unused-vars warning occurs ...
The error can be resolved by adding the 'include' property. include specifies an array of filenames or patterns to include in the program....
Read more >
no-unused-vars - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >
Code Quality report fails when ESLint is set up (with plugins ...
I added ESLint to a project that already had the Code Quality job set up, which all of a sudden started to fail...
Read more >
vue/no-parsing-error
This rule reports syntax errors in <template> . For example: Syntax errors of scripts in directives. Syntax errors of scripts in mustaches.
Read more >
Use Bicep linter - Azure Resource Manager | Microsoft Learn
In this article. Linter requirements; Default rules; Use in Visual Studio Code; Use in Bicep CLI; Silencing false positives; Next steps.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found