Comparing version 1.0.0-beta.2 to 1.0.0-beta.3
@@ -9,12 +9,10 @@ "use strict"; | ||
var ts = require('typescript'); | ||
var compiler_1 = require('@angular/compiler'); | ||
var templateParser_1 = require('./templateParser'); | ||
var recursiveAngularExpressionVisitor_1 = require('./recursiveAngularExpressionVisitor'); | ||
var expressionTypes_1 = require('./expressionTypes'); | ||
var compiler = require('@angular/compiler'); | ||
var templateParser_1 = require('./templates/templateParser'); | ||
var parseCss_1 = require('./styles/parseCss'); | ||
var basicCssAstVisitor_1 = require('./styles/basicCssAstVisitor'); | ||
var basicTemplateAstVisitor_1 = require('./templates/basicTemplateAstVisitor'); | ||
var recursiveAngularExpressionVisitor_1 = require('./templates/recursiveAngularExpressionVisitor'); | ||
var utils_1 = require('../util/utils'); | ||
var SyntaxKind = require('../util/syntaxKind'); | ||
var getDecoratorName = function (decorator) { | ||
var baseExpr = decorator.expression || {}; | ||
var expr = baseExpr.expression || {}; | ||
return expr.text; | ||
}; | ||
var getDecoratorStringArgs = function (decorator) { | ||
@@ -25,49 +23,9 @@ var baseExpr = decorator.expression || {}; | ||
}; | ||
var getExpressionDisplacement = function (binding) { | ||
var attrLen = 0; | ||
var valLen = 0; | ||
var totalLength = 0; | ||
var result = 0; | ||
if (binding instanceof compiler_1.BoundEventAst || binding instanceof compiler_1.BoundElementPropertyAst) { | ||
var subBindingLen = 0; | ||
if (binding instanceof compiler_1.BoundElementPropertyAst) { | ||
var prop = binding; | ||
switch (prop.type) { | ||
case compiler_1.PropertyBindingType.Animation: | ||
subBindingLen = 'animate'.length + 1; | ||
break; | ||
case compiler_1.PropertyBindingType.Attribute: | ||
subBindingLen = 'attr'.length + 1; | ||
break; | ||
case compiler_1.PropertyBindingType.Class: | ||
subBindingLen = 'class'.length + 1; | ||
break; | ||
case compiler_1.PropertyBindingType.Style: | ||
subBindingLen = 'style'.length + 1; | ||
break; | ||
} | ||
} | ||
attrLen = binding.name.length + 4 + subBindingLen; | ||
if (binding instanceof compiler_1.BoundEventAst) { | ||
valLen = binding.handler.span.end; | ||
} | ||
else { | ||
valLen = binding.value.span.end; | ||
} | ||
totalLength = binding.sourceSpan.end.offset - binding.sourceSpan.start.offset; | ||
var whitespace = totalLength - (attrLen + valLen) - 1; | ||
result = whitespace + attrLen + binding.sourceSpan.start.offset; | ||
} | ||
else if (binding instanceof compiler_1.BoundTextAst) { | ||
result = binding.sourceSpan.start.offset; | ||
} | ||
return result; | ||
}; | ||
var Ng2Walker = (function (_super) { | ||
__extends(Ng2Walker, _super); | ||
function Ng2Walker(sourceFile, _originalOptions, TemplateVisitorCtr) { | ||
if (TemplateVisitorCtr === void 0) { TemplateVisitorCtr = recursiveAngularExpressionVisitor_1.RecursiveAngularExpressionVisitor; } | ||
function Ng2Walker(sourceFile, _originalOptions, _config) { | ||
_super.call(this, sourceFile, _originalOptions); | ||
this._originalOptions = _originalOptions; | ||
this.TemplateVisitorCtr = TemplateVisitorCtr; | ||
this._config = _config; | ||
this._normalizeConfig(_config); | ||
} | ||
@@ -87,3 +45,3 @@ Ng2Walker.prototype.visitClassDeclaration = function (declaration) { | ||
Ng2Walker.prototype.visitMethodDecorator = function (decorator) { | ||
var name = getDecoratorName(decorator); | ||
var name = utils_1.getDecoratorName(decorator); | ||
if (name === 'HostListener') { | ||
@@ -94,3 +52,3 @@ this.visitNg2HostListener(decorator.parent, decorator, getDecoratorStringArgs(decorator)); | ||
Ng2Walker.prototype.visitPropertyDecorator = function (decorator) { | ||
var name = getDecoratorName(decorator); | ||
var name = utils_1.getDecoratorName(decorator); | ||
switch (name) { | ||
@@ -109,3 +67,4 @@ case 'Input': | ||
Ng2Walker.prototype.visitClassDecorator = function (decorator) { | ||
var name = getDecoratorName(decorator); | ||
var _this = this; | ||
var name = utils_1.getDecoratorName(decorator); | ||
if (!decorator.expression.arguments || | ||
@@ -118,20 +77,25 @@ !decorator.expression.arguments.length || | ||
this.visitNg2Component(decorator.parent, decorator); | ||
var inlineTemplate = decorator.expression.arguments[0] | ||
.properties.map(function (prop) { | ||
if (prop.name.text === 'template') { | ||
return prop; | ||
} | ||
return null; | ||
}).filter(function (el) { return !!el; }).map(function (prop) { return prop.initializer; }).pop(); | ||
var inlineTemplate = utils_1.getDecoratorPropertyInitializer(decorator, 'template'); | ||
if (inlineTemplate) { | ||
try { | ||
if (inlineTemplate.kind === ts.SyntaxKind.StringLiteral || | ||
inlineTemplate.kind === SyntaxKind.current().FirstTemplateToken) { | ||
this.visitNg2TemplateHelper(templateParser_1.parseTemplate(inlineTemplate.text), decorator.parent, inlineTemplate.pos + 2); | ||
if (utils_1.isSimpleTemplateString(inlineTemplate)) { | ||
var templateAst = templateParser_1.parseTemplate(inlineTemplate.text); | ||
this.visitNg2TemplateHelper(templateAst, decorator.parent, inlineTemplate.pos + 2); | ||
} | ||
} | ||
catch (e) { | ||
console.error('Cannot parse the template', e); | ||
} | ||
} | ||
var inlineStyles = utils_1.getDecoratorPropertyInitializer(decorator, 'styles'); | ||
if (inlineStyles && inlineStyles.kind === SyntaxKind.current().ArrayLiteralExpression) { | ||
inlineStyles.elements.forEach(function (inlineStyle) { | ||
try { | ||
if (utils_1.isSimpleTemplateString(inlineStyle)) { | ||
_this.visitNg2StyleHelper(parseCss_1.parseCss(inlineStyle.text), decorator.parent, inlineStyle.pos + 2); | ||
} | ||
} | ||
catch (e) { | ||
} | ||
}); | ||
} | ||
} | ||
@@ -145,30 +109,2 @@ else if (name === 'Directive') { | ||
}; | ||
Ng2Walker.prototype.visitNg2TemplateAST = function (ast, context, templateStart) { | ||
var _this = this; | ||
var templateVisitor = new this.TemplateVisitorCtr(this.getSourceFile(), this._originalOptions, context, templateStart); | ||
templateVisitor.visit(ast); | ||
templateVisitor.getFailures().forEach(function (f) { return _this.addFailure(f); }); | ||
}; | ||
Ng2Walker.prototype.visitNg2TemplateBoundText = function (text, context, templateStart) { | ||
if (expressionTypes_1.ExpTypes.ASTWithSource(text.value)) { | ||
var ast = text.value.ast; | ||
ast.interpolateExpression = text.value.source; | ||
this.visitNg2TemplateAST(ast, context, templateStart + getExpressionDisplacement(text)); | ||
} | ||
}; | ||
Ng2Walker.prototype.visitNg2TemplateBoundElementPropertyAst = function (prop, context, templateStart) { | ||
var ast = prop.value.ast; | ||
ast.interpolateExpression = prop.value.source; | ||
this.visitNg2TemplateAST(prop.value, context, templateStart + getExpressionDisplacement(prop)); | ||
}; | ||
Ng2Walker.prototype.visitNg2TemplateBoundElementEventAst = function (event, context, templateStart) { | ||
this.visitNg2TemplateAST(event.handler, context, templateStart + getExpressionDisplacement(event)); | ||
}; | ||
Ng2Walker.prototype.visitNg2TemplateElement = function (element, context, templateStart) { | ||
var _this = this; | ||
element.inputs.forEach(function (i) { return _this.visitNg2TemplateBoundElementPropertyAst(i, context, templateStart); }); | ||
element.outputs.forEach(function (o) { return _this.visitNg2TemplateBoundElementEventAst(o, context, templateStart); }); | ||
element.attrs.forEach(function (a) { return _this.visitNg2TemplateAttribute(a, templateStart); }); | ||
element.children.forEach(function (e) { return _this.visitNg2Template(e, context, templateStart); }); | ||
}; | ||
Ng2Walker.prototype.visitNg2Component = function (controller, decorator) { }; | ||
@@ -181,28 +117,33 @@ Ng2Walker.prototype.visitNg2Directive = function (controller, decorator) { }; | ||
Ng2Walker.prototype.visitNg2HostListener = function (method, decorator, args) { }; | ||
Ng2Walker.prototype.visitNg2TemplateAttribute = function (attr, templateStart) { }; | ||
Ng2Walker.prototype.visitNg2TemplateText = function (text, context, templateStart) { }; | ||
Ng2Walker.prototype.visitNg2Template = function (root, context, templateStart) { | ||
if (root instanceof compiler_1.ElementAst) { | ||
return this.visitNg2TemplateElement(root, context, templateStart); | ||
Ng2Walker.prototype.visitNg2TemplateHelper = function (roots, context, baseStart) { | ||
var _this = this; | ||
if (!roots || !roots.length) { | ||
return; | ||
} | ||
else if (root instanceof compiler_1.TextAst) { | ||
return this.visitNg2TemplateText(root, context, templateStart); | ||
else { | ||
var visitor = new this._config.templateVisitorCtrl(this.getSourceFile(), this._originalOptions, context, baseStart, this._config.expressionVisitorCtrl); | ||
compiler.templateVisitAll(visitor, roots, context); | ||
visitor.getFailures().forEach(function (f) { return _this.addFailure(f); }); | ||
} | ||
else if (root instanceof compiler_1.BoundTextAst) { | ||
return this.visitNg2TemplateBoundText(root, context, templateStart); | ||
} | ||
}; | ||
Ng2Walker.prototype.visitNg2TemplateHelper = function (roots, context, baseStart) { | ||
Ng2Walker.prototype.visitNg2StyleHelper = function (style, context, baseStart) { | ||
var _this = this; | ||
if (!roots || !roots.length) { | ||
if (!style) { | ||
return; | ||
} | ||
else { | ||
roots.forEach(function (root) { | ||
return _this.visitNg2Template(root, context, baseStart); | ||
}); | ||
var visitor = new this._config.cssVisitorCtrl(this.getSourceFile(), this._originalOptions, context, baseStart); | ||
style.visit(visitor); | ||
visitor.getFailures().forEach(function (f) { return _this.addFailure(f); }); | ||
} | ||
}; | ||
Ng2Walker.prototype._normalizeConfig = function (config) { | ||
this._config = Object.assign({ | ||
templateVisitorCtrl: basicTemplateAstVisitor_1.BasicTemplateAstVisitor, | ||
expressionVisitorCtrl: recursiveAngularExpressionVisitor_1.RecursiveAngularExpressionVisitor, | ||
cssVisitorCtrl: basicCssAstVisitor_1.BasicCssAstVisitor | ||
}, this._config || {}); | ||
}; | ||
return Ng2Walker; | ||
}(Lint.RuleWalker)); | ||
exports.Ng2Walker = Ng2Walker; |
@@ -11,3 +11,3 @@ "use strict"; | ||
var ng2Walker_1 = require('./angular/ng2Walker'); | ||
var recursiveAngularExpressionVisitor_1 = require('./angular/recursiveAngularExpressionVisitor'); | ||
var recursiveAngularExpressionVisitor_1 = require('./angular/templates/recursiveAngularExpressionVisitor'); | ||
var classDeclarationUtils_1 = require('./util/classDeclarationUtils'); | ||
@@ -44,3 +44,4 @@ var DeclarationType; | ||
available = classDeclarationUtils_1.getDeclaredMethodNames(this.context) | ||
.concat(classDeclarationUtils_1.getDeclaredPropertyNames(this.context)); | ||
.concat(classDeclarationUtils_1.getDeclaredPropertyNames(this.context)) | ||
.concat(this.preDefinedVariables); | ||
ast.receiver.visit(this); | ||
@@ -110,3 +111,5 @@ if (ast.receiver && ast.receiver.name) { | ||
Rule.prototype.apply = function (sourceFile) { | ||
return this.applyWithWalker(new ng2Walker_1.Ng2Walker(sourceFile, this.getOptions(), SymbolAccessValidator)); | ||
return this.applyWithWalker(new ng2Walker_1.Ng2Walker(sourceFile, this.getOptions(), { | ||
expressionVisitorCtrl: SymbolAccessValidator | ||
})); | ||
}; | ||
@@ -113,0 +116,0 @@ Rule.FAILURE = 'The %s "%s" that you\'re trying to access does not exist in the class declaration.'; |
@@ -51,3 +51,3 @@ "use strict"; | ||
var name = expr.text; | ||
if (name == 'Attribute') { | ||
if (name === 'Attribute') { | ||
var failureConfig = [className, parameterName, parameterName]; | ||
@@ -54,0 +54,0 @@ failureConfig.unshift(Rule.FAILURE_STRING); |
{ | ||
"name": "codelyzer", | ||
"version": "1.0.0-beta.2", | ||
"version": "1.0.0-beta.3", | ||
"description": "Linting for Angular 2 applications, following https:/angular.io/styleguide.", | ||
@@ -34,8 +34,10 @@ "contributors": [ | ||
"tslint": "^3.9.0", | ||
"@angular/compiler": "~2.1.0", | ||
"@angular/core": "~2.1.0" | ||
"@angular/compiler": "~2.1.1", | ||
"@angular/core": "~2.1.1" | ||
}, | ||
"dependencies": { | ||
"css-selector-tokenizer": "^0.7.0", | ||
"cssauron": "^1.4.0", | ||
"sprintf-js": "^1.0.3" | ||
} | ||
} |
@@ -10,3 +10,3 @@ "use strict"; | ||
var ng2Walker_1 = require('./angular/ng2Walker'); | ||
var recursiveAngularExpressionVisitor_1 = require('./angular/recursiveAngularExpressionVisitor'); | ||
var recursiveAngularExpressionVisitor_1 = require('./angular/templates/recursiveAngularExpressionVisitor'); | ||
var SyntaxKind = require('./util/syntaxKind'); | ||
@@ -88,3 +88,5 @@ var DeclarationType; | ||
Rule.prototype.apply = function (sourceFile) { | ||
return this.applyWithWalker(new ng2Walker_1.Ng2Walker(sourceFile, this.getOptions(), SymbolAccessValidator)); | ||
return this.applyWithWalker(new ng2Walker_1.Ng2Walker(sourceFile, this.getOptions(), { | ||
expressionVisitorCtrl: SymbolAccessValidator | ||
})); | ||
}; | ||
@@ -91,0 +93,0 @@ Rule.FAILURE = 'The %s "%s" that you\'re trying to access does not exist in the class declaration.'; |
@@ -5,3 +5,4 @@ "use strict"; | ||
exports.getDeclaredPropertyNames = function (declaration) { | ||
return declaration.members.filter(function (m) { return m.kind === SyntaxKind.PropertyDeclaration; }) | ||
return declaration.members.filter(function (m) { return m.kind === SyntaxKind.PropertyDeclaration || | ||
m.kind === SyntaxKind.GetAccessor || m.kind === SyntaxKind.SetAccessor; }) | ||
.map(function (d) { return d.name.text; }); | ||
@@ -8,0 +9,0 @@ }; |
"use strict"; | ||
var ts = require('typescript'); | ||
var SyntaxKind = require('./syntaxKind'); | ||
exports.stringDistance = function (s, t, ls, lt) { | ||
@@ -21,1 +23,33 @@ if (ls === void 0) { ls = s.length; } | ||
}; | ||
exports.isSimpleTemplateString = function (e) { | ||
return e.kind === ts.SyntaxKind.StringLiteral || | ||
e.kind === SyntaxKind.current().FirstTemplateToken; | ||
}; | ||
exports.getDecoratorPropertyInitializer = function (decorator, name) { | ||
return decorator.expression.arguments[0] | ||
.properties.map(function (prop) { | ||
if (prop.name.text === name) { | ||
return prop; | ||
} | ||
return null; | ||
}).filter(function (el) { return !!el; }).map(function (prop) { return prop.initializer; }).pop(); | ||
}; | ||
exports.getDecoratorName = function (decorator) { | ||
var baseExpr = decorator.expression || {}; | ||
var expr = baseExpr.expression || {}; | ||
return expr.text; | ||
}; | ||
exports.getComponentDecorator = function (declaration) { | ||
return (declaration.decorators || []) | ||
.filter(function (d) { | ||
if (!d.expression.arguments || | ||
!d.expression.arguments.length || | ||
!d.expression.arguments[0].properties) { | ||
return false; | ||
} | ||
var name = exports.getDecoratorName(d); | ||
if (name === 'Component') { | ||
return true; | ||
} | ||
}).pop(); | ||
}; |
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
229182
45
5902
6
+ Addedcssauron@^1.4.0
+ Addedcss-selector-tokenizer@0.7.3(transitive)
+ Addedcssauron@1.4.0(transitive)
+ Addedcssesc@3.0.0(transitive)
+ Addedfastparse@1.1.2(transitive)
+ Addedthrough@2.3.8(transitive)