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

react-bind-this-issue doesn't detect bind decorators defined after usage #813

Closed
microsoft/rushstack
#1802
@cyberhck

Description

@cyberhck

Bug Report

  • tslint-microsoft-contrib version: latest
  • TSLint version: latest
  • TypeScript version: latest
  • Running TSLint via: (pick one) CLI

In PR #534 , I introduced a feature, but it contains a missing feature A.K.A 🐛

It does half the work, it only detects bound methods above usage, and not the ones below usages.

TypeScript code being linted

class Component extends React.Component {
    public render(): JSX.Element {
        return (
            <button onClick={this.handleClick}></button>
        );
    }
    @autobind
    private handleClick(): void {
        console.info("clicked");
    }
}

with tslint.json configuration:

{
  "rules": {
    "react-this-binding-issue": [true, {"bind-decorators": ["autobind"]}]
  }
}

Actual behavior

Shouldn't report violation

Expected behavior

Reports violation

However the same code works if I do something like this:

class Component extends React.Component {
    @autobind
    private handleClick(): void {
        console.info("clicked");
    }
    public render(): JSX.Element {
        return (
            <button onClick={this.handleClick}></button>
        );
    }
}

Difference is that the method went up.

And I know what happened.

On the source code for react-this-binding-issue we're looking for method definitions, and JSX tags, and when we see methods, we push it to array if it's bound, but that method isn't encountered yet, it isn't listed in the bound methods, hence it'll report violation.

I don't know how I missed this when I created this PR and looks like no one has noticed till now 😄

Any suggestions are welcome, if I find some free time, I'll try to come up with a solution.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Difficulty: EasySomeone with little to no experience in TSLint should be able to send a pull request for this issue.Status: Accepting PRsType: Bug

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions