1 | "use strict";
|
2 | var __extends = (this && this.__extends) || (function () {
|
3 | var extendStatics = Object.setPrototypeOf ||
|
4 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
5 | function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
6 | return function (d, b) {
|
7 | extendStatics(d, b);
|
8 | function __() { this.constructor = d; }
|
9 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
10 | };
|
11 | })();
|
12 | Object.defineProperty(exports, "__esModule", { value: true });
|
13 | var ts = require("typescript");
|
14 | var Lint = require("tslint");
|
15 | var ErrorTolerantWalker_1 = require("./utils/ErrorTolerantWalker");
|
16 | var AstUtils_1 = require("./utils/AstUtils");
|
17 | var Rule = (function (_super) {
|
18 | __extends(Rule, _super);
|
19 | function Rule() {
|
20 | return _super !== null && _super.apply(this, arguments) || this;
|
21 | }
|
22 | Rule.prototype.apply = function (sourceFile) {
|
23 | return this.applyWithWalker(new NoBackboneGetSetOutsideModelRuleWalker(sourceFile, this.getOptions()));
|
24 | };
|
25 | Rule.metadata = {
|
26 | ruleName: 'no-backbone-get-set-outside-model',
|
27 | type: 'maintainability',
|
28 | description: 'Avoid using `model.get(\'x\')` and `model.set(\'x\', value)` Backbone accessors outside of the owning model.',
|
29 | options: null,
|
30 | optionsDescription: '',
|
31 | typescriptOnly: true,
|
32 | issueClass: 'Non-SDL',
|
33 | issueType: 'Warning',
|
34 | severity: 'Important',
|
35 | level: 'Opportunity for Excellence',
|
36 | group: 'Correctness',
|
37 | commonWeaknessEnumeration: '398, 710'
|
38 | };
|
39 | Rule.GET_FAILURE_STRING = 'Backbone get() called outside of owning model: ';
|
40 | Rule.SET_FAILURE_STRING = 'Backbone set() called outside of owning model: ';
|
41 | return Rule;
|
42 | }(Lint.Rules.AbstractRule));
|
43 | exports.Rule = Rule;
|
44 | var NoBackboneGetSetOutsideModelRuleWalker = (function (_super) {
|
45 | __extends(NoBackboneGetSetOutsideModelRuleWalker, _super);
|
46 | function NoBackboneGetSetOutsideModelRuleWalker() {
|
47 | return _super !== null && _super.apply(this, arguments) || this;
|
48 | }
|
49 | NoBackboneGetSetOutsideModelRuleWalker.prototype.visitCallExpression = function (node) {
|
50 | if (AstUtils_1.AstUtils.getFunctionTarget(node) !== 'this') {
|
51 | var functionName = AstUtils_1.AstUtils.getFunctionName(node);
|
52 | if (functionName === 'get' && node.arguments.length === 1 && node.arguments[0].kind === ts.SyntaxKind.StringLiteral) {
|
53 | var msg = Rule.GET_FAILURE_STRING + node.getText();
|
54 | this.addFailureAt(node.getStart(), node.getEnd(), msg);
|
55 | }
|
56 | if (functionName === 'set' && node.arguments.length === 2 && node.arguments[0].kind === ts.SyntaxKind.StringLiteral) {
|
57 | var msg = Rule.SET_FAILURE_STRING + node.getText();
|
58 | this.addFailureAt(node.getStart(), node.getEnd(), msg);
|
59 | }
|
60 | }
|
61 | _super.prototype.visitCallExpression.call(this, node);
|
62 | };
|
63 | return NoBackboneGetSetOutsideModelRuleWalker;
|
64 | }(ErrorTolerantWalker_1.ErrorTolerantWalker));
|
65 |
|
\ | No newline at end of file |