Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[[Fix]] Don't warn when RegExp() is used without 'new'. #3529

Merged
merged 1 commit into from Feb 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 11 additions & 8 deletions src/jshint.js
Expand Up @@ -3046,14 +3046,17 @@ var JSHINT = (function() {

if (left) {
if (left.type === "(identifier)") {
if (left.value.match(/^[A-Z]([A-Z0-9_$]*[a-z][A-Za-z0-9_$]*)?$/)) {
if ("Array Number String Boolean Date Object Error Symbol".indexOf(left.value) === -1) {
if (left.value === "Math") {
/* istanbul ignore next */
warning("W063", left);
} else if (state.option.newcap) {
warning("W064", left);
}
var newcapRe = /^[A-Z]([A-Z0-9_$]*[a-z][A-Za-z0-9_$]*)?$/;
var newcapIgnore = [
"Array", "Boolean", "Date", "Error", "Number",
"Object", "RegExp", "String", "Symbol"
];
if (newcapRe.test(left.value) && newcapIgnore.indexOf(left.value) === -1) {
if (left.value === "Math") {
/* istanbul ignore next */
warning("W063", left);
} else if (state.option.newcap) {
warning("W064", left);
}
}
}
Expand Down
7 changes: 6 additions & 1 deletion tests/unit/fixtures/newcap.js
Expand Up @@ -19,8 +19,13 @@ bat = myAnimal();

// Make sure we don't warn on Error, Number, etc.
Array();
Boolean();
Date();
Error();
Number();
/*jshint -W010 */
Object();
/*jshint +W010 */
RegExp();
String();
Boolean();
Symbol();