All files noMixedInterfaceRule.js

90.24% Statements 37/41
69.57% Branches 16/23
84.62% Functions 11/13
94.74% Lines 36/38
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61  1x 1x     1x 2x 2x 2x     1x 1x 1x 1x   1x   1x 1x 1x   1x   1x 1x 1x 1x   1x   1x   7x   4x 4x 1x   4x   1x             4x 4x 4x 7x 7x 1x   6x 6x   3x    
"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = Object.setPrototypeOf ||
        ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
        function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
var Lint = require("tslint");
var Rule = (function (_super) {
    __extends(Rule, _super);
    function Rule() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    Rule.prototype.apply = function (sourceFile) {
        var walker = new PropertyInterfaceWalker(sourceFile, this.getOptions());
        return this.applyWithWalker(walker);
    };
    return Rule;
}(Lint.Rules.AbstractRule));
Rule.FAILURE_STRING = "Only the same kind of members allowed in interfaces.";
exports.Rule = Rule;
var PropertyInterfaceWalker = (function (_super) {
    __extends(PropertyInterfaceWalker, _super);
    function PropertyInterfaceWalker() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    PropertyInterfaceWalker.prototype.visitInterfaceDeclaration = function (node) {
        // Extract 'kind' from all members to a list of numbers.
        var memberKinds = node.members.map(function (m) { return m.kind; });
        // Check so all members of a node have the same kind,
        var unUniqueMember = uniqIndex(memberKinds);
        if (unUniqueMember !== -1) {
            this.addFailure(this.createFailure(node.members[unUniqueMember].getStart(), node.members[unUniqueMember].getWidth(), Rule.FAILURE_STRING));
        }
        _super.prototype.visitInterfaceDeclaration.call(this, node);
    };
    return PropertyInterfaceWalker;
}(Lint.RuleWalker));
/**
 * Return the index of the first non unique item.
 *
 */
function uniqIndex(list) {
    var i = 0;
    var lastItem = undefined;
    for (var _i = 0, list_1 = list; _i < list_1.length; _i++) {
        var item = list_1[_i];
        if (lastItem !== undefined && lastItem !== item) {
            return i;
        }
        i++;
        lastItem = item;
    }
    return -1;
}