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

Recommended max-func-body-length rule ignores functions named /.+describe.+/ as well #465

Closed
makotom opened this issue Jul 23, 2018 · 2 comments
Labels
Difficulty: Easy Someone with little to no experience in TSLint should be able to send a pull request for this issue. Good First Issue 🙌 Howdy, neighbor! Type: Rule Feature Adding a feature to an existing rule.
Milestone

Comments

@makotom
Copy link
Contributor

makotom commented Jul 23, 2018

Repro

I've prepared a easy-to-start test case. Clone the package, run npm i, and then npm run lint.

OR

  1. Write a TypeScript code in which xyzdescribexyz is called with a 101-line arrow function as a parameter.
  2. Run tslint with "tslint-microsoft-contrib" rules.

Expected result

"Max arrow function body length exceeded" error should be raised at the point calling xyzdescribexyz.

Actual result

No error for xyzdescribexyz.
Note that the test case I provided also includes a test for describ, to which an error is raised as expected.

Considerations

This happens because the current recommended options for max-func-body-length rule sets "ignore-parameters-to-function-regex" to "describe". Therefore, functions whose name matches /.+describe.+/ (I mean not only /^describe$/) will be ignored for this rule by default.

I recognize that this option is set not to raise errors for describe() in Mocha (indeed it is stated that "this can be useful for Mocha users to ignore the describe() function" in README), and I personally think the intention itself is rational. However, since the given rule matches functions other than describe(), which is not a good idea, I would propose to change the recommended value to a stricter one, such as /^describe$/.

@JoshuaKGoldberg
Copy link

Hi @makotom - thanks for such a detailed issue! The problem and solution as you've stated them seem reasonable. I'd love to see a pull request adding them in!

@JoshuaKGoldberg JoshuaKGoldberg added Good First Issue 🙌 Howdy, neighbor! Difficulty: Easy Someone with little to no experience in TSLint should be able to send a pull request for this issue. Type: Rule Feature Adding a feature to an existing rule. labels Jul 23, 2018
@makotom
Copy link
Contributor Author

makotom commented Jul 24, 2018

@JoshuaKGoldberg, thank you for your prompt response!

I'm preparing a pull request, but since I found another issue #468 and it needs this insane hack, I am suspending to post a PR.
Once #468 has got fixed, or if the test is unrequired, I would like to go with PR. :)

JoshuaKGoldberg pushed a commit that referenced this issue Jul 26, 2018
* Proposed fix for issue #465

* Revised tests for the fix of #465
@JoshuaKGoldberg JoshuaKGoldberg added this to the 5.1.1 milestone Aug 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Difficulty: Easy Someone with little to no experience in TSLint should be able to send a pull request for this issue. Good First Issue 🙌 Howdy, neighbor! Type: Rule Feature Adding a feature to an existing rule.
Projects
None yet
Development

No branches or pull requests

2 participants