microsoft / tslint-microsoft-contrib

A set of TSLint rules used on some Microsoft projects.
MIT License
702 stars 198 forks source link

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

Closed karol-majewski closed 5 years ago

karol-majewski commented 5 years ago

Bug Report

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 commented 5 years ago

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 commented 5 years ago

💀 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 https://github.com/palantir/tslint/issues/4534. 😱

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

👋 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!