All files readonlyKeywordRule.js

87.5% Statements 28/32
75% Branches 18/24
83.33% Functions 10/12
92.86% Lines 26/28
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  1x 1x     1x 1x 1x 1x     1x 1x 1x 1x         1x 1x   7x   1x 7x   1x   1x   831x     831x 156x   95x 18x   77x   77x 77x     736x    
"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 ts = require("typescript");
var Lint = require("tslint");
var Shared = require("./readonly-shared");
/**
 * This rule checks that the readonly keyword is used in all PropertySignature and
 * IndexerSignature nodes (which are the only places that the readonly keyword can exist).
 */
var Rule = (function (_super) {
    __extends(Rule, _super);
    function Rule() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    Rule.prototype.apply = function (sourceFile) {
        return this.applyWithFunction(sourceFile, function (ctx) { return Shared.walk(ctx, checkNode, "A readonly modifier is required."); }, Shared.parseOptions(this.ruleArguments));
    };
    return Rule;
}(Lint.Rules.AbstractRule));
exports.Rule = Rule;
function checkNode(node, ctx) {
    return checkPropertySignatureAndIndexSignature(node, ctx);
}
function checkPropertySignatureAndIndexSignature(node, ctx) {
    if (node.kind === ts.SyntaxKind.PropertySignature || node.kind === ts.SyntaxKind.IndexSignature) {
        if (!(node.modifiers && node.modifiers.filter(function (m) { return m.kind === ts.SyntaxKind.ReadonlyKeyword; }).length > 0)) {
            // Check if ignore-prefix applies
            if (Shared.shouldIgnorePrefix(node, ctx.options, ctx.sourceFile)) {
                return [];
            }
            var length_1 = node.getWidth(ctx.sourceFile);
            // const fulltext = node.getText(ctx.sourceFile);
            var fulltext = node.getText(ctx.sourceFile);
            return [Shared.createInvalidNode(node, new Lint.Replacement(node.end - length_1, length_1, "readonly " + fulltext))];
        }
    }
    return [];
}