-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Closed
Labels
accepting prsGo ahead, send a pull request that resolves this issueGo ahead, send a pull request that resolves this issuebugSomething isn't workingSomething isn't workingpackage: eslint-pluginIssues related to @typescript-eslint/eslint-pluginIssues related to @typescript-eslint/eslint-plugin
Description
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
Repro Code
class Foo {
#bar: string;
get bar(): string {
return this.#bar;
}
set bar(value: string) {
this.#bar = value;
}
}
ESLint Config
module.exports = {
"rules": {
"@typescript-eslint/member-ordering": [
"warn",
{
"default": {
"memberTypes": [
["get", "set"]
],
"order": "natural"
}
}
]
}
}
tsconfig
Expected Result
No error or warning reported
Actual Result
Error/ warningwith the following message is reported:
Member bar should be declared before member bar. 8:3 - 10:4
Additional Info
This happens when there are member with the same name, for example with getters and setters:
get bar(): string {}
set bar(value: string) {}
I've tried looking at the source code:
typescript-eslint/packages/eslint-plugin/src/rules/member-ordering.ts
Lines 809 to 826 in 32c807b
function naturalOutOfOrder( | |
name: string, | |
previousName: string, | |
order: AlphabeticalOrder, | |
): boolean { | |
switch (order) { | |
case 'alphabetically': | |
return name < previousName; | |
case 'alphabetically-case-insensitive': | |
return name.toLowerCase() < previousName.toLowerCase(); | |
case 'natural': | |
return naturalCompare(name, previousName) !== 1; | |
case 'natural-case-insensitive': | |
return ( | |
naturalCompare(name.toLowerCase(), previousName.toLowerCase()) !== 1 | |
); | |
} | |
} |
It seems the logic for natural
and natural-case-insensitive
ordering is slightly different than the alphabetically*
ordering.
And with the case of name
and previousName
are the same, alphabetically*
order will returns false
while natural*
order will returns true (0 !== 1)
omril1JoshuaKGoldberg
Metadata
Metadata
Assignees
Labels
accepting prsGo ahead, send a pull request that resolves this issueGo ahead, send a pull request that resolves this issuebugSomething isn't workingSomething isn't workingpackage: eslint-pluginIssues related to @typescript-eslint/eslint-pluginIssues related to @typescript-eslint/eslint-plugin