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.
- Widely applicable: ✓
- Generic: ✓
- Atomic: ✓
- Unique: ✓
- Library agnostic: ~
- 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:
- Created 7 years ago
- Comments:7 (4 by maintainers)
Top GitHub Comments
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
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.