canonical
Version:
Canonical code style linter and formatter for JavaScript, SCSS, CSS and JSON.
41 lines (31 loc) • 1.05 kB
JavaScript
/**
* @fileoverview Rule to flag when using constructor without parentheses
* @author Ilya Volodin
*/
;
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
module.exports = {
meta: {
docs: {
description: "require parentheses when invoking a constructor with no arguments",
category: "Stylistic Issues",
recommended: false
},
schema: []
},
create: function(context) {
return {
NewExpression: function(node) {
var tokens = context.getTokens(node);
var prenticesTokens = tokens.filter(function(token) {
return token.value === "(" || token.value === ")";
});
if (prenticesTokens.length < 2) {
context.report(node, "Missing '()' invoking a constructor");
}
}
};
}
};