diff options
author | Florian Dold <florian.dold@gmail.com> | 2017-08-14 05:01:11 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2017-08-14 05:02:09 +0200 |
commit | 363723fc84f7b8477592e0105aeb331ec9a017af (patch) | |
tree | 29f92724f34131bac64d6a318dd7e30612e631c7 /node_modules/tslint/lib/rules/noParameterPropertiesRule.js | |
parent | 5634e77ad96bfe1818f6b6ee70b7379652e5487f (diff) |
node_modules
Diffstat (limited to 'node_modules/tslint/lib/rules/noParameterPropertiesRule.js')
-rw-r--r-- | node_modules/tslint/lib/rules/noParameterPropertiesRule.js | 55 |
1 files changed, 25 insertions, 30 deletions
diff --git a/node_modules/tslint/lib/rules/noParameterPropertiesRule.js b/node_modules/tslint/lib/rules/noParameterPropertiesRule.js index 86fa67bad..d0b929650 100644 --- a/node_modules/tslint/lib/rules/noParameterPropertiesRule.js +++ b/node_modules/tslint/lib/rules/noParameterPropertiesRule.js @@ -17,6 +17,8 @@ */ Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); +var tsutils_1 = require("tsutils"); +var ts = require("typescript"); var Lint = require("../index"); var Rule = (function (_super) { tslib_1.__extends(Rule, _super); @@ -28,40 +30,33 @@ var Rule = (function (_super) { return "Property '" + ident + "' cannot be declared in the constructor"; }; Rule.prototype.apply = function (sourceFile) { - return this.applyWithWalker(new NoParameterPropertiesWalker(sourceFile, this.getOptions())); + return this.applyWithFunction(sourceFile, walk); + }; + /* tslint:disable:object-literal-sort-keys */ + Rule.metadata = { + ruleName: "no-parameter-properties", + description: "Disallows parameter properties in class constructors.", + rationale: (_a = ["\n Parameter properties can be confusing to those new to TS as they are less explicit\n than other ways of declaring and initializing class members."], _a.raw = ["\n Parameter properties can be confusing to those new to TS as they are less explicit\n than other ways of declaring and initializing class members."], Lint.Utils.dedent(_a)), + optionsDescription: "Not configurable.", + options: null, + optionExamples: [true], + type: "style", + typescriptOnly: true, }; return Rule; }(Lint.Rules.AbstractRule)); -/* tslint:disable:object-literal-sort-keys */ -Rule.metadata = { - ruleName: "no-parameter-properties", - description: "Disallows parameter properties in class constructors.", - rationale: (_a = ["\n Parameter properties can be confusing to those new to TS as they are less explicit\n than other ways of declaring and initializing class members."], _a.raw = ["\n Parameter properties can be confusing to those new to TS as they are less explicit\n than other ways of declaring and initializing class members."], Lint.Utils.dedent(_a)), - optionsDescription: "Not configurable.", - options: null, - optionExamples: [true], - type: "style", - typescriptOnly: true, -}; exports.Rule = Rule; -var NoParameterPropertiesWalker = (function (_super) { - tslib_1.__extends(NoParameterPropertiesWalker, _super); - function NoParameterPropertiesWalker() { - return _super !== null && _super.apply(this, arguments) || this; - } - NoParameterPropertiesWalker.prototype.visitConstructorDeclaration = function (node) { - var parameters = node.parameters; - for (var _i = 0, parameters_1 = parameters; _i < parameters_1.length; _i++) { - var parameter = parameters_1[_i]; - if (parameter.modifiers != null && parameter.modifiers.length > 0) { - var errorMessage = Rule.FAILURE_STRING_FACTORY(parameter.name.text); - var lastModifier = parameter.modifiers[parameter.modifiers.length - 1]; - this.addFailureFromStartToEnd(parameter.getStart(), lastModifier.getEnd(), errorMessage); +function walk(ctx) { + return ts.forEachChild(ctx.sourceFile, function cb(node) { + if (node.kind === ts.SyntaxKind.Constructor) { + for (var _i = 0, _a = node.parameters; _i < _a.length; _i++) { + var parameter = _a[_i]; + if (tsutils_1.isParameterProperty(parameter)) { + ctx.addFailure(parameter.getStart(ctx.sourceFile), parameter.name.pos, Rule.FAILURE_STRING_FACTORY(parameter.name.getText(ctx.sourceFile))); + } } } - _super.prototype.visitConstructorDeclaration.call(this, node); - }; - return NoParameterPropertiesWalker; -}(Lint.RuleWalker)); -exports.NoParameterPropertiesWalker = NoParameterPropertiesWalker; + return ts.forEachChild(node, cb); + }); +} var _a; |