Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: [unbound-method] Does not fail for destructured parameters #8947

Open
4 tasks done
steverep opened this issue Apr 18, 2024 · 3 comments · May be fixed by #8952
Open
4 tasks done

Bug: [unbound-method] Does not fail for destructured parameters #8947

steverep opened this issue Apr 18, 2024 · 3 comments · May be fixed by #8952
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@steverep
Copy link

Before You File a Bug Report Please Confirm You Have Done The Following...

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have searched for related issues and found none that matched my issue.
  • I have read the FAQ and my problem is not listed.

Playground Link

https://typescript-eslint.io/play/#ts=5.4.3&fileType=.ts&code=MYGwhgzhAEAKD2ECWAXJ8B20DeBYAUNNAMQAe0AvNAAwDcBRxAnpTffg9KQBQCUO0TkQBOAUxQBXYVhQALJBAB0ZdkQC%2BBTkz44h0MZOnQ5C5U1XQN%2BKwQBmEjMDSZot%2BPG4AHAIwAuOIio6BgANAKk-qQATGFM-kxRlv4IyM4Y-HiE0MCYECjhkd6x8d6WrD4WBlJYANqk3joA1FxRfLEN-M0JfAC67FZAA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6WJgIwHsOATWgFtE%2BABbc%2B6KImjRu0SODABfEMqA&tsconfig=&tokens=false

Repro Code

class Position {
  #x = 0;
  #y = 0;

  x() { 
    return this.#x;
  }

  y() {
    return this.#y;
  }
}

function foo(p1: Position, { x: x2, y: y2 }: Position) {
  const { x: x1, y: y1 } = p1;
  return [x1() + x2(), y1() + y2()];
}

ESLint Config

module.exports = {
  "rules": {
    "@typescript-eslint/unbound-method": "error"
  }
}

tsconfig

{
  "compilerOptions": {
    // ...
  }
}

Expected Result

I expect the rule to fail when destructuring x2 and y2 in the second function parameter.

Actual Result

There are errors when destructuring x1 and y1 in the function body as expected, but no error for the equivalent code within the function parameter.

Additional Info

No response

@steverep steverep added bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for maintainers to take a look labels Apr 18, 2024
@kirkwaiblinger
Copy link
Member

To be clear, this is what you want to happen, right?:

type HasMethod = { method(): void };
// actual
function f({ method }: HasMethod) {
}
// expected
function f({ method }: HasMethod) {
             ^^^^^^
}

@steverep
Copy link
Author

Yes, that destructured assignment should trigger the rule the same way as if it were destructured in the body.

@kirkwaiblinger
Copy link
Member

Awesome, thanks for the report! Seems like a bug to me as well.

Looking at past work it looks like this was probably just a simple oversight when the code was added that handles other cases of destructuring (#2228). Might be as simple as adding ObjectPattern to the rule.

@kirkwaiblinger kirkwaiblinger added accepting prs Go ahead, send a pull request that resolves this issue and removed triage Waiting for maintainers to take a look labels Apr 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
2 participants