Skip to content

[no-unused-vars] warning for used vars #171

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

Closed
jzilg opened this issue Jan 31, 2019 · 6 comments
Closed

[no-unused-vars] warning for used vars #171

jzilg opened this issue Jan 31, 2019 · 6 comments
Labels
bug Something isn't working locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin package: parser Issues related to @typescript-eslint/parser

Comments

@jzilg
Copy link

jzilg commented Jan 31, 2019

Repro

I get many alerts from eslint because I have supposedly unused variables. For Example in this File.

import React, { ReactElement } from 'react'
import Todo from '../../interfaces/todo.interface'
import TodoListItem from '../TodoListItem'
import style from './todo-list.scss'

interface ListProps {
    todos: Todo[]
    addTodo: Function
    saveTodo: Function
    removeTodo: Function
    isLoading: boolean
}

const TodoList = ({
    todos,
    addTodo,
    saveTodo,
    removeTodo,
    isLoading,
}: ListProps): ReactElement<{}> => {
    const createNewId = (): number => {
        if (!todos.length) {
            return 0
        }
        const ids = todos.map(todo => todo.id)
        const highestId = Math.max(...ids)
        return highestId + 1
    }

    const addNewTodo = (): void => {
        const id = createNewId()
        addTodo(id)
    }

    const todoElements = todos.map(todo => (
        <li key={todo.id} className={style['list-element']}>
            <TodoListItem
                todo={todo}
                saveTodo={saveTodo}
                removeTodo={removeTodo}
                isLoading={isLoading}
            />
        </li>
    ))

    return (
        <div className="container">
            <h1>
                Todo List
            </h1>
            <ul className={style.list}>
                {todoElements}
            </ul>
            <button
                type="button"
                className={style['add-todo-btn']}
                title="Add Todo"
                onClick={addNewTodo}
                disabled={isLoading}
            >
                +
            </button>
        </div>
    )
}

export default TodoList

Expected Result
no eslint warnings, scince all variables are used at some point.

Actual Result
4:8 warning 'style' is defined but never used @typescript-eslint/no-unused-vars
17:5 warning 'saveTodo' is defined but never used @typescript-eslint/no-unused-vars
18:5 warning 'removeTodo' is defined but never used @typescript-eslint/no-unused-vars
19:5 warning 'isLoading' is defined but never used @typescript-eslint/no-unused-vars
30:11 warning 'addNewTodo' is assigned a value but never used @typescript-eslint/no-unused-vars
35:36 warning 'todo' is defined but never used @typescript-eslint/no-unused-vars

Additional Info
I just migrated from https://www.npmjs.com/package/eslint-plugin-typescript. While using that package, there was no warnings.

Versions

package version
@typescript-eslint/eslint-plugin 1.1.1
@typescript-eslint/parser 1.1.1
TypeScript 3.2.4
ESLint 5.12.1
node 10.14.1
npm 6.5.0
@jzilg jzilg added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look labels Jan 31, 2019
@runeh
Copy link

runeh commented Jan 31, 2019

We have the same issue. Workaround is to lock @typescript-eslint/parser to version 1.1.0. Something changed in the 1.1.1 patch version.

@armano2
Copy link
Collaborator

armano2 commented Jan 31, 2019

regression got fixed in @1.1.2-alpha.5, 6147de1

@armano2 armano2 added the package: parser Issues related to @typescript-eslint/parser label Jan 31, 2019
@bradzacher bradzacher added bug Something isn't working and removed triage Waiting for team members to take a look labels Jan 31, 2019
@bradzacher
Copy link
Member

As this has been fixed, I'll close this issue.

@gabemeola
Copy link

Still receiving this error as of 1.2.0

@armano2
Copy link
Collaborator

armano2 commented Feb 1, 2019

@gabemeola can you provide some example (source code)?

@bradzacher
Copy link
Member

@gabemeola there are a number of false positive cases for no-unused-vars.
Just commenting "still receiving this error" isn't very helpful when the OP listed 6 separate cases.
Which case exactly? One, or all of them?

Please open a new issue with a code sample, so we can investigate appropriately.

@typescript-eslint typescript-eslint locked as resolved and limited conversation to collaborators Feb 1, 2019
@bradzacher bradzacher added the locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. label Apr 14, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin package: parser Issues related to @typescript-eslint/parser
Projects
None yet
Development

No branches or pull requests

5 participants