Skip to content
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

no-unused-vars deprecated, noUnusedLocals ignored #1954

Closed
joeytwiddle opened this issue Nov 1, 2018 · 5 comments
Closed

no-unused-vars deprecated, noUnusedLocals ignored #1954

joeytwiddle opened this issue Nov 1, 2018 · 5 comments

Comments

@joeytwiddle
Copy link
Contributor

joeytwiddle commented Nov 1, 2018

Steps to reproduce

nvm use v10
npm install -g @loopback/cli
lb4 lb4-lint-test -y
cd lb-4-lint-test   # sic
# Add an unused variable
echo "const foo = 'hello';" >> src/index.ts
npm run test

Current Behavior

Output:

no-unused-variable is deprecated. Since TypeScript 2.9. Please use the built-in compiler checks instead.

ERROR: .../lb-4-lint-test/src/index.ts[17, 7]: 'foo' is declared but its value is never read.

Expected Behavior

Tests pass without error.

Towards a solution

On the web I read that, with no-unused-vars now deprecated in tslint, we are supposed to add noUnusedLocals to tsconfig.json instead:

  "compilerOptions": { "noUnusedLocals": false },

But that doesn't work either!

Quick fix

UPDATE February 2019: This workaround is no longer helping. The only way I now know to allow unused variables to pass linting, is to not upgrade typescript and tslint!

What does did work, was if I changed the tsconfig.json as above, and I also changed how linting is called in our package.json:

    "tslint": "tslint -p tsconfig.json",

^^ Hopefully this can help anyone who is stuck with this.

But notably when I try to do closer to what lb-tslint does:

    "tslint": "tslint -p tsconfig.json -c tslint.build.json",

then the error comes back again!

So I'm guessing this is actually a bug with tslint? Anyway I will leave this issue here for anyone who is having trouble right now.

@raymondfeng
Copy link
Contributor

raymondfeng commented Nov 1, 2018

See palantir/tslint#4100

@raymondfeng
Copy link
Contributor

BTW, noUnusedLocals is only available as a command line option for TypeScript. It cannot be set in tsconfig.json.

@JoshuaKGoldberg
Copy link

cannot be set in tsconfig.json

You can set it as a child of "compilerOptions":

{
  "compilerOptions": {
    "module": "esnext",
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "strict": true,
    "target": "es2017"
  }
}

@raymondfeng
Copy link
Contributor

@JoshuaKGoldberg Thanks for pointing out. If I remember correctly, we cannot override such rules in TypeScript like // tslint:disable:....

@joeytwiddle
Copy link
Contributor Author

joeytwiddle commented Feb 15, 2019

To restate the problem:

  • tslint is ignoring the setting noUnusedLocals: false in tsconfig.json
    It is still complaining about unused locals.

I finally found the solution. In tslint.json, add this rule:

"rules": {
  "no-unused": false
}

The change was documented here: 78c9d36 but I only find that now. :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants