Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds mocha-aware prefer-arrow-callback rule #163

Conversation

quarklemotion
Copy link

@quarklemotion quarklemotion commented Jun 16, 2018

Addresses #141


  • Copied core eslint prefer-arrow-callback rule code, test code, and markdown doc from: https://github.com/eslint/eslint/blob/master/docs/rules/prefer-arrow-callback.md
  • Modified this rule to be mocha-aware by utilizing the existing utility function astUtils.isMochaFunctionCall(node, scope)
  • Updated tests to include rule not triggered tests for all mocha functions
  • Updated documentation to include instructions to disable the core prefer-arrow-callback rule before enabling the mocha/prefer-arrow-callback rule

The following eslint rules are failing with this code:

/Users/mfields/workspace/eslint-plugin-mocha/lib/rules/prefer-arrow-callback.js
   90:1   error  Function 'getCallbackInfo' has a complexity of 12                                     complexity
   90:1   error  Function 'getCallbackInfo' has too many statements (13). Maximum allowed is 10        max-statements
  251:38  error  Method 'FunctionExpression:exit' has a complexity of 16                               complexity
  251:38  error  Method 'FunctionExpression:exit' has too many statements (14). Maximum allowed is 10  max-statements
  290:28  error  Method 'fix' has a complexity of 9                                                    complexity
  290:28  error  Method 'fix' has too many statements (11). Maximum allowed is 10                      max-statements

It looks like it will take some substantial work to get this code in line with the complexity limit of 4. I think it would be preferable to not completely rewrite this rule so that updates from the core eslint prefer-arrow-callback rule can be applied more easily here in the future. Would the maintainers here be open to a rule-specific relaxing of the complexity and max-statements eslint rules (now included in code changes)?

Copy link
Owner

@lo1tuma lo1tuma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work, LGTM 👍.
Also the reasoning for relaxing some eslint rules in this specific file makes sense.

@lo1tuma lo1tuma added the feature label Jul 6, 2018
@lo1tuma lo1tuma merged commit c61955a into lo1tuma:master Jul 6, 2018
@quarklemotion quarklemotion deleted the quarklemotion/add-mocha-aware-prefer-arrow-callback branch July 13, 2018 03:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants