UNPKG

2.24 kBJavaScriptView Raw
1var __extends = (this && this.__extends) || function (d, b) {
2 for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
3 function __() { this.constructor = d; }
4 __.prototype = b.prototype;
5 d.prototype = new __();
6};
7var SyntaxKind = require('./utils/SyntaxKind');
8var ErrorTolerantWalker = require('./utils/ErrorTolerantWalker');
9var AstUtils = require('./utils/AstUtils');
10var Rule = (function (_super) {
11 __extends(Rule, _super);
12 function Rule() {
13 _super.apply(this, arguments);
14 }
15 Rule.prototype.apply = function (sourceFile) {
16 return this.applyWithWalker(new NoBackboneGetSetOutsideModelRuleWalker(sourceFile, this.getOptions()));
17 };
18 Rule.GET_FAILURE_STRING = 'Backbone get() called outside of owning model: ';
19 Rule.SET_FAILURE_STRING = 'Backbone set() called outside of owning model: ';
20 return Rule;
21})(Lint.Rules.AbstractRule);
22exports.Rule = Rule;
23var NoBackboneGetSetOutsideModelRuleWalker = (function (_super) {
24 __extends(NoBackboneGetSetOutsideModelRuleWalker, _super);
25 function NoBackboneGetSetOutsideModelRuleWalker() {
26 _super.apply(this, arguments);
27 }
28 NoBackboneGetSetOutsideModelRuleWalker.prototype.visitCallExpression = function (node) {
29 if (AstUtils.getFunctionTarget(node) !== 'this') {
30 var functionName = AstUtils.getFunctionName(node);
31 if (functionName === 'get' && node.arguments.length === 1 && node.arguments[0].kind === SyntaxKind.current().StringLiteral) {
32 var msg = Rule.GET_FAILURE_STRING + node.getText();
33 this.addFailure(this.createFailure(node.getStart(), node.getEnd(), msg));
34 }
35 if (functionName === 'set' && node.arguments.length === 2 && node.arguments[0].kind === SyntaxKind.current().StringLiteral) {
36 var msg = Rule.SET_FAILURE_STRING + node.getText();
37 this.addFailure(this.createFailure(node.getStart(), node.getEnd(), msg));
38 }
39 }
40 _super.prototype.visitCallExpression.call(this, node);
41 };
42 return NoBackboneGetSetOutsideModelRuleWalker;
43})(ErrorTolerantWalker);
44//# sourceMappingURL=noBackboneGetSetOutsideModelRule.js.map
\No newline at end of file