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.

@babel/eslint-parser false positive for no-unused-vars rule with TypeScript types

See original GitHub issue

Bug Report

  • I would like to work on a fix!

Current behavior @babel/eslint-parser gives false positive (shows error) for no-unused-vars rule with TypeScript types:

error  'Rubik' is defined but never used  no-unused-vars

Input Code

import Rubik from './Rubik';

export default class Arranger {
  private readonly rubik: Rubik;
}

Expected behavior When run eslint, no errors/warnings should arise.

Babel Configuration (babel.config.js, .babelrc, package.json#babel, cli command, .eslintrc)

  • Filename: babel.config.js
{
  "presets": [
    "@babel/preset-env",
    "@babel/preset-typescript"
  ],
  "plugins": [
    "@babel/proposal-class-properties"
  ]
}
  • Filename: .eslintrc.json
{
  "parser": "@babel/eslint-parser",
  "rules": {
    "no-unused-vars": ["error"]
  }
}

Environment

  System:
    OS: Linux 4.19 Alpine Linux
  Binaries:
    Node: 12.18.3 - /usr/bin/node
    Yarn: 1.22.4 - /usr/bin/yarn
  npmPackages:
    @babel/core: ^7.10.2 => 7.11.4
    @babel/eslint-parser: ^7.11.4 => 7.11.4
    @babel/eslint-plugin: ^7.11.3 => 7.11.3
    @babel/plugin-proposal-class-properties: ^7.8.3 => 7.10.4
    @babel/preset-env: ^7.10.2 => 7.11.0
    @babel/preset-typescript: ^7.9.0 => 7.10.4
    eslint: 7.2.* => 7.2.0
    webpack: ^4.43.0 => 4.44.1

Note This issue already existed before switching to Babel monorepo (in babel/babel-eslint) so the switch is not the cause.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
taylankasapcommented, Oct 14, 2020

In that case it’s all good.

Maybe this part can be mentioned in readme or docs:

We’ve left linting TypeScript to @typescript-eslint due to all the duplicated work and lack of type information

Anyway, thanks for the info.

0reactions
kaicataldocommented, Oct 19, 2020

@taylankasap That’s a good idea!

@prateekbh That’s right!

Read more comments on GitHub >

github_iconTop Results From Across the Web

typescript-eslint/no-unused-vars false positive in type ...
Question: What's wrong with this rule and why it triggers in this case. Why eslint recognizes type declaration for functions in types/interfaces ...
Read more >
Kent C. Dodds on Twitter: "Starting to think that using ...
Getting some parser errors + things like "Partial<Props>" is triggering eslint's "no-undef" rule to error out because "Partial" is not defined.
Read more >
TSConfig Reference - Docs on every TSConfig option
Intro to the TSConfig Reference. A TSConfig file in a directory indicates that the directory is the root of a TypeScript or JavaScript...
Read more >
parseroptions.project has been set for @typescript-eslint/parser
@bluenote10 I use both overrides.rules and rules because I need to lint different files in different ways. For example, rules contains the rules...
Read more >
typescript-eslint/no-unused-vars false positive in type ...
@typescript-eslint/parser; @typescript-eslint/eslint-plugin. in your .eslintrc.js make sure you have the following lines added to rules section:
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