UNPKG

2.5 kBJavaScriptView Raw
1"use strict";
2var __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})();
12Object.defineProperty(exports, "__esModule", { value: true });
13var Lint = require("tslint");
14var ErrorTolerantWalker_1 = require("./utils/ErrorTolerantWalker");
15var Rule = (function (_super) {
16 __extends(Rule, _super);
17 function Rule() {
18 return _super !== null && _super.apply(this, arguments) || this;
19 }
20 Rule.FAILURE_STRING_FACTORY = function (initializer, expression) {
21 return "Do not use the 'for in' statement: 'for (" + initializer + " in " + expression + ")'. If this is an object, use 'Object.keys' instead. If this is an array use a standard 'for' loop instead.";
22 };
23 Rule.prototype.apply = function (sourceFile) {
24 return this.applyWithWalker(new NoForInRuleWalker(sourceFile, this.getOptions()));
25 };
26 Rule.metadata = {
27 ruleName: 'no-for-in',
28 type: 'maintainability',
29 description: 'Avoid use of for-in statements. They can be replaced by Object.keys',
30 options: null,
31 optionsDescription: '',
32 typescriptOnly: true,
33 issueClass: 'Non-SDL',
34 issueType: 'Warning',
35 severity: 'Moderate',
36 level: 'Opportunity for Excellence',
37 group: 'Clarity',
38 commonWeaknessEnumeration: '398, 710'
39 };
40 return Rule;
41}(Lint.Rules.AbstractRule));
42exports.Rule = Rule;
43var NoForInRuleWalker = (function (_super) {
44 __extends(NoForInRuleWalker, _super);
45 function NoForInRuleWalker() {
46 return _super !== null && _super.apply(this, arguments) || this;
47 }
48 NoForInRuleWalker.prototype.visitForInStatement = function (node) {
49 var initializer = node.initializer.getText();
50 var expression = node.expression.getText();
51 var msg = Rule.FAILURE_STRING_FACTORY(initializer, expression);
52 this.addFailureAt(node.getStart(), node.getWidth(), msg);
53 };
54 return NoForInRuleWalker;
55}(ErrorTolerantWalker_1.ErrorTolerantWalker));
56//# sourceMappingURL=noForInRule.js.map
\No newline at end of file