Closed
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
interface Broken {
b: number;
a: number;
}
interface Works {
b: number;
a: number;
o?: number;
}
ESLint Config
module.exports = {
parser: "@typescript-eslint/parser",
rules: {
"@typescript-eslint/<rule-name>": ["error", {
"interfaces": {
"optionalityOrder": "required-first",
"order": "natural-case-insensitive"
}
}
},
};
tsconfig
Expected Result
In interface "Broken", an error should be shown because the members are not sorted
Actual Result
No error is shown
Additional Info
I believe the problem is at packages/eslint-plugin/src/rules/member-ordering.ts:875
const switchIndex = members.findIndex(
(member, i) =>
i && isMemberOptional(member) !== isMemberOptional(members[i - 1]),
);
if (switchIndex !== -1) {
if (!checkRequiredOrder(members, optionalityOrder)) {
return;
}
checkOrder(members.slice(0, switchIndex));
checkOrder(members.slice(switchIndex));
}
If no optional members are found, the rule does nothing. So the else case is missing:
// ...
checkOrder(members.slice(0, switchIndex));
checkOrder(members.slice(switchIndex));
}
else {
checkOrder(members);
}