jscs-dev / node-jscs

:arrow_heading_up: JavaScript Code Style checker (unmaintained)
https://jscs-dev.github.io
MIT License
4.96k stars 513 forks source link

jscs "requireCapitalizedConstructors" and jshint "newcap" are different #2046

Closed AlexanderOMara closed 8 years ago

AlexanderOMara commented 8 years ago

Basically requireCapitalizedConstructors works by requiring constructors after the new keyword to be capitalized, where as newcap works by requiring the new keyword before capitalized function calls.

Here is a test case to show the difference:

.jscsrc

{
    "requireCapitalizedConstructors": true
}

.jshintrc

{
    "newcap": true
}

test.js

function Test() {
    return null;
}
function test() {
    return null;
}

var testUpper = Test();
var testLower = new test();

jscs output:

$ jscs .
Constructor functions should be capitalized at ./test.js :
     7 |
     8 |var testUpper = Test();
     9 |var testLower = new test();
----------------------------^
    10 |

1 code style error found.

jshint output:

$ jshint .
test.js: line 8, col 17, Missing 'new' prefix when invoking a constructor.

1 error

Personally, I would like to have both in jscs. Is there an option I'm missing to enforce this, or could one be added?

markelog commented 8 years ago

Sounds like a different rule, would you like to implement it?

AlexanderOMara commented 8 years ago

Sure, I've just submitted a pull request.