UNPKG

@coffeelint/cli

Version:
65 lines (56 loc) 2.3 kB
(function() { var EmptyConstructorNeedsParens; module.exports = EmptyConstructorNeedsParens = (function() { class EmptyConstructorNeedsParens { // Return an error if the given indentation token is not correct. lintToken(token, tokenApi) { var identIndex, isIdent, nextToken, peek, ref, ref1, ref2; if (token[1] === 'new') { peek = tokenApi.peek.bind(tokenApi); // Find the last chained identifier, e.g. Bar in new foo.bar.Bar(). identIndex = 1; while (true) { isIdent = (ref = (ref1 = peek(identIndex)) != null ? ref1[0] : void 0) === 'IDENTIFIER' || ref === 'PROPERTY'; nextToken = peek(identIndex + 1); if (isIdent) { if ((nextToken != null ? nextToken[0] : void 0) === '.') { // skip the dot and start with the next token identIndex += 2; continue; } if ((nextToken != null ? nextToken[0] : void 0) === 'INDEX_START') { while (((ref2 = peek(identIndex)) != null ? ref2[0] : void 0) !== 'INDEX_END') { identIndex++; } continue; } } break; } // The callStart is generated if your parameters are all on the same // line with implicit parens, and if your parameters start on the // next line, but is missing if there are no params and no parens. if (isIdent && (nextToken != null)) { return this.handleExpectedCallStart(nextToken, tokenApi); } } } handleExpectedCallStart(isCallStart, tokenApi) { if (isCallStart[0] !== 'CALL_START') { return { token: tokenApi.peek(isCallStart, 1) }; } } }; EmptyConstructorNeedsParens.prototype.rule = { type: 'style', name: 'empty_constructor_needs_parens', level: 'ignore', message: 'Invoking a constructor without parens and without arguments', description: `Requires constructors with no parameters to include the parens` }; EmptyConstructorNeedsParens.prototype.tokens = ['UNARY']; return EmptyConstructorNeedsParens; }).call(this); }).call(this);