Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

TSLint does not respect the underscore pattern for unused parameters #4505

Closed
pronebird opened this issue Feb 5, 2019 · 4 comments
Closed

Comments

@pronebird
Copy link

pronebird commented Feb 5, 2019

Bug Report

  • TSLint version: 5.12.1
  • TypeScript version: 3.x
  • Running TSLint via: CLI

Actual behavior

TSLint does not respect the underscore pattern for unused parameters.

p.s: The code below is stripped down a little to demonstrate the issue.

Take 1

Use unused parameters:

ipcRenderer.on(event, (unusedEvent: Electron.Event, newState: T) => fn(newState));

Get punched by TypeScript:

error TS6133: 'unusedEvent' is declared but its value is never read.

Take 2

Underscore the unused parameter

ipcRenderer.on(event, (_unusedEvent: Electron.Event, newState: T) => fn(newState));

Get praised by TypeScript:

$ tsc
✨ Done in 8.15s.

Take 3

Try linting the code that TypeScript is happy about:

ERROR: 297:28 variable-name variable name must be in lowerCamelCase, PascalCase or UPPER_CASE

Very cool.

with tslint.json configuration:

{
  "defaultSeverity": "error",
  "extends": [
    "tslint:latest",
    "tslint-config-prettier"
  ],
  "rules": {
    "max-classes-per-file": false,
    "object-literal-sort-keys": false
  }
}

Expected behaviour

TSLint should respect the underscore pattern for unused parameters.

@JoshuaKGoldberg
Copy link
Contributor

Hi @pronebird! Have you tried using the allow-leading-underscore option? https://palantir.github.io/tslint/rules/variable-name/

@pronebird
Copy link
Author

pronebird commented Feb 9, 2019

Hi @JoshuaKGoldberg!

Yep and it works, but I would like this pattern to be only allowed for unused parameters only. I think it makes sense because it's more of an exception. Normally we use camelCase.

@JoshuaKGoldberg
Copy link
Contributor

Gotcha (and agreed). This is a duplicate of #3442, then. +1 for allowing this!

@pronebird
Copy link
Author

Ah right, thanks! 👍

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

No branches or pull requests

2 participants