question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue
"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.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
benjaminbilletcommented, Jan 27, 2017

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

0reactions
ilyavolodincommented, May 18, 2016

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Rule Proposal: max-lines · Issue #6078 · eslint/eslint - GitHub
This rule will disallow that a file gets the number of lines more than the ... Rule Proposal: func-body-max-length or func-body object #6146....
Read more >
SEC Proposed Rules
SEC Proposed Rules · Regulation NMS: Minimum Pricing Increments, Access Fees, and Transparency of Better Priced Orders · File No: S7-30-22 · Comments...
Read more >
OCC Proposes Rule to Clarify "Valid When Made" Doctrine
This proposal will address confusion about the effect of a transfer on a loan's valid interest rate, including confusion resulting from a recent ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found