UNPKG

@coffeelint/cli

Version:
48 lines (40 loc) 1.77 kB
(function() { var NoStandAloneAt; module.exports = NoStandAloneAt = (function() { class NoStandAloneAt { lintToken(token, tokenApi) { var isAStart, isDot, isProp, isProtoProp, nextToken, noSpace, ref, ref1; [nextToken] = tokenApi.peek(); noSpace = !token.spaced; isProp = nextToken === 'PROPERTY'; isAStart = nextToken === 'INDEX_START' || nextToken === 'CALL_START'; // @[] or @() isDot = nextToken === '.'; // https://github.com/jashkenas/coffee-script/issues/1601 // @::foo is valid, but @:: behaves inconsistently and is planned for // removal. Technically @:: is a stand alone ::, but I think it makes // sense to group it into no_stand_alone_at isProtoProp = nextToken === '::' && ((ref = (ref1 = tokenApi.peek(2)) != null ? ref1[0] : void 0) === 'PROPERTY'); // Return an error after an '@' token unless: // 1: there is a '.' afterwards (isDot) // 2: there isn't a space after the '@' and the token following the '@' // is an property, the start of an index '[' or is an property after // the '::' if (!(isDot || (noSpace && (isProp || isAStart || isProtoProp)))) { return {token}; } } }; NoStandAloneAt.prototype.rule = { type: 'style', name: 'no_stand_alone_at', level: 'ignore', message: '@ must not be used stand alone', description: `This rule checks that no stand alone @ are in use, they are discouraged. Further information in CoffeeScript issue <a href="https://github.com/jashkenas/coffee-script/issues/1601"> #1601</a>` }; NoStandAloneAt.prototype.tokens = ['@']; return NoStandAloneAt; }).call(this); }).call(this);