max-func-body-length fails to count body length correctly #468
Description
Prerequisite
I assume that the following is a 3-line function:
(): void => { // Line 1
// Line 2
} // Line 3
// I seriously think that it is an important definition. Without it, we (at least, I) can get confused. :P
Repro
git clone https://github.com/makotom/tslint-test-20180724.git
npm i
npm run lint
OR
- Write a TypeScript code having the snippet I wrote in Prerequisite above.
- Write a tslint.json and set rule
"max-func-body-length": [true, 2]
. This intends to raise an error if a function has more than 2 lines. - Run
tslint
Expected Result
An error should be raised to a function having more than 2 lines.
Actual Result
No error.
Note that the test case I've provided (which is also referred in Repro) contains a 4-line function as well, to which an error is fired as expected.
Considerations
As I wrote in my testcase, this happens because it does not add 1
to endLine - startLine
to calculate body length. I believe that it should add 1
- if not, it yields 0-line function if startLine === endLine
satisfies (e.g. (x: number): number => x + 1
).
Apparently, this can be fixed very easily. However, I found out that fixing it may break several tests which depends on error messages. I'm also afraid that the fix, which could be a single line, may break many other things. This is why I'm opning a new issue, rather than a PR, to call for discussions as the first step.