Skip to content
This repository was archived by the owner on Jul 15, 2023. It is now read-only.
This repository was archived by the owner on Jul 15, 2023. It is now read-only.

max-func-body-length fails to count body length correctly  #468

Closed
@makotom

Description

@makotom

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

  1. git clone https://github.com/makotom/tslint-test-20180724.git
  2. npm i
  3. npm run lint

OR

  1. Write a TypeScript code having the snippet I wrote in Prerequisite above.
  2. 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.
  3. 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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions