Comparing version 0.0.10 to 0.0.11
@@ -7,16 +7,47 @@ "use strict"; | ||
}; | ||
var parameterConstructorBase_1 = require("./parameterConstructorBase"); | ||
var decoratorValidator_1 = require("./util/decoratorValidator"); | ||
var FAILURE_STRING = 'In the constructor of class "%s", the parameter "%s" uses the @Attribute decorator, ' + | ||
'which is considered as a bad practice. Please, consider construction of type "@Input() %s: string"'; | ||
var attributeCondition = function (name) { | ||
return (name == 'Attribute'); | ||
}; | ||
var Lint = require('tslint/lib/lint'); | ||
var sprintf_js_1 = require('sprintf-js'); | ||
var Rule = (function (_super) { | ||
__extends(Rule, _super); | ||
function Rule(ruleName, value, disabledIntervals) { | ||
_super.call(this, ruleName, value, disabledIntervals, decoratorValidator_1.decoratorValidator(attributeCondition), FAILURE_STRING); | ||
function Rule() { | ||
_super.apply(this, arguments); | ||
} | ||
Rule.prototype.apply = function (sourceFile) { | ||
return this.applyWithWalker(new ConstructorMetadataWalker(sourceFile, this.getOptions())); | ||
}; | ||
Rule.FAILURE_STRING = 'In the constructor of class "%s",' + | ||
' the parameter "%s" uses the @Attribute decorator, ' + | ||
'which is considered as a bad practice. Please,' + | ||
' consider construction of type "@Input() %s: string"'; | ||
return Rule; | ||
}(parameterConstructorBase_1.ConstructorRule)); | ||
}(Lint.Rules.AbstractRule)); | ||
exports.Rule = Rule; | ||
var ConstructorMetadataWalker = (function (_super) { | ||
__extends(ConstructorMetadataWalker, _super); | ||
function ConstructorMetadataWalker() { | ||
_super.apply(this, arguments); | ||
} | ||
ConstructorMetadataWalker.prototype.visitConstructorDeclaration = function (node) { | ||
var parentName = node.parent.name.text; | ||
(node.parameters || []).forEach(this.validateParameter.bind(this, parentName)); | ||
_super.prototype.visitConstructorDeclaration.call(this, node); | ||
}; | ||
ConstructorMetadataWalker.prototype.validateParameter = function (className, parameter) { | ||
var _this = this; | ||
var parameterName = parameter.name.text; | ||
if (parameter.decorators) { | ||
parameter.decorators.forEach(function (decorator) { | ||
var baseExpr = decorator.expression || {}; | ||
var expr = baseExpr.expression || {}; | ||
var name = expr.text; | ||
if (name == 'Attribute') { | ||
var failureConfig = [className, parameterName, parameterName]; | ||
failureConfig.unshift(Rule.FAILURE_STRING); | ||
_this.addFailure(_this.createFailure(parameter.getStart(), parameter.getWidth(), sprintf_js_1.sprintf.apply(_this, failureConfig))); | ||
} | ||
}); | ||
} | ||
}; | ||
return ConstructorMetadataWalker; | ||
}(Lint.RuleWalker)); | ||
exports.ConstructorMetadataWalker = ConstructorMetadataWalker; |
@@ -7,17 +7,35 @@ "use strict"; | ||
}; | ||
var propertyClassBase_1 = require("./propertyClassBase"); | ||
var decoratorValidator_1 = require('./util/decoratorValidator'); | ||
var FAILURE_STRING = 'In the class "%s", the directive input property "%s" should not be renamed.' + | ||
'Please, consider the following use "@Input() %s: string"'; | ||
var renameInputCondition = function (name, arg, element) { | ||
var memberName = element.name.text; | ||
return (name === 'Input' && arg && memberName != arg.text); | ||
}; | ||
var Lint = require('tslint/lib/lint'); | ||
var sprintf_js_1 = require('sprintf-js'); | ||
var ng2Walker_1 = require("./util/ng2Walker"); | ||
var Rule = (function (_super) { | ||
__extends(Rule, _super); | ||
function Rule(ruleName, value, disabledIntervals) { | ||
_super.call(this, ruleName, value, disabledIntervals, decoratorValidator_1.decoratorValidator(renameInputCondition), FAILURE_STRING); | ||
function Rule() { | ||
_super.apply(this, arguments); | ||
} | ||
Rule.prototype.apply = function (sourceFile) { | ||
return this.applyWithWalker(new InputMetadataWalker(sourceFile, this.getOptions())); | ||
}; | ||
Rule.FAILURE_STRING = 'In the class "%s", the directive ' + | ||
'input property "%s" should not be renamed.' + | ||
'Please, consider the following use "@Input() %s: string"'; | ||
return Rule; | ||
}(propertyClassBase_1.ClassParameterRule)); | ||
}(Lint.Rules.AbstractRule)); | ||
exports.Rule = Rule; | ||
var InputMetadataWalker = (function (_super) { | ||
__extends(InputMetadataWalker, _super); | ||
function InputMetadataWalker() { | ||
_super.apply(this, arguments); | ||
} | ||
InputMetadataWalker.prototype.visitNg2Input = function (property, input, args) { | ||
var className = property.parent.name.text; | ||
var memberName = property.name.text; | ||
if (args.length != 0 && memberName != args[0]) { | ||
var failureConfig = [className, memberName, memberName]; | ||
failureConfig.unshift(Rule.FAILURE_STRING); | ||
this.addFailure(this.createFailure(property.getStart(), property.getWidth(), sprintf_js_1.sprintf.apply(this, failureConfig))); | ||
} | ||
}; | ||
return InputMetadataWalker; | ||
}(ng2Walker_1.Ng2Walker)); | ||
exports.InputMetadataWalker = InputMetadataWalker; |
@@ -7,17 +7,35 @@ "use strict"; | ||
}; | ||
var propertyClassBase_1 = require("./propertyClassBase"); | ||
var decoratorValidator_1 = require('./util/decoratorValidator'); | ||
var FAILURE_STRING = 'In the class "%s", the directive output property "%s" should not be renamed.' + | ||
'Please, consider the following use "@Output() %s = new EventEmitter();"'; | ||
var renameOutputCondition = function (name, arg, element) { | ||
var memberName = element.name.text; | ||
return (name === 'Output' && arg && memberName !== arg.text); | ||
}; | ||
var Lint = require('tslint/lib/lint'); | ||
var sprintf_js_1 = require('sprintf-js'); | ||
var ng2Walker_1 = require("./util/ng2Walker"); | ||
var Rule = (function (_super) { | ||
__extends(Rule, _super); | ||
function Rule(ruleName, value, disabledIntervals) { | ||
_super.call(this, ruleName, value, disabledIntervals, decoratorValidator_1.decoratorValidator(renameOutputCondition), FAILURE_STRING); | ||
function Rule() { | ||
_super.apply(this, arguments); | ||
} | ||
Rule.prototype.apply = function (sourceFile) { | ||
return this.applyWithWalker(new OutputMetadataWalker(sourceFile, this.getOptions())); | ||
}; | ||
Rule.FAILURE_STRING = 'In the class "%s", the directive output ' + | ||
'property "%s" should not be renamed.' + | ||
'Please, consider the following use "@Output() %s = new EventEmitter();"'; | ||
return Rule; | ||
}(propertyClassBase_1.ClassParameterRule)); | ||
}(Lint.Rules.AbstractRule)); | ||
exports.Rule = Rule; | ||
var OutputMetadataWalker = (function (_super) { | ||
__extends(OutputMetadataWalker, _super); | ||
function OutputMetadataWalker() { | ||
_super.apply(this, arguments); | ||
} | ||
OutputMetadataWalker.prototype.visitNg2Output = function (property, output, args) { | ||
var className = property.parent.name.text; | ||
var memberName = property.name.text; | ||
if (args.length != 0 && memberName != args[0]) { | ||
var failureConfig = [className, memberName, memberName]; | ||
failureConfig.unshift(Rule.FAILURE_STRING); | ||
this.addFailure(this.createFailure(property.getStart(), property.getWidth(), sprintf_js_1.sprintf.apply(this, failureConfig))); | ||
} | ||
}; | ||
return OutputMetadataWalker; | ||
}(ng2Walker_1.Ng2Walker)); | ||
exports.OutputMetadataWalker = OutputMetadataWalker; |
@@ -6,3 +6,3 @@ "use strict"; | ||
it("should fail, when it's used attribute decorator", function () { | ||
var source = "\n class ButtonComponent {\n label: string;\n constructor(public @Attribute('label') label) {\n this.label = label;\n }\n }"; | ||
var source = "\n class ButtonComponent {\n label: string;\n constructor(@Attribute('label') label) {\n this.label = label;\n }\n }"; | ||
testHelper_1.assertFailure('attribute-parameter-decorator', source, { | ||
@@ -13,7 +13,7 @@ message: 'In the constructor of class "ButtonComponent", the parameter "label" uses the @Attribute decorator, ' + | ||
line: 3, | ||
character: 35 | ||
character: 28 | ||
}, | ||
endPosition: { | ||
line: 3, | ||
character: 60 | ||
character: 53 | ||
} | ||
@@ -20,0 +20,0 @@ }); |
@@ -26,4 +26,2 @@ "use strict"; | ||
}); | ||
}); | ||
describe('valid directive input property', function () { | ||
it('should succeed, when a directive input property rename is the same as the name of the property', function () { | ||
@@ -30,0 +28,0 @@ var source = "\n class ButtonComponent {\n @Input('label') label: string;\n }"; |
@@ -26,4 +26,2 @@ "use strict"; | ||
}); | ||
}); | ||
describe('valid directive output property', function () { | ||
it('should succeed, when a directive output property rename is the same as the property name', function () { | ||
@@ -30,0 +28,0 @@ var source = "\n class ButtonComponent {\n @Output('change') change = new EventEmitter<any>();\n }"; |
{ | ||
"name": "codelyzer", | ||
"version": "0.0.10", | ||
"version": "0.0.11", | ||
"description": "A set of linters for Angular 2 applications, following https://github.com/mgechev/angular2-style-guide.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
443803
103
10029
0