Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ReSharper warnings for JavaScript naming convention on constructor functions

In JavaScript, I like the naming convention of PascalCase for constructor functions and camelCase for other functions. It looks like ReSharper is configured for these settings. However, for code like this:

function Thing(a, b) {
    return {
        prop1: a,
        prop2: b
    };
}

var thing = new Thing(2, 6);

...I receive this warning:

Name 'Thing' does not not match rule 'Local Function'. Suggested name is 'thing'.

It doesn't make a difference if I change Thing to this:

function Thing(a, b) {
    this.prop1 = a;
    this.prop2 = b;
}

I suspect that only "public" functions are considered constructors. Do any of you know how ReSharper differentiates between a "Local" and "Constructor" function? Even better, do you know how to override this behavior?

like image 661
Jacob Avatar asked Jun 25 '13 18:06

Jacob


1 Answers

Well, this is a bug in ReSharper. You can wait or fix it yourself. Or define it in global scope.

Btw, those functions do very, very different things. You definitely don't want to call the former a constructor.

like image 162
Esailija Avatar answered Oct 24 '22 06:10

Esailija