1 | "use strict";
|
2 | var __extends = (this && this.__extends) || (function () {
|
3 | var extendStatics = function (d, b) {
|
4 | extendStatics = Object.setPrototypeOf ||
|
5 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
6 | function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
7 | return extendStatics(d, b);
|
8 | }
|
9 | return function (d, b) {
|
10 | extendStatics(d, b);
|
11 | function __() { this.constructor = d; }
|
12 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
13 | };
|
14 | })();
|
15 | Object.defineProperty(exports, "__esModule", { value: true });
|
16 | var ts = require("typescript");
|
17 | var Lint = require("tslint");
|
18 | var tsutils = require("tsutils");
|
19 | var Rule = (function (_super) {
|
20 | __extends(Rule, _super);
|
21 | function Rule() {
|
22 | return _super !== null && _super.apply(this, arguments) || this;
|
23 | }
|
24 | Rule.prototype.apply = function (sourceFile) {
|
25 | return this.applyWithFunction(sourceFile, walk);
|
26 | };
|
27 | Rule.metadata = {
|
28 | ruleName: 'missing-optional-annotation',
|
29 | type: 'maintainability',
|
30 | description: 'Deprecated - This rule is now enforced by the TypeScript compiler',
|
31 | options: null,
|
32 | optionsDescription: '',
|
33 | typescriptOnly: true,
|
34 | issueClass: 'Ignored',
|
35 | issueType: 'Warning',
|
36 | severity: 'Low',
|
37 | level: 'Opportunity for Excellence',
|
38 | group: 'Deprecated',
|
39 | recommendation: 'false'
|
40 | };
|
41 | Rule.FAILURE_STRING = 'Argument following optional argument missing optional annotation: ';
|
42 | return Rule;
|
43 | }(Lint.Rules.AbstractRule));
|
44 | exports.Rule = Rule;
|
45 | function walk(ctx) {
|
46 | function cb(node) {
|
47 | if (tsutils.isMethodDeclaration(node) ||
|
48 | tsutils.isConstructorDeclaration(node) ||
|
49 | tsutils.isArrowFunction(node) ||
|
50 | tsutils.isFunctionDeclaration(node) ||
|
51 | tsutils.isFunctionExpression(node)) {
|
52 | validateParameters(node);
|
53 | }
|
54 | return ts.forEachChild(node, cb);
|
55 | }
|
56 | return ts.forEachChild(ctx.sourceFile, cb);
|
57 | function validateParameters(node) {
|
58 | var optionalParameterFound = false;
|
59 | if (node.parameters === undefined) {
|
60 | return;
|
61 | }
|
62 | node.parameters.forEach(function (parameter) {
|
63 | if (parameter.questionToken !== undefined || parameter.initializer !== undefined) {
|
64 | optionalParameterFound = true;
|
65 | }
|
66 | else if (optionalParameterFound && parameter.initializer === undefined) {
|
67 | var msg = Rule.FAILURE_STRING + parameter.getFullText();
|
68 | ctx.addFailureAt(parameter.name.getStart(), parameter.name.getWidth(), msg);
|
69 | }
|
70 | });
|
71 | }
|
72 | }
|
73 |
|
\ | No newline at end of file |