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

Rule Proposal: func-body-max-length or func-body object #6146

Closed
Mouvedia opened this issue May 12, 2016 · 7 comments
Closed

Rule Proposal: func-body-max-length or func-body object #6146

Mouvedia opened this issue May 12, 2016 · 7 comments
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion feature This change adds a new feature to ESLint rule Relates to ESLint's core rules

Comments

@Mouvedia
Copy link

Mouvedia commented May 12, 2016

"func-body-max-length": [1, 600] // max characters

// or (if we are adding other related properties)

"func-body": [1, {
    "max-length": 600,
    "max-line": 42,
}]

It's principally geared towards performance in Node.js: 50% boost is non-negligeable.
cf https://medium.com/@borismcr/this-is-a-good-candidate-for-an-eslint-plugin-5cb3d6b96f93#.3b00geo6f

But it could also be useful to alert the programmer that a function is too big.
Concerning the max-line property, Iv seen schools enforcing 25 lines per function in the C course.

  1. Widely applicable: ✓
  2. Generic: ✓
  3. Atomic: ✓
  4. Unique: ✓
  5. Library agnostic: ~
  6. No conflicts: ✓

In the same way as max-len, the max-length rule

calculates the length of a line via code points, not characters. That means if you use a double-byte character in your code, it will count as 2 code points instead of 1, and 2 will be used to calculate line length. This is a technical limitation of JavaScript that is made easier with ES2015, and we will look to update this when ES2015 is available in Node.js.

@eslintbot eslintbot added the triage An ESLint team member will look at this issue soon label May 12, 2016
@mysticatea mysticatea added rule Relates to ESLint's core rules feature This change adds a new feature to ESLint evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion and removed triage An ESLint team member will look at this issue soon labels May 13, 2016
@mysticatea
Copy link
Member

mysticatea commented May 13, 2016

Thank you for this issue.

At first, we are not accepting rules for the performance of a specific platform. Such rules are proper as plugins.

Also, I don't think we need this rule in core because we already have several rules for function-size: complexity, max-statements, etc.

@ilyavolodin
Copy link
Member

Agree. I think this is better as plugin.

@Mouvedia
Copy link
Author

#6078 is related as well.

@Mouvedia Mouvedia changed the title func-body-max-length or func-body object Rule proposal: func-body-max-length or func-body object May 13, 2016
@Mouvedia Mouvedia changed the title Rule proposal: func-body-max-length or func-body object Rule Proposal: func-body-max-length or func-body object May 13, 2016
@alberto
Copy link
Member

alberto commented May 14, 2016

Agree it's a better fit for a custom rule, but not in core.

@Mouvedia
Copy link
Author

Mouvedia commented May 18, 2016

There are already 3 rules covering func-body-max-length:

@ilyavolodin
Copy link
Member

It looks like v8-func-inline is exactly what you are looking for. Since it already exists as a plugin, that is easily installable, I'm going to close this issue, because I don't think those types of specialized rules are a good fit for the core. If you disagree, please feel free to reopen.

@benjaminbillet
Copy link

Hi all,

Limiting the size of a function can be a good practice, like limiting file lengths (max-lines), line lengths (max-len), callback depth (max-nested-callbacks) or block depth (max-depth). In everyday work, I often encounter large functions in JS projects (more than 200 lines). Such functions can be very difficult to understand.

I think that a func-body-max-length should be part of the core rules, as any best practice rule.

Thanks

@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Feb 6, 2018
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Feb 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion feature This change adds a new feature to ESLint rule Relates to ESLint's core rules
Projects
None yet
Development

No branches or pull requests

6 participants