1 | var __extends = (this && this.__extends) || function (d, b) {
|
2 | for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
3 | function __() { this.constructor = d; }
|
4 | __.prototype = b.prototype;
|
5 | d.prototype = new __();
|
6 | };
|
7 | var ErrorTolerantWalker = require('./utils/ErrorTolerantWalker');
|
8 | var Rule = (function (_super) {
|
9 | __extends(Rule, _super);
|
10 | function Rule() {
|
11 | _super.apply(this, arguments);
|
12 | }
|
13 | Rule.prototype.apply = function (sourceFile) {
|
14 | return this.applyWithWalker(new NoDuplicateParameterNamesWalker(sourceFile, this.getOptions()));
|
15 | };
|
16 | Rule.FAILURE_STRING = 'Duplicate parameter name: ';
|
17 | return Rule;
|
18 | })(Lint.Rules.AbstractRule);
|
19 | exports.Rule = Rule;
|
20 | var NoDuplicateParameterNamesWalker = (function (_super) {
|
21 | __extends(NoDuplicateParameterNamesWalker, _super);
|
22 | function NoDuplicateParameterNamesWalker() {
|
23 | _super.apply(this, arguments);
|
24 | }
|
25 | NoDuplicateParameterNamesWalker.prototype.visitMethodDeclaration = function (node) {
|
26 | this.validateParameterNames(node);
|
27 | _super.prototype.visitMethodDeclaration.call(this, node);
|
28 | };
|
29 | NoDuplicateParameterNamesWalker.prototype.visitConstructorDeclaration = function (node) {
|
30 | this.validateParameterNames(node);
|
31 | _super.prototype.visitConstructorDeclaration.call(this, node);
|
32 | };
|
33 | NoDuplicateParameterNamesWalker.prototype.visitArrowFunction = function (node) {
|
34 | this.validateParameterNames(node);
|
35 | _super.prototype.visitArrowFunction.call(this, node);
|
36 | };
|
37 | NoDuplicateParameterNamesWalker.prototype.visitFunctionDeclaration = function (node) {
|
38 | this.validateParameterNames(node);
|
39 | _super.prototype.visitFunctionDeclaration.call(this, node);
|
40 | };
|
41 | NoDuplicateParameterNamesWalker.prototype.visitFunctionExpression = function (node) {
|
42 | this.validateParameterNames(node);
|
43 | _super.prototype.visitFunctionExpression.call(this, node);
|
44 | };
|
45 | NoDuplicateParameterNamesWalker.prototype.validateParameterNames = function (node) {
|
46 | var _this = this;
|
47 | var seenNames = {};
|
48 | node.parameters.forEach(function (parameter) {
|
49 | var parameterName = parameter.name.text;
|
50 | if (parameterName != null) {
|
51 | if (seenNames[parameterName]) {
|
52 | _this.addFailure(_this.createFailure(parameter.name.getStart(), parameterName.length, Rule.FAILURE_STRING + '\'' + parameterName + '\''));
|
53 | }
|
54 | else {
|
55 | seenNames[parameterName] = true;
|
56 | }
|
57 | }
|
58 | });
|
59 | };
|
60 | return NoDuplicateParameterNamesWalker;
|
61 | })(ErrorTolerantWalker);
|
62 |
|
\ | No newline at end of file |