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: object-shorthand loses type parameters when auto-fixing #18429

Closed
1 task
aldeed opened this issue May 7, 2024 · 1 comment · Fixed by #18438
Closed
1 task

Bug: object-shorthand loses type parameters when auto-fixing #18429

aldeed opened this issue May 7, 2024 · 1 comment · Fixed by #18438
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion bug ESLint is working incorrectly repro:needed

Comments

@aldeed
Copy link

aldeed commented May 7, 2024

Environment

Node version: v18.19.0
npm version: v10.7.0
Local ESLint version: v8.57.0 (Currently used)
Global ESLint version: Not found
Operating System: darwin 23.4.0

What parser are you using?

@typescript-eslint/parser

What did you do?

Configuration
module.exports = {
  parser: "@typescript-eslint/parser",
  rules: {
    "object-shorthand": [
      "error",
      "always",
      { avoidExplicitReturnArrows: true },
    ],
  },
};

Run auto-fix on this:

const testObj = {
  myMethod: <T>(obj: T): T => {
    return obj;
  },
};

What did you expect to happen?

const testObj = {
  myMethod<T>(obj: T): T {
    return obj;
  },
};

What actually happened?

const testObj = {
  myMethod(obj: T): T {
    return obj;
  },
};

Link to Minimal Reproducible Example

https://typescript-eslint.io/play/#ts=5.4.5&fileType=.ts&code=MYewdgzgLgBFCm0DyAjAVjAvDA3gKBhgFsBPAWXigAsQATALhgB4AVAPgAoR1GWBKXlja4ChGACdKAV3FgY3NAG5RAXwA0eFcqA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQPYCMArRAYwBcBaZAC12jOoEMA7AE3TAG1xsdFpodSABoevSI3gB3RgE9Uo3hCxKcjAG64AlqwCiADwAO8LSS1kASojKxozAIIDcU1BjJxEY7AF8vAXR5fbyA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false

Participation

  • I am willing to submit a pull request for this issue.

Additional comments

First reported here.

@aldeed aldeed added bug ESLint is working incorrectly repro:needed labels May 7, 2024
@nzakas nzakas self-assigned this May 8, 2024
@nzakas nzakas added the accepted There is consensus among the team that this change meets the criteria for inclusion label May 8, 2024
@nzakas
Copy link
Member

nzakas commented May 8, 2024

Thanks for the report. I think we can tweak the rule to fix this.

@nzakas nzakas removed their assignment May 8, 2024
shulaoda added a commit to shulaoda/eslint that referenced this issue May 10, 2024
shulaoda added a commit to shulaoda/eslint that referenced this issue May 12, 2024
aladdin-add pushed a commit that referenced this issue May 16, 2024
* fix: object-shorthand loses type parameters when auto-fixing

Fixes #18429

* refactor: remove special astUtils feature

* refactor: judge the first token and use it's index

* style: remove unnecessary condition

* test: update test fixture

* fix: modify the logic to support special test case

* refactor: follow very nice code advice
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion bug ESLint is working incorrectly repro:needed
Projects
Status: Complete
Development

Successfully merging a pull request may close this issue.

2 participants