question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Include function name in report message if possible / relevant

See original GitHub issue

I have these two warning about the same function in my code.

  • complexity Function ‘formatLog’ has a complexity of 12.
  • max-statements This function has too many statements (25). Maximum allowed is 16.

Notice that the latter says This function, where the former says Function 'formatLog'. This named notation I find really helpful.

I did a quick search in the rules and found a few more mentioning a function that could potentially be named.


What rule do you want to change?

  • array-callback-return
  • complexity
  • consistent-return
  • func-names
  • max-params
  • max-statements
  • no-empty-functions
  • strict

I excluded

1. rules where the function should not be the focus of the feedback message. Eg. no-dupe-args gives Duplicate param '{{name}}'. Since we already name the param, I don’t find it more useful to include a named function as well.

2. rules regarding function calls (Eg. func-call-spacing)

3. deprecated rules

Does this change cause the rule to produce more or fewer warnings?

Same.

How will the change be implemented?

  1. this program if global return
  2. ${getFunctionNameWithKind(node)} if function

array-callback-return

Before

Expected to return a value at the end of this function.

Expected to return a value in this function.

Expected a return value.

After

Expected to return a value at the end of ${getFunctionNameWithKind(node)}.

Expected to return a value in ${getFunctionNameWithKind(node)}.

${getFunctionNameWithKind(node)} expected a return value.

complexity

Before

Function ‘{{name}}’ has a complexity of {{complexity}}.

After

${getFunctionNameWithKind(node)} has a complexity of {{complexity}}.

consistent-return

Before

Expected {{which}} return value.

Expected to return a value at the end of this {{type}}.

After

${getFunctionNameWithKind(node)} expected {{which}} return value.

Expected to return a value at the end of ${getFunctionNameWithKind(node)}.

func-names

Before

Unexpected function expression name.

After

Unexpected named ${getFunctionNameWithKind(node)}.

max-params

Before

This function has too many parameters ({{count}}). Maximum allowed is {{max}}.

After

${getFunctionNameWithKind(node)} has too many parameters ({{count}}). Maximum allowed is {{max}}.

max-statements

Before

This function has too many statements ({{count}}). Maximum allowed is {{max}}.

After

${getFunctionNameWithKind(node)} has too many statements ({{count}}). Maximum allowed is {{max}}.

no-empty-functions

Before

Unexpected empty {{kind}}.

After

Unexpected empty ${getFunctionNameWithKind(node)}.

strict

Before

Wrap this function in a function with ‘use strict’ directive.

After

Wrap ${getFunctionNameWithKind(node)} in a function with ‘use strict’ directive.

CHANGELOG

  • 30/12
    • Added ${getFunctionNameWithKind(node)}.
    • Rewrote func-names feedback message.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:5
  • Comments:17 (17 by maintainers)

github_iconTop GitHub Comments

2reactions
platinumazurecommented, Oct 3, 2016

Looks good to me! (I prefer “this function” over “function ‘anonymous’” in the unlikely event someone uses “anonymous” as a function name.)

1reaction
platinumazurecommented, Sep 27, 2016

I like the idea. That said, since we are also discussing a rule change elsewhere about using a function’s inferred name to suppress warnings, I would like to make sure we consolidate all that logic in one place (ast-utils maybe?).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python Logging (function name, file name, line number) using ...
This will log the message passed in, plus the (original) function name, the filename in which the definition appears, and the line in...
Read more >
Function.prototype.name - JavaScript - MDN Web Docs
The name property of a Function instance indicates the function's name as specified when it was created, or it may be either anonymous...
Read more >
Use parameters in queries, forms, and reports
This article explains how to use forms in Access to enhance your use of parameters in queries, forms, and reports.
Read more >
Using Lambda with Amazon SQS - AWS Documentation
Use a Lambda function to process messages from an Amazon SQS queue. ... If messages are still available, Lambda increases the number of...
Read more >
XSL Transformations (XSLT) Version 3.0 - W3C
It will be very helpful if you include the string “[XSLT30]” in the ... 10.3.1 Function Name and Arity; 10.3.2 Arguments; 10.3.3 Function...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found