0

I've set up ESLint and testing it out for a couple of days and there's something that's been bugging me.

I get error message that reads: 'Book' is defined but never used. (no-unused-vars)

class Book extends REST {
  sayHi() {
    return `Hi! I am the book ${this.title}. I was written in ${this.year} by ${this.author}!`;
  }
}

In this case Book gets an error. In another file it's REST that gets the same error. They are defined, and used.. I don't understand what I'm doing wrong. I'd rather not turn off no-unused-vars.

This is the .eslintrc.json where I have all my rules:

{
"env": {
    "browser": true,
    "node": true
},
"extends": "recommended",
"parserOptions": {
    "ecmaVersion": 6,
    "sourceType": "module",
    "ecmaFeatures": {
        "modules": true,
        "experimentalObjectRestSpread": true
    }
},
"rules": {
    "no-restricted-syntax": 0,
    "no-param-reassign": 0,
    "no-return-await": 0,
    "no-underscore-dangle": 0,
    "prefer-template": 0,
    "no-undef": "off",
    "spaced-comment": 0,
    "no-trailing-spaces": 0,
    "no-undefined": 0,
    "space-before-blocks": 0,
    "comma-dangle": 0,
    "no-tabs": 0,
    "no-mixed-spaces-and-tabs": 0,
    "indent": 0,
    "linebreak-style": 0,
    "avoidEscape": true,
    "prefer-const": 0,
    "no-console": 0,
    "getter-return": 1,
    "no-compare-neg-zero": 0,
    "no-constant-condition": 0,
    "no-control-regex": 0,
    "no-empty": 1,
    "no-extra-parens": 1,
    "no-extra-semi": 1,
    "no-inner-declarations": 0,
    "class-methods-use-this": 1,
    "guard-for-in": 0,
    "eqeqeq": 1,
    "dot-notation": 1,
    "no-empty-function": 1,
    "no-empty-pattern": 0,
    "no-eval": 0,
    "no-multi-spaces": 1
  }
}

I've seen this issue pop up a lot online when I tried to google an solution, I can't find one that worked for me. Anyone have any idea what's up?

Janssonn
  • 87
  • 1
  • 8
  • 1
    Uh, in that snippet alone, you do *not* use `Book` anywhere, you only define it. Where and how do you use it? Please post that code as well. – Bergi Aug 29 '18 at 13:12
  • 1
    Can you share the code where you have used it? If you are intending to use it in other files, simply export it and the error will be gone, if it is private for the module, it must be used within the module – Bamieh Aug 29 '18 at 13:23
  • 2
    Exporting of the class should fix this issue, or show how do you use it – Drag13 Aug 29 '18 at 13:39
  • You're right. My bad, I missed some stuff in another file. (I rechecked all the other files upon your suggestions) Thank you :) – Janssonn Aug 29 '18 at 15:06

0 Answers0