microsoft/tslint-microsoft-contrib

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

karol-majewski opened this issue ยท 2 comments

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.

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.

๐Ÿ’€ 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!