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: [sort-type-constituents] Auto-fix can change behavior #6339

Closed
4 tasks done
ersimont opened this issue Jan 14, 2023 · 0 comments · Fixed by #6384
Closed
4 tasks done

Bug: [sort-type-constituents] Auto-fix can change behavior #6339

ersimont opened this issue Jan 14, 2023 · 0 comments · Fixed by #6384
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

@ersimont
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=4.9.3&sourceType=module&code=C4TwDgpgBAQgTgewNYQHYB4AqA+KBeAWACgooAfKACkyggA9g0ATAZylQFcBbAIwjigB+KAHIAFgEsRUAFyjgY-hBEBKYqQotgcCagDmAbmJA&eslintrc=N4KABGBEBOCuA2BTAzpAXGYUACAXAngA4oDG0AlobgLQrzkB2uA9MgPbQ0HHUlsPJc5XLERNUGANqRE0aB0gBdMAF8QKoA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA

Repro Code

type Broken<T> =
  | (T extends number ? 'hi' : 'there')
  | string;

ESLint Config

module.exports = {
  parser: "@typescript-eslint/parser",
  rules: {
    "@typescript-eslint/<rule-name>": ["error", ...<options>],
  },
};

tsconfig

{
  "compilerOptions": {}
}

Expected Result

When using "fix", I expect it to keep the same semantics of the code. This might include keeping the () around the T extends clause.

Also I expect the "fix" to be stable, so that it no longer reports an error.

Actual Result

It fixes to this, which changes the meaning of the code:

type Broken<T> =
  string | T extends number ? 'hi' : 'there';

Also, it still complains about the order. If you fix again it changes to

type Broken<T> =
  T | string extends number ? 'hi' : 'there';

Additional Info

I don't know/care what order it sorts to, as long as it doesn't break my code! 🙂

@ersimont ersimont 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 Jan 14, 2023
@bradzacher bradzacher added accepting prs Go ahead, send a pull request that resolves this issue and removed triage Waiting for maintainers to take a look labels Jan 14, 2023
sviat9440 pushed a commit to MillerSvt/typescript-eslint that referenced this issue Jan 29, 2023
sviat9440 pushed a commit to MillerSvt/typescript-eslint that referenced this issue Jan 29, 2023
sviat9440 added a commit to MillerSvt/typescript-eslint that referenced this issue Jan 29, 2023
JoshuaKGoldberg pushed a commit that referenced this issue Jan 31, 2023
…6384)

fix(sort-type-constituents): Fixed behavior change when sorting TSConditionalType (#6339)
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
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
Development

Successfully merging a pull request may close this issue.

2 participants