1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | var ts = require("typescript");
|
4 | var Lint = require("tslint");
|
5 | var utils = require("tsutils/typeguard/2.8");
|
6 | var Ignore = require("./shared/ignore");
|
7 | var check_node_1 = require("./shared/check-node");
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | exports.Rule = check_node_1.createCheckNodeRule(Ignore.checkNodeWithIgnore(checkNode), "A readonly modifier is required.");
|
14 | function checkNode(node, ctx) {
|
15 | return { invalidNodes: checkPropertySignatureAndIndexSignature(node, ctx) };
|
16 | }
|
17 | function checkPropertySignatureAndIndexSignature(node, ctx) {
|
18 | if ((utils.isPropertySignature(node) ||
|
19 | utils.isIndexSignatureDeclaration(node) ||
|
20 | utils.isPropertyDeclaration(node)) &&
|
21 | !(node.modifiers &&
|
22 | node.modifiers.filter(function (m) { return m.kind === ts.SyntaxKind.ReadonlyKeyword; })
|
23 | .length > 0)) {
|
24 |
|
25 | if (Ignore.shouldIgnorePrefix(node, ctx.options, ctx.sourceFile)) {
|
26 | return [];
|
27 | }
|
28 | var start = utils.isIndexSignatureDeclaration(node)
|
29 | ? node.getStart(ctx.sourceFile)
|
30 | : node.name.getStart(ctx.sourceFile);
|
31 | return [
|
32 | check_node_1.createInvalidNode(node, [new Lint.Replacement(start, 0, "readonly ")])
|
33 | ];
|
34 | }
|
35 | return [];
|
36 | }
|
37 |
|
\ | No newline at end of file |