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.

`func-names` error on "inferrable names"

See original GitHub issue

Hi, Excuse me for bringing issue #7235 up again, but why Foo.prototype.bar = function() {}; is incorrect when using the as-needed option? while I understand that the function’s name property would be empty, in callstacks this function will have the name Foo.bar, and I think this goes along with the TSC decision of “see the rule as ensuring names are present for debugging”. Also this is the behavior of JSCS requireNamedUnassignedFunctions (which is actually what I’m trying to restore)… Thx

— EDIT — I propose a rule change for func-names to have option to error only for unassigned functions, I am not sure whether this should be a change or a whole new rule.

What rule do you want to change? func-names

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

How will the change be implemented? (New option, new default behavior, etc.)? New option

Please provide some example code that this change will affect: Currently func-names require all function expressions to have names, even if the name can be inferred from the context. The new option will enforce the rule only if the function is unassigned, like callbacks:

setTimeout(function() {
    throw new Error('I am truly anonymous');
}, 1000);

The code below is currently “incorrect” using the func-names rule, adding an option (say: unassigned-only) will make it “correct”

function Foo() {}
Foo.prototype.baz = function() {
    throw new Error('I am not so anonymous, at least V8 knows who I am');
};

What does the rule currently do for this code? Errors - saying a name is required

What will the rule do after it’s changed? Will not error.

As I said, maybe a new rule is more appropriate here (I am currently using a custom rule I wrote to achieve that, can use it as a base for a new rule).

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:18 (11 by maintainers)

github_iconTop GitHub Comments

2reactions
ValYouWcommented, Jul 1, 2017

In case anyone is interested in JSCS requireNamedUnassignedFunctions behavior I created an ESLint plugin: https://github.com/ValYouW/eslint-plugin-named-unassigned-functions

1reaction
loganfsmythcommented, Dec 11, 2016

@ljharb That form doesn’t get an inferred names in the ES6 spec AFAIK.

Read more comments on GitHub >

github_iconTop Results From Across the Web

func-names - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >
Warning Unexpected unnamed function func-names under ...
These are two different issues… Unexpected unnamed function. This is, as pointed out by Constantin, the ESLint rule func-names.
Read more >
How to correct a #NAME? error - Microsoft Support
Important: The #NAME? error signifies that something needs to be corrected in the syntax, so when you see the error in your formula,...
Read more >
func-names - Rules - ESLint中文文档
/*eslint func-names: ["error", "always"]*/ Foo.prototype.bar = function() {}; (function() { // ... }()). Examples of correct code for this rule with the ...
Read more >
SQL0440N returned using table function ... - IBM
It is possible to recieve error SQL0440n on a routine like ... syscat.functions where funcname='function name in question' order by 1,2";.
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