-
Notifications
You must be signed in to change notification settings - Fork 887
Add more function features #3849
Comments
Hi @seanhly, can you please make a separate issue for each rule that you would like? |
There already exists #3549 about |
-1 to a built-in preference for a single return. I find it easier to read code that has minimal nesting of conditionals. function sample(input) {
if (isInvalid(input)) {
return invalidValue;
}
const first = runFirst(input);
const last = runLast(input, first);
return processLast(last);
} |
I agree, your example looks like fine code. I think when I was writing this I was in the process of refactoring a method with dozens of exit points (not safe guards, just arbitrary return statements), and when I wanted to do something simple like "print this when the method returns", I had to edit a lot more than one line. It seems clearer to me now the problem was with long functions rather than multiple return statements. If a "single-return" rule or "max-return-statements" rule is added, some code perfectionist with quirks out there is bound to use it, which I find a little amusing. TSLint in a team project is like the code implementation of passive-aggressive behavior, and always leads to interesting debates when someone notices their favorite funky way to do something doesn't even make it past the linter to compile. But I digress, "single-return" may have no real use. |
Note: per #4534, this issue will be closed in less than a month if no PR is sent to add the rule. If you really need the rule, custom rules are always an option and can be maintained outside this repo! |
💀 It's time! 💀TSLint is being deprecated and no longer accepting pull requests for new rules. See #4534. 😱 If you'd like to see this rule implemented, you have two choices:
👋 It was a pleasure open sourcing with you! If you believe this message was posted here in error, please comment so we can re-open the issue! |
🤖 Beep boop! 👉 TSLint is deprecated 👈 (#4534) and you should switch to typescript-eslint! 🤖 🔒 This issue is being locked to prevent further unnecessary discussions. Thank you! 👋 |
The following features would be appreciated:
max-function-line-count
: A line limit for functions.Add some parameters to
max-file-line-count
so that the line count can ignore lines containing comments, or empty lines, for example.single-return
: Functions can only contain one return statement if this is set to true (some argue that long functions with multiple return statements can be hard to follow).The text was updated successfully, but these errors were encountered: