Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

react-unused-props-and-state doesn't count actual usages #879

Closed
karol-majewski opened this issue Jun 13, 2019 · 2 comments
Closed

react-unused-props-and-state doesn't count actual usages #879

karol-majewski opened this issue Jun 13, 2019 · 2 comments
Labels
Difficulty: Hard Only someone with heavy experience in TSLint should be able to send a pull request for this issue. 💀 R.I.P. 💀 Status: Accepting PRs Type: Bug

Comments

@karol-majewski
Copy link

Bug Report

  • tslint-microsoft-contrib version: 6.2.0
  • TSLint version: 5.17.0
  • TypeScript version: 3.5.1
  • Running TSLint via: (pick one) Visual Studio Code

TypeScript code being linted

import * as React from 'react';

declare const Avatar: React.FC<{ name: string; label: number }>;

interface Props {
  name: string;
  age: number;
}

const User: React.FunctionComponent<Props> = ({ name }) =>
  <Avatar name={name} label={42} />;

const Client: React.FunctionComponent<Props> = ({ age }) =>
  <Avatar name="Bob" label={age} />;

with tslint.json configuration:

{
  "rules": {
    "react-unused-props-and-state": [
      true,
      {
        "props-interface-regex": "Props$",
        "state-interface-regex": "State$"
      }
    ]
  }
}

Actual behavior

No error.

Expected behavior

There should be errors for both components. Neither of them uses all props it's given. From the Props interface perspective everything is okay (all props are referenced), but from the component's perspective, some props are unused.

@JoshuaKGoldberg
Copy link

Ha, yes, this rule is a bit of a pain. Accepting PRs but be warned it's pretty hairy!

Some good backing discussion: #416, #796, #824, #864.

@JoshuaKGoldberg JoshuaKGoldberg added Difficulty: Hard Only someone with heavy experience in TSLint should be able to send a pull request for this issue. Status: Accepting PRs Type: Bug labels Jun 15, 2019
@JoshuaKGoldberg
Copy link

💀 It's time! 💀

TSLint is being deprecated; therefore, it and tslint-microsoft-contrib are no longer accepting pull requests for major new changes or features. See palantir/tslint#4534. 😱

If you'd like to see this change implemented, you have two choices:

  • Recommended: Check if this is available in ESLint + typescript-eslint
  • Not Recommended: Fork TSLint or tslint-microsoft-contrib locally 🤷‍♂️

👋 It was a pleasure open sourcing with you!

If you believe this message was posted here in error, please comment so we can re-open the issue!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Difficulty: Hard Only someone with heavy experience in TSLint should be able to send a pull request for this issue. 💀 R.I.P. 💀 Status: Accepting PRs Type: Bug
Projects
None yet
Development

No branches or pull requests

2 participants