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

[naming-convention] Precedence of property selector has been changed #2860

Closed
3 tasks done
susisu opened this issue Dec 9, 2020 · 1 comment · Fixed by #2877
Closed
3 tasks done

[naming-convention] Precedence of property selector has been changed #2860

susisu opened this issue Dec 9, 2020 · 1 comment · Fixed by #2877
Labels
bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@susisu
Copy link
Contributor

susisu commented Dec 9, 2020

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have read the FAQ and my problem is not listed.

Repro

{
  "rules": {
    "@typescript-eslint/naming-convention": [
      "error",
      {
        "selector": "memberLike",
        "format": ["camelCase"]
      },
      {
        "selector": "property",
        "format": ["camelCase", "PascalCase"]
      }
    ]
  }
}
const foo = { MyProperty: 42 };

Expected Result
Because typescript-eslint 4.8.2 doesn't report error for this, I expect typescript-eslint 4.9.x also doesn't report error.

Actual Result
The following error is reported.

  1:15  error  Object Literal Property name `MyProperty` must match one of the following formats: camelCase  @typescript-eslint/naming-convention

Previously property had a higher precedence than memberLike, but it is now a meta selector and the precedence seems to be lower (ref: #2807).

I know it works as expected if I use "selector": ["classProperty", "objectLiteralProperty", "typeProperty"] instead of "selector": "property", but I report this issue because it feels like a breaking change in a minor upgrade for me.

Additional Info

Versions

package version
@typescript-eslint/eslint-plugin 4.9.1
@typescript-eslint/parser 4.9.1
TypeScript 4.1.2
ESLint 7.15.0
node 14.6.0
@susisu susisu added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for maintainers to take a look labels Dec 9, 2020
@bradzacher bradzacher added bug Something isn't working and removed triage Waiting for maintainers to take a look labels Dec 9, 2020
@bradzacher
Copy link
Member

yeah this shouldn't have changed.
It's an interesting outcome of how the numbers sum up.

By converting property and method to group selectors, they gained an equal precedence to memberLike, meaning they're ordered by numerical value.

By definition, memberLike is a | of those two selector's values (and some others), so memberLike is always going to have a larger numerical value as ofc (property | method) > property.

So we'll need to manually inflate both property and method's enum value separately from memberLike so that they can be numerically larger than it - but it must be done in such a way that the bit field doesn't overlap with an existing selector.

E.g. something like

property = property | (Max(Selectors) << 1);

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
2 participants