UNPKG

@coffeelint/cli

Version:
45 lines (36 loc) 1.15 kB
(function() { var ParseintRadix; module.exports = ParseintRadix = (function() { class ParseintRadix { lintToken(token, tokenApi) { var callEnd, functionName, prevToken; [prevToken, functionName] = tokenApi.peek(-1); if (functionName === 'parseInt') { [callEnd] = tokenApi.peek(2); if (callEnd === 'CALL_END') { return {token}; } } } }; ParseintRadix.prototype.rule = { type: 'problem', name: 'missing_parseint_radix', level: 'warn', message: 'parseInt is missing the radix argument', description: `This rule warns about using parseInt without a radix. From the MDN developers reference: <q>Always specify this parameter to eliminate reader confusion and to guarantee predictable behavior.</q> <pre> <code># You would expect this to result in 8, but # it might result in 0 (parsed as octal). parseInt '08' # To be safe, specify the radix argument: parseInt '08', 10 </code> </pre>` }; ParseintRadix.prototype.tokens = ['CALL_START']; return ParseintRadix; }).call(this); }).call(this);