Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

Add more function features #3849

Closed
ghost opened this issue Apr 23, 2018 · 7 comments
Closed

Add more function features #3849

ghost opened this issue Apr 23, 2018 · 7 comments

Comments

@ghost
Copy link

ghost commented Apr 23, 2018

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).

@johnwiseheart
Copy link
Contributor

Hi @seanhly, can you please make a separate issue for each rule that you would like?

@thorn0
Copy link

thorn0 commented May 1, 2018

There already exists #3549 about max-function-line-count / max-func-body-length.

@JoshuaKGoldberg
Copy link
Contributor

single-return

-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);
}

@ghost
Copy link
Author

ghost commented Oct 3, 2018

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.

@JoshuaKGoldberg
Copy link
Contributor

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!

@JoshuaKGoldberg
Copy link
Contributor

💀 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!

@JoshuaKGoldberg
Copy link
Contributor

🤖 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! 👋

@palantir palantir locked and limited conversation to collaborators Mar 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants