Skip to content

Bug: [member-ordering] optionalityOrder is reversed #6255

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

Closed
4 tasks done
TFohrer opened this issue Dec 20, 2022 · 1 comment · Fixed by #6256
Closed
4 tasks done

Bug: [member-ordering] optionalityOrder is reversed #6255

TFohrer opened this issue Dec 20, 2022 · 1 comment · Fixed by #6256
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

@TFohrer
Copy link

TFohrer commented Dec 20, 2022

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.8.4&sourceType=module&code=C4TwDgpgBAsiAq5oF4oG8BQUoCcIEcBXASzwBMAFHAezAC4oBnYHYgOwHMBuLKW4YtTYBDADZVaAfgbNWnHgF8gA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6AW0XYCNFpaA9tAAmfZgHN0YANrhsOPtCGQANHPnysGnEVIAZSvj4BDeKgxbtOATUoCmpw4QDyIvlJiIAjrErREwrQAZn7I+JDqVhAAvpHasdoAunKx0UA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA

Repro Code

type MyType = {
  requiredProp: string;
  optionalProp?: string;
}

ESLint Config

module.exports = {
  parser: "@typescript-eslint/parser",
  "rules": {
    "@typescript-eslint/member-ordering": [
      "error",
          {
        "typeLiterals": {
          "optionalityOrder": "required-first"
          }
          }
      ]
  }
};

tsconfig

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

Expected Result

I expect no error when the requiredProp is the first item.
I expect an error when the requiredProp is not the first item.

Actual Result

Error is shown when requiredProp is first item:

Member requiredProp should be declared after all optional members. 2:3 - 2:24

Additional Info

Seems like in the implementation the result for the optionalOrRequired condition is reversed:
https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/rules/member-ordering.ts#L784

@TFohrer TFohrer added bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look labels Dec 20, 2022
@TFohrer
Copy link
Author

TFohrer commented Dec 20, 2022

Maybe @asdf93074 can you check this.

@JoshuaKGoldberg JoshuaKGoldberg added accepting prs Go ahead, send a pull request that resolves this issue and removed triage Waiting for team members to take a look labels Dec 20, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 28, 2022
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
2 participants