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.

Have 'func-name-matching' ignore defineProperty function values by default

See original GitHub issue

What rule do you want to change?

func-name-matching

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 default behavior where we allow { value } property descriptor a different name than value.

Please provide some example code that this change will affect:

var model = {};

Object.defineProperty(model, 'key', {
  value: function key() {
    //
  }
});

console.log(model.key.name); // logs 'key'

What does the rule currently do for this code?

Function name key should match property name value

What will the rule do after it’s changed?

No error.

Issue Analytics

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

github_iconTop GitHub Comments

4reactions
platinumazurecommented, Jan 5, 2017

Thanks @ljharb, your point is well taken.

Let’s step back a bit and just follow our process. If the team champions and endorses not only the standard property-descriptor functions, but also user-configurable ones, then that’s what we’ll implement. If the team champions and endorses just the standard property-descriptor functions, then we’ll implement that instead and we can re-evaluate later if we get more demand for customizability. (And until that point, @ljharb can certainly create a custom rule for his use case.)

I’m 👍 for the standard property descriptor functions for sure-- it should be fairly easy to do. I’m not outright opposed to customizations, but I’m not yet convinced we have enough demand from the community just yet.

3reactions
mysticateacommented, Oct 23, 2016

Sounds reasonable to me.

Object.defineProperty(model, 'foo', {
  value: function foo() {
    //
  },
  enumerable: true,
  configurable: true,
  writable: true
});

This is same as

model.foo = function foo() {
    //
};

The function foo is the value of model.foo. Also, function value in the stacktrace is not helpful to developers. value does not express what the function is. It should be foo. So I think the rule should enforce the name to foo rather than value.

Object.defineProperty(model, 'foo', {
    value: function value() {  //※ Function name `value` should match property name `foo`.
        //
    }
});

Object.defineProperties(model, {
    foo: {
        value: function value() {  //※ Function name `value` should match property name `foo`.
            //
        }
    }
});

Object.defineProperty(model, 'foo', {
    value: function foo() {  //※ OK
        //
    }
});

Object.defineProperties(model, {
    foo: {
        value: function foo() {  //※ OK
            //
        }
    }
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

func-name-matching - ESLint - Pluggable JavaScript Linter
This rule requires function names to match the name of the variable or property to which they are assigned. The rule will ignore...
Read more >
Why is it possible to omit default values in overridden member ...
Declare in both, allow subtype to override the default in the supertype. ... function is not allowed to specify default values for its...
Read more >
Default parameters - JavaScript - MDN Web Docs
Default function parameters allow named parameters to be initialized with default values if no value or undefined is passed.
Read more >
func-name-matching - Rules - ESLint中文文档
要求函数名与赋值给它们的变量名或属性名相匹配(func-name-matching). Rule Details. This rule requires function names to match the name of the variable ...
Read more >
Understanding Default Parameters in JavaScript - DigitalOcean
These allow developers to initialize a function with default values if the arguments are not supplied to the function call.
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