Comparing version 1.0.0-beta.4 to 2.0.0-beta.0
@@ -1,1 +0,30 @@ | ||
export declare const INTERPOLATION: [string, string]; | ||
import * as ts from 'typescript'; | ||
import { CodeWithSourceMap } from './metadata'; | ||
export interface UrlResolver { | ||
(url: string, d: ts.Decorator): string; | ||
} | ||
export interface TemplateTransformer { | ||
(template: string, url: string, d: ts.Decorator): CodeWithSourceMap; | ||
} | ||
export interface StyleTransformer { | ||
(style: string, url: string, d: ts.Decorator): CodeWithSourceMap; | ||
} | ||
export declare const LogLevel: { | ||
None: number; | ||
Error: number; | ||
Info: number; | ||
Debug: number; | ||
}; | ||
export interface Config { | ||
interpolation: [string, string]; | ||
resolveUrl: UrlResolver; | ||
transformTemplate: TemplateTransformer; | ||
transformStyle: StyleTransformer; | ||
predefinedDirectives: DirectiveDeclaration[]; | ||
logLevel: number; | ||
} | ||
export interface DirectiveDeclaration { | ||
selector: string; | ||
exportAs: string; | ||
} | ||
export declare const Config: Config; |
"use strict"; | ||
exports.INTERPOLATION = ['{{', '}}']; | ||
exports.LogLevel = { | ||
None: 0, | ||
Error: 1, | ||
Info: 3, | ||
Debug: 7 | ||
}; | ||
var BUILD_TYPE = 'prod'; | ||
exports.Config = { | ||
interpolation: ['{{', '}}'], | ||
resolveUrl: function (url, d) { | ||
return url; | ||
}, | ||
transformTemplate: function (code, url, d) { | ||
return { code: code, url: url }; | ||
}, | ||
transformStyle: function (code, url, d) { | ||
return { code: code, url: url }; | ||
}, | ||
predefinedDirectives: [ | ||
{ selector: 'form', exportAs: 'ngForm' } | ||
], | ||
logLevel: BUILD_TYPE === 'dev' ? exports.LogLevel.Debug : exports.LogLevel.None | ||
}; | ||
var root = require('app-root-path'); | ||
try { | ||
var newConfig = require(root.path + '/.codelyzer'); | ||
Object.assign(exports.Config, newConfig); | ||
} | ||
catch (e) { | ||
console.info('Cannot find ".codelyzer.js" in the root of the project'); | ||
} |
@@ -1,2 +0,2 @@ | ||
import * as Lint from 'tslint/lib/lint'; | ||
import * as Lint from 'tslint'; | ||
import * as ts from 'typescript'; | ||
@@ -7,2 +7,4 @@ import * as compiler from '@angular/compiler'; | ||
import { RecursiveAngularExpressionVisitorCtr, TemplateAstVisitorCtr } from './templates/basicTemplateAstVisitor'; | ||
import { MetadataReader } from './metadataReader'; | ||
import { ComponentMetadata, DirectiveMetadata, StyleMetadata } from './metadata'; | ||
export interface Ng2WalkerConfig { | ||
@@ -16,3 +18,4 @@ expressionVisitorCtrl?: RecursiveAngularExpressionVisitorCtr; | ||
private _config; | ||
constructor(sourceFile: ts.SourceFile, _originalOptions: Lint.IOptions, _config?: Ng2WalkerConfig); | ||
protected _metadataReader: MetadataReader; | ||
constructor(sourceFile: ts.SourceFile, _originalOptions: Lint.IOptions, _config?: Ng2WalkerConfig, _metadataReader?: MetadataReader); | ||
visitClassDeclaration(declaration: ts.ClassDeclaration): void; | ||
@@ -24,4 +27,4 @@ visitMethodDeclaration(method: ts.MethodDeclaration): void; | ||
protected visitClassDecorator(decorator: ts.Decorator): void; | ||
protected visitNg2Component(controller: ts.ClassDeclaration, decorator: ts.Decorator): void; | ||
protected visitNg2Directive(controller: ts.ClassDeclaration, decorator: ts.Decorator): void; | ||
protected visitNg2Component(metadata: ComponentMetadata): void; | ||
protected visitNg2Directive(metadata: DirectiveMetadata): void; | ||
protected visitNg2Pipe(controller: ts.ClassDeclaration, decorator: ts.Decorator): void; | ||
@@ -32,5 +35,5 @@ protected visitNg2Input(property: ts.PropertyDeclaration, input: ts.Decorator, args: string[]): void; | ||
protected visitNg2HostListener(method: ts.MethodDeclaration, decorator: ts.Decorator, args: string[]): void; | ||
protected visitNg2TemplateHelper(roots: compiler.TemplateAst[], context: ts.ClassDeclaration, baseStart: number): void; | ||
protected visitNg2StyleHelper(style: CssAst, context: ts.ClassDeclaration, baseStart: number): void; | ||
private _normalizeConfig(config?); | ||
protected visitNg2TemplateHelper(roots: compiler.TemplateAst[], context: ComponentMetadata, baseStart: number): void; | ||
protected visitNg2StyleHelper(style: CssAst, context: ComponentMetadata, styleMetadata: StyleMetadata, baseStart: number): void; | ||
protected getContextSourceFile(path: string, content: string): ts.SourceFile; | ||
} |
@@ -7,3 +7,3 @@ "use strict"; | ||
}; | ||
var Lint = require("tslint/lib/lint"); | ||
var Lint = require("tslint"); | ||
var ts = require("typescript"); | ||
@@ -16,4 +16,7 @@ var compiler = require("@angular/compiler"); | ||
var recursiveAngularExpressionVisitor_1 = require("./templates/recursiveAngularExpressionVisitor"); | ||
var metadata_1 = require("./metadata"); | ||
var ng2WalkerFactoryUtils_1 = require("./ng2WalkerFactoryUtils"); | ||
var config_1 = require("./config"); | ||
var logger_1 = require("../util/logger"); | ||
var utils_1 = require("../util/utils"); | ||
var SyntaxKind = require("../util/syntaxKind"); | ||
var getDecoratorStringArgs = function (decorator) { | ||
@@ -26,10 +29,28 @@ var baseExpr = decorator.expression || {}; | ||
__extends(Ng2Walker, _super); | ||
function Ng2Walker(sourceFile, _originalOptions, _config) { | ||
function Ng2Walker(sourceFile, _originalOptions, _config, _metadataReader) { | ||
var _this = _super.call(this, sourceFile, _originalOptions) || this; | ||
_this._originalOptions = _originalOptions; | ||
_this._config = _config; | ||
_this._normalizeConfig(_config); | ||
_this._metadataReader = _metadataReader; | ||
_this._metadataReader = _this._metadataReader || ng2WalkerFactoryUtils_1.ng2WalkerFactoryUtils.defaultMetadataReader(); | ||
_this._config = Object.assign({ | ||
templateVisitorCtrl: basicTemplateAstVisitor_1.BasicTemplateAstVisitor, | ||
expressionVisitorCtrl: recursiveAngularExpressionVisitor_1.RecursiveAngularExpressionVisitor, | ||
cssVisitorCtrl: basicCssAstVisitor_1.BasicCssAstVisitor | ||
}, _this._config || {}); | ||
_this._config = Object.assign({ | ||
templateVisitorCtrl: basicTemplateAstVisitor_1.BasicTemplateAstVisitor, | ||
expressionVisitorCtrl: recursiveAngularExpressionVisitor_1.RecursiveAngularExpressionVisitor, | ||
cssVisitorCtrl: basicCssAstVisitor_1.BasicCssAstVisitor | ||
}, _this._config || {}); | ||
return _this; | ||
} | ||
Ng2Walker.prototype.visitClassDeclaration = function (declaration) { | ||
var metadata = this._metadataReader.read(declaration); | ||
if (metadata instanceof metadata_1.ComponentMetadata) { | ||
this.visitNg2Component(metadata); | ||
} | ||
else if (metadata instanceof metadata_1.DirectiveMetadata) { | ||
this.visitNg2Directive(metadata); | ||
} | ||
(declaration.decorators || []).forEach(this.visitClassDecorator.bind(this)); | ||
@@ -67,3 +88,2 @@ _super.prototype.visitClassDeclaration.call(this, declaration); | ||
Ng2Walker.prototype.visitClassDecorator = function (decorator) { | ||
var _this = this; | ||
var name = utils_1.getDecoratorName(decorator); | ||
@@ -75,37 +95,42 @@ if (!decorator.expression.arguments || | ||
} | ||
if (name === 'Component') { | ||
this.visitNg2Component(decorator.parent, decorator); | ||
var inlineTemplate = utils_1.getDecoratorPropertyInitializer(decorator, 'template'); | ||
if (inlineTemplate) { | ||
if (name === 'Pipe') { | ||
this.visitNg2Pipe(decorator.parent, decorator); | ||
} | ||
}; | ||
Ng2Walker.prototype.visitNg2Component = function (metadata) { | ||
var template = metadata.template; | ||
var getPosition = function (node) { | ||
var pos = 0; | ||
if (node) { | ||
pos = node.pos + 1; | ||
try { | ||
if (utils_1.isSimpleTemplateString(inlineTemplate)) { | ||
var templateAst = templateParser_1.parseTemplate(inlineTemplate.text); | ||
this.visitNg2TemplateHelper(templateAst, decorator.parent, inlineTemplate.pos + 2); | ||
} | ||
pos = node.getStart() + 1; | ||
} | ||
catch (e) { } | ||
} | ||
return pos; | ||
}; | ||
if (template && template.template) { | ||
try { | ||
var templateAst = templateParser_1.parseTemplate(template.template.code, config_1.Config.predefinedDirectives); | ||
this.visitNg2TemplateHelper(templateAst, metadata, getPosition(template.node)); | ||
} | ||
catch (e) { | ||
logger_1.logger.error('Cannot parse the template of', ((metadata.controller || {}).name || {}).text); | ||
} | ||
} | ||
var styles = metadata.styles; | ||
if (styles && styles.length) { | ||
for (var i = 0; i < styles.length; i += 1) { | ||
var style = styles[i]; | ||
try { | ||
this.visitNg2StyleHelper(parseCss_1.parseCss(style.style.code), metadata, style, getPosition(style.node)); | ||
} | ||
catch (e) { | ||
logger_1.logger.error('Cannot parse the styles of', ((metadata.controller || {}).name || {}).text); | ||
} | ||
} | ||
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) { | ||
} | ||
}); | ||
} | ||
} | ||
else if (name === 'Directive') { | ||
this.visitNg2Directive(decorator.parent, decorator); | ||
} | ||
else if (name === 'Pipe') { | ||
this.visitNg2Pipe(decorator.parent, decorator); | ||
} | ||
}; | ||
Ng2Walker.prototype.visitNg2Component = function (controller, decorator) { }; | ||
Ng2Walker.prototype.visitNg2Directive = function (controller, decorator) { }; | ||
Ng2Walker.prototype.visitNg2Directive = function (metadata) { }; | ||
Ng2Walker.prototype.visitNg2Pipe = function (controller, decorator) { }; | ||
@@ -122,8 +147,9 @@ Ng2Walker.prototype.visitNg2Input = function (property, input, args) { }; | ||
else { | ||
var visitor = new this._config.templateVisitorCtrl(this.getSourceFile(), this._originalOptions, context, baseStart, this._config.expressionVisitorCtrl); | ||
compiler.templateVisitAll(visitor, roots, context); | ||
var sourceFile = this.getContextSourceFile(context.template.url, context.template.template.source); | ||
var visitor = new this._config.templateVisitorCtrl(sourceFile, this._originalOptions, context, baseStart, this._config.expressionVisitorCtrl); | ||
compiler.templateVisitAll(visitor, roots, context.controller); | ||
visitor.getFailures().forEach(function (f) { return _this.addFailure(f); }); | ||
} | ||
}; | ||
Ng2Walker.prototype.visitNg2StyleHelper = function (style, context, baseStart) { | ||
Ng2Walker.prototype.visitNg2StyleHelper = function (style, context, styleMetadata, baseStart) { | ||
var _this = this; | ||
@@ -134,3 +160,4 @@ if (!style) { | ||
else { | ||
var visitor = new this._config.cssVisitorCtrl(this.getSourceFile(), this._originalOptions, context, baseStart); | ||
var sourceFile = this.getContextSourceFile(styleMetadata.url, styleMetadata.style.source); | ||
var visitor = new this._config.cssVisitorCtrl(sourceFile, this._originalOptions, context, styleMetadata, baseStart); | ||
style.visit(visitor); | ||
@@ -140,8 +167,8 @@ 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 || {}); | ||
Ng2Walker.prototype.getContextSourceFile = function (path, content) { | ||
var current = this.getSourceFile(); | ||
if (!path) { | ||
return current; | ||
} | ||
return ts.createSourceFile(path, "`" + content + "`", ts.ScriptTarget.ES5); | ||
}; | ||
@@ -148,0 +175,0 @@ return Ng2Walker; |
@@ -0,12 +1,14 @@ | ||
import * as ts from 'typescript'; | ||
import * as Lint from 'tslint'; | ||
import * as ast from './cssAst'; | ||
import * as ts from 'typescript'; | ||
import * as Lint from 'tslint/lib/lint'; | ||
import { SourceMappingVisitor } from '../sourceMappingVisitor'; | ||
import { ComponentMetadata, StyleMetadata } from '../metadata'; | ||
export interface CssAstVisitorCtrl { | ||
new (sourceFile: ts.SourceFile, options: Lint.IOptions, context: ts.ClassDeclaration, templateStart: number): any; | ||
new (sourceFile: ts.SourceFile, options: Lint.IOptions, context: ComponentMetadata, style: StyleMetadata, templateStart: number): any; | ||
} | ||
export declare class BasicCssAstVisitor extends Lint.RuleWalker implements ast.CssAstVisitor { | ||
export declare class BasicCssAstVisitor extends SourceMappingVisitor implements ast.CssAstVisitor { | ||
protected _originalOptions: Lint.IOptions; | ||
protected context: ts.ClassDeclaration; | ||
protected context: ComponentMetadata; | ||
protected templateStart: number; | ||
constructor(sourceFile: ts.SourceFile, _originalOptions: Lint.IOptions, context: ts.ClassDeclaration, templateStart: number); | ||
constructor(sourceFile: ts.SourceFile, _originalOptions: Lint.IOptions, context: ComponentMetadata, style: StyleMetadata, templateStart: number); | ||
visitCssValue(ast: ast.CssStyleValueAst, context?: any): any; | ||
@@ -13,0 +15,0 @@ visitCssInlineRule(ast: ast.CssInlineRuleAst, context?: any): any; |
@@ -7,7 +7,7 @@ "use strict"; | ||
}; | ||
var Lint = require("tslint/lib/lint"); | ||
var sourceMappingVisitor_1 = require("../sourceMappingVisitor"); | ||
var BasicCssAstVisitor = (function (_super) { | ||
__extends(BasicCssAstVisitor, _super); | ||
function BasicCssAstVisitor(sourceFile, _originalOptions, context, templateStart) { | ||
var _this = _super.call(this, sourceFile, _originalOptions) || this; | ||
function BasicCssAstVisitor(sourceFile, _originalOptions, context, style, templateStart) { | ||
var _this = _super.call(this, sourceFile, _originalOptions, style.style, templateStart) || this; | ||
_this._originalOptions = _originalOptions; | ||
@@ -63,3 +63,3 @@ _this.context = context; | ||
return BasicCssAstVisitor; | ||
}(Lint.RuleWalker)); | ||
}(sourceMappingVisitor_1.SourceMappingVisitor)); | ||
exports.BasicCssAstVisitor = BasicCssAstVisitor; |
import * as ast from '@angular/compiler'; | ||
import * as ts from 'typescript'; | ||
import * as Lint from 'tslint/lib/lint'; | ||
import * as Lint from 'tslint'; | ||
import * as e from '@angular/compiler/src/expression_parser/ast'; | ||
import { ComponentMetadata } from '../metadata'; | ||
import { SourceMappingVisitor } from '../sourceMappingVisitor'; | ||
export interface RecursiveAngularExpressionVisitorCtr { | ||
new (sourceFile: ts.SourceFile, options: Lint.IOptions, context: ts.ClassDeclaration, basePosition: number): any; | ||
new (sourceFile: ts.SourceFile, options: Lint.IOptions, context: ComponentMetadata, basePosition: number): any; | ||
} | ||
export interface TemplateAstVisitorCtr { | ||
new (sourceFile: ts.SourceFile, options: Lint.IOptions, context: ts.ClassDeclaration, templateStart: number, expressionVisitorCtrl: RecursiveAngularExpressionVisitorCtr): any; | ||
new (sourceFile: ts.SourceFile, options: Lint.IOptions, context: ComponentMetadata, templateStart: number, expressionVisitorCtrl: RecursiveAngularExpressionVisitorCtr): any; | ||
} | ||
export declare class BasicTemplateAstVisitor extends Lint.RuleWalker implements ast.TemplateAstVisitor { | ||
export declare class BasicTemplateAstVisitor extends SourceMappingVisitor implements ast.TemplateAstVisitor { | ||
private _originalOptions; | ||
private context; | ||
protected context: ComponentMetadata; | ||
protected templateStart: number; | ||
private expressionVisitorCtrl; | ||
private _variables; | ||
constructor(sourceFile: ts.SourceFile, _originalOptions: Lint.IOptions, context: ts.ClassDeclaration, templateStart: number, expressionVisitorCtrl?: RecursiveAngularExpressionVisitorCtr); | ||
constructor(sourceFile: ts.SourceFile, _originalOptions: Lint.IOptions, context: ComponentMetadata, templateStart: number, expressionVisitorCtrl?: RecursiveAngularExpressionVisitorCtr); | ||
protected visitNg2TemplateAST(ast: e.AST, templateStart: number): void; | ||
@@ -19,0 +21,0 @@ visit?(node: ast.TemplateAst, context: any): any; |
@@ -8,5 +8,5 @@ "use strict"; | ||
var ast = require("@angular/compiler"); | ||
var Lint = require("tslint/lib/lint"); | ||
var expressionTypes_1 = require("../expressionTypes"); | ||
var recursiveAngularExpressionVisitor_1 = require("./recursiveAngularExpressionVisitor"); | ||
var sourceMappingVisitor_1 = require("../sourceMappingVisitor"); | ||
var getExpressionDisplacement = function (binding) { | ||
@@ -56,3 +56,3 @@ var attrLen = 0; | ||
if (expressionVisitorCtrl === void 0) { expressionVisitorCtrl = recursiveAngularExpressionVisitor_1.RecursiveAngularExpressionVisitor; } | ||
var _this = _super.call(this, sourceFile, _originalOptions) || this; | ||
var _this = _super.call(this, sourceFile, _originalOptions, context.template.template, templateStart) || this; | ||
_this._originalOptions = _originalOptions; | ||
@@ -87,2 +87,6 @@ _this.context = context; | ||
var _this = this; | ||
var references = element.references.map(function (r) { return r.name; }); | ||
var oldVariables = this._variables; | ||
this._variables = this._variables.concat(references); | ||
element.references.forEach(function (r) { return _this.visit(r, context); }); | ||
element.inputs.forEach(function (i) { return _this.visit(i, context); }); | ||
@@ -92,4 +96,4 @@ element.outputs.forEach(function (o) { return _this.visit(o, context); }); | ||
element.children.forEach(function (e) { return _this.visit(e, context); }); | ||
element.references.forEach(function (r) { return _this.visit(r, context); }); | ||
element.directives.forEach(function (d) { return _this.visit(d, context); }); | ||
this._variables = oldVariables; | ||
}; | ||
@@ -125,3 +129,3 @@ BasicTemplateAstVisitor.prototype.visitReference = function (ast, context) { | ||
return BasicTemplateAstVisitor; | ||
}(Lint.RuleWalker)); | ||
}(sourceMappingVisitor_1.SourceMappingVisitor)); | ||
exports.BasicTemplateAstVisitor = BasicTemplateAstVisitor; |
@@ -1,9 +0,11 @@ | ||
import * as Lint from 'tslint/lib/lint'; | ||
import * as Lint from 'tslint'; | ||
import * as ts from 'typescript'; | ||
import * as e from '@angular/compiler/src/expression_parser/ast'; | ||
export declare class RecursiveAngularExpressionVisitor extends Lint.RuleWalker implements e.AstVisitor { | ||
protected context: ts.ClassDeclaration; | ||
import { SourceMappingVisitor } from '../sourceMappingVisitor'; | ||
import { ComponentMetadata } from '../metadata'; | ||
export declare class RecursiveAngularExpressionVisitor extends SourceMappingVisitor implements e.AstVisitor { | ||
protected context: ComponentMetadata; | ||
protected basePosition: number; | ||
preDefinedVariables: any[]; | ||
constructor(sourceFile: ts.SourceFile, options: Lint.IOptions, context: ts.ClassDeclaration, basePosition: number); | ||
constructor(sourceFile: ts.SourceFile, options: Lint.IOptions, context: ComponentMetadata, basePosition: number); | ||
visit(ast: e.AST, context: any): any; | ||
@@ -10,0 +12,0 @@ visitBinary(ast: e.Binary, context: any): any; |
@@ -7,7 +7,7 @@ "use strict"; | ||
}; | ||
var Lint = require("tslint/lib/lint"); | ||
var sourceMappingVisitor_1 = require("../sourceMappingVisitor"); | ||
var RecursiveAngularExpressionVisitor = (function (_super) { | ||
__extends(RecursiveAngularExpressionVisitor, _super); | ||
function RecursiveAngularExpressionVisitor(sourceFile, options, context, basePosition) { | ||
var _this = _super.call(this, sourceFile, options) || this; | ||
var _this = _super.call(this, sourceFile, options, context.template.template, basePosition) || this; | ||
_this.context = context; | ||
@@ -98,3 +98,3 @@ _this.basePosition = basePosition; | ||
return RecursiveAngularExpressionVisitor; | ||
}(Lint.RuleWalker)); | ||
}(sourceMappingVisitor_1.SourceMappingVisitor)); | ||
exports.RecursiveAngularExpressionVisitor = RecursiveAngularExpressionVisitor; |
@@ -1,1 +0,4 @@ | ||
export declare const parseTemplate: (template: string) => any; | ||
export declare const parseTemplate: (template: string, directives?: { | ||
selector: string; | ||
exportAs: string; | ||
}[]) => any; |
"use strict"; | ||
var core_1 = require("@angular/core"); | ||
var compiler = require("@angular/compiler"); | ||
var config_1 = require("../config"); | ||
var compiler = require("@angular/compiler"); | ||
exports.parseTemplate = function (template) { | ||
var refId = 0; | ||
var dummyMetadataFactory = function (selector, exportAs) { | ||
if (refId > 1e10) { | ||
refId = 0; | ||
} | ||
return { | ||
inputs: {}, | ||
outputs: {}, | ||
hostListeners: {}, | ||
hostProperties: {}, | ||
hostAttributes: {}, | ||
isSummary: true, | ||
type: { | ||
diDeps: [], | ||
lifecycleHooks: [], | ||
isHost: false, | ||
reference: ++refId + '-ref' | ||
}, | ||
isComponent: false, | ||
selector: selector, | ||
exportAs: exportAs, | ||
providers: [], | ||
viewProviders: [], | ||
queries: [], | ||
entryComponents: [], | ||
changeDetection: 0, | ||
template: { | ||
isSummary: true, | ||
animations: [], | ||
ngContentSelectors: [], | ||
encapsulation: 0 | ||
} | ||
}; | ||
}; | ||
var defaultDirectives = []; | ||
exports.parseTemplate = function (template, directives) { | ||
if (directives === void 0) { directives = []; } | ||
defaultDirectives = directives.map(function (d) { return dummyMetadataFactory(d.selector, d.exportAs); }); | ||
var TemplateParser = compiler.TemplateParser; | ||
@@ -12,3 +49,3 @@ var expressionParser = new compiler.Parser(new compiler.Lexer()); | ||
var tmplParser = new TemplateParser(expressionParser, elementSchemaRegistry, htmlParser, ngConsole, []); | ||
var interpolation = config_1.INTERPOLATION; | ||
var interpolation = config_1.Config.interpolation; | ||
var templateMetadata = { | ||
@@ -34,3 +71,3 @@ encapsulation: 0, | ||
var type = new compiler.CompileTypeMetadata({ diDeps: [] }); | ||
return tmplParser.tryParse(compiler.CompileDirectiveMetadata.create({ type: type, template: templateMetadata }), template, [], [], [core_1.NO_ERRORS_SCHEMA], '').templateAst; | ||
return tmplParser.tryParse(compiler.CompileDirectiveMetadata.create({ type: type, template: templateMetadata }), template, defaultDirectives, [], [core_1.NO_ERRORS_SCHEMA], '').templateAst; | ||
}; |
@@ -1,4 +0,5 @@ | ||
import * as Lint from 'tslint/lib/lint'; | ||
import * as Lint from 'tslint'; | ||
import * as ts from 'typescript'; | ||
import { Ng2Walker } from './angular/ng2Walker'; | ||
import { ComponentMetadata } from './angular/metadata'; | ||
export declare class Rule extends Lint.Rules.AbstractRule { | ||
@@ -10,3 +11,3 @@ static FAILURE: string; | ||
export declare class ClassMetadataWalker extends Ng2Walker { | ||
visitNg2Component(controller: ts.ClassDeclaration, decorator: ts.Decorator): void; | ||
visitNg2Component(meta: ComponentMetadata): void; | ||
} |
@@ -7,3 +7,3 @@ "use strict"; | ||
}; | ||
var Lint = require("tslint/lib/lint"); | ||
var Lint = require("tslint"); | ||
var sprintf_js_1 = require("sprintf-js"); | ||
@@ -31,4 +31,4 @@ var ng2Walker_1 = require("./angular/ng2Walker"); | ||
} | ||
ClassMetadataWalker.prototype.visitNg2Component = function (controller, decorator) { | ||
var name = controller.name; | ||
ClassMetadataWalker.prototype.visitNg2Component = function (meta) { | ||
var name = meta.controller.name; | ||
var className = name.text; | ||
@@ -38,2 +38,3 @@ if (!Rule.validate(className)) { | ||
} | ||
_super.prototype.visitNg2Component.call(this, meta); | ||
}; | ||
@@ -40,0 +41,0 @@ return ClassMetadataWalker; |
@@ -1,4 +0,5 @@ | ||
import * as Lint from 'tslint/lib/lint'; | ||
import * as Lint from 'tslint'; | ||
import * as ts from 'typescript'; | ||
import { Ng2Walker } from './angular/ng2Walker'; | ||
import { DirectiveMetadata } from './angular/metadata'; | ||
export declare class Rule extends Lint.Rules.AbstractRule { | ||
@@ -10,3 +11,3 @@ static FAILURE: string; | ||
export declare class ClassMetadataWalker extends Ng2Walker { | ||
visitNg2Directive(controller: ts.ClassDeclaration, decorator: ts.Decorator): void; | ||
visitNg2Directive(meta: DirectiveMetadata): void; | ||
} |
@@ -7,3 +7,3 @@ "use strict"; | ||
}; | ||
var Lint = require("tslint/lib/lint"); | ||
var Lint = require("tslint"); | ||
var sprintf_js_1 = require("sprintf-js"); | ||
@@ -31,4 +31,4 @@ var ng2Walker_1 = require("./angular/ng2Walker"); | ||
} | ||
ClassMetadataWalker.prototype.visitNg2Directive = function (controller, decorator) { | ||
var name = controller.name; | ||
ClassMetadataWalker.prototype.visitNg2Directive = function (meta) { | ||
var name = meta.controller.name; | ||
var className = name.text; | ||
@@ -35,0 +35,0 @@ if (!Rule.validate(className)) { |
import * as ts from 'typescript'; | ||
import * as Lint from 'tslint/lib/lint'; | ||
import * as Lint from 'tslint'; | ||
export declare class Rule extends Lint.Rules.AbstractRule { | ||
@@ -4,0 +4,0 @@ static FAILURE_STRING: string; |
@@ -8,3 +8,3 @@ "use strict"; | ||
var ts = require("typescript"); | ||
var Lint = require("tslint/lib/lint"); | ||
var Lint = require("tslint"); | ||
var Rule = (function (_super) { | ||
@@ -11,0 +11,0 @@ __extends(Rule, _super); |
export { Rule as ComponentClassSuffixRule } from './componentClassSuffixRule'; | ||
export { Rule as ComponentSelectorNameRule } from './componentSelectorNameRule'; | ||
export { Rule as ComponentSelectorPrefixRule } from './componentSelectorPrefixRule'; | ||
export { Rule as ComponentSelectorTypeRule } from './componentSelectorTypeRule'; | ||
export { Rule as ComponentSelectorRule } from './componentSelectorRule'; | ||
export { Rule as DirectiveClassSuffixRule } from './directiveClassSuffixRule'; | ||
export { Rule as DirectiveSelectorNameRule } from './directiveSelectorNameRule'; | ||
export { Rule as DirectiveSelectorPrefixRule } from './directiveSelectorPrefixRule'; | ||
export { Rule as DirectiveSelectorTypeRule } from './directiveSelectorTypeRule'; | ||
export { Rule as DirectiveSelectorRule } from './directiveSelectorRule'; | ||
export { Rule as ImportDestructuringSpacingRule } from './importDestructuringSpacingRule'; | ||
@@ -25,1 +21,2 @@ export { Rule as InvokeInjectableRule } from './invokeInjectableRule'; | ||
export { Rule as UsePipeTransformInterfaceRule } from './usePipeTransformInterfaceRule'; | ||
export * from './angular/config'; |
20
index.js
"use strict"; | ||
function __export(m) { | ||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; | ||
} | ||
var componentClassSuffixRule_1 = require("./componentClassSuffixRule"); | ||
exports.ComponentClassSuffixRule = componentClassSuffixRule_1.Rule; | ||
var componentSelectorNameRule_1 = require("./componentSelectorNameRule"); | ||
exports.ComponentSelectorNameRule = componentSelectorNameRule_1.Rule; | ||
var componentSelectorPrefixRule_1 = require("./componentSelectorPrefixRule"); | ||
exports.ComponentSelectorPrefixRule = componentSelectorPrefixRule_1.Rule; | ||
var componentSelectorTypeRule_1 = require("./componentSelectorTypeRule"); | ||
exports.ComponentSelectorTypeRule = componentSelectorTypeRule_1.Rule; | ||
var componentSelectorRule_1 = require("./componentSelectorRule"); | ||
exports.ComponentSelectorRule = componentSelectorRule_1.Rule; | ||
var directiveClassSuffixRule_1 = require("./directiveClassSuffixRule"); | ||
exports.DirectiveClassSuffixRule = directiveClassSuffixRule_1.Rule; | ||
var directiveSelectorNameRule_1 = require("./directiveSelectorNameRule"); | ||
exports.DirectiveSelectorNameRule = directiveSelectorNameRule_1.Rule; | ||
var directiveSelectorPrefixRule_1 = require("./directiveSelectorPrefixRule"); | ||
exports.DirectiveSelectorPrefixRule = directiveSelectorPrefixRule_1.Rule; | ||
var directiveSelectorTypeRule_1 = require("./directiveSelectorTypeRule"); | ||
exports.DirectiveSelectorTypeRule = directiveSelectorTypeRule_1.Rule; | ||
var directiveSelectorRule_1 = require("./directiveSelectorRule"); | ||
exports.DirectiveSelectorRule = directiveSelectorRule_1.Rule; | ||
var importDestructuringSpacingRule_1 = require("./importDestructuringSpacingRule"); | ||
@@ -50,1 +45,2 @@ exports.ImportDestructuringSpacingRule = importDestructuringSpacingRule_1.Rule; | ||
exports.UsePipeTransformInterfaceRule = usePipeTransformInterfaceRule_1.Rule; | ||
__export(require("./angular/config")); |
@@ -1,2 +0,2 @@ | ||
import * as Lint from 'tslint/lib/lint'; | ||
import * as Lint from 'tslint'; | ||
import * as ts from 'typescript'; | ||
@@ -3,0 +3,0 @@ import { Ng2Walker } from './angular/ng2Walker'; |
@@ -7,3 +7,3 @@ "use strict"; | ||
}; | ||
var Lint = require("tslint/lib/lint"); | ||
var Lint = require("tslint"); | ||
var ng2Walker_1 = require("./angular/ng2Walker"); | ||
@@ -10,0 +10,0 @@ var Rule = (function (_super) { |
@@ -1,2 +0,2 @@ | ||
import * as Lint from 'tslint/lib/lint'; | ||
import * as Lint from 'tslint'; | ||
import * as ts from 'typescript'; | ||
@@ -3,0 +3,0 @@ export declare class Rule extends Lint.Rules.AbstractRule { |
@@ -7,3 +7,3 @@ "use strict"; | ||
}; | ||
var Lint = require("tslint/lib/lint"); | ||
var Lint = require("tslint"); | ||
var sprintf_js_1 = require("sprintf-js"); | ||
@@ -43,4 +43,4 @@ var utils_1 = require("./util/utils"); | ||
} | ||
available = classDeclarationUtils_1.getDeclaredMethodNames(this.context) | ||
.concat(classDeclarationUtils_1.getDeclaredPropertyNames(this.context)) | ||
available = classDeclarationUtils_1.getDeclaredMethodNames(this.context.controller) | ||
.concat(classDeclarationUtils_1.getDeclaredPropertyNames(this.context.controller)) | ||
.concat(this.preDefinedVariables); | ||
@@ -73,3 +73,3 @@ ast.receiver.visit(this); | ||
var width = ast.name.length; | ||
this.addFailure(this.createFailure(this.basePosition + ast.span.start, width, failureString)); | ||
this.addFailure(this.createFailure(ast.span.start, width, failureString)); | ||
} | ||
@@ -76,0 +76,0 @@ return null; |
@@ -1,2 +0,2 @@ | ||
import * as Lint from 'tslint/lib/lint'; | ||
import * as Lint from 'tslint'; | ||
import * as ts from 'typescript'; | ||
@@ -3,0 +3,0 @@ export declare class Rule extends Lint.Rules.AbstractRule { |
@@ -7,3 +7,3 @@ "use strict"; | ||
}; | ||
var Lint = require("tslint/lib/lint"); | ||
var Lint = require("tslint"); | ||
var sprintf_js_1 = require("sprintf-js"); | ||
@@ -10,0 +10,0 @@ var SyntaxKind = require("./util/syntaxKind"); |
@@ -1,2 +0,2 @@ | ||
import * as Lint from 'tslint/lib/lint'; | ||
import * as Lint from 'tslint'; | ||
import * as ts from 'typescript'; | ||
@@ -3,0 +3,0 @@ export declare class Rule extends Lint.Rules.AbstractRule { |
@@ -7,3 +7,3 @@ "use strict"; | ||
}; | ||
var Lint = require("tslint/lib/lint"); | ||
var Lint = require("tslint"); | ||
var sprintf_js_1 = require("sprintf-js"); | ||
@@ -10,0 +10,0 @@ var SyntaxKind = require("./util/syntaxKind"); |
@@ -1,2 +0,2 @@ | ||
import * as Lint from 'tslint/lib/lint'; | ||
import * as Lint from 'tslint'; | ||
import * as ts from 'typescript'; | ||
@@ -3,0 +3,0 @@ import { Ng2Walker } from './angular/ng2Walker'; |
@@ -7,3 +7,3 @@ "use strict"; | ||
}; | ||
var Lint = require("tslint/lib/lint"); | ||
var Lint = require("tslint"); | ||
var sprintf_js_1 = require("sprintf-js"); | ||
@@ -10,0 +10,0 @@ var ng2Walker_1 = require("./angular/ng2Walker"); |
@@ -1,2 +0,2 @@ | ||
import * as Lint from 'tslint/lib/lint'; | ||
import * as Lint from 'tslint'; | ||
import * as ts from 'typescript'; | ||
@@ -3,0 +3,0 @@ import { Ng2Walker } from './angular/ng2Walker'; |
@@ -7,3 +7,3 @@ "use strict"; | ||
}; | ||
var Lint = require("tslint/lib/lint"); | ||
var Lint = require("tslint"); | ||
var sprintf_js_1 = require("sprintf-js"); | ||
@@ -10,0 +10,0 @@ var ng2Walker_1 = require("./angular/ng2Walker"); |
@@ -1,5 +0,6 @@ | ||
import * as Lint from 'tslint/lib/lint'; | ||
import * as Lint from 'tslint'; | ||
import * as ts from 'typescript'; | ||
import { Ng2Walker } from './angular/ng2Walker'; | ||
import { CssAst } from './angular/styles/cssAst'; | ||
import { ComponentMetadata, StyleMetadata } from './angular/metadata'; | ||
export declare class Rule extends Lint.Rules.AbstractRule { | ||
@@ -12,3 +13,3 @@ static FAILURE: string; | ||
visitClassDeclaration(declaration: ts.ClassDeclaration): void; | ||
protected visitNg2StyleHelper(style: CssAst, context: ts.ClassDeclaration, baseStart: number): void; | ||
protected visitNg2StyleHelper(style: CssAst, context: ComponentMetadata, styleMetadata: StyleMetadata, baseStart: number): void; | ||
} |
@@ -7,3 +7,3 @@ "use strict"; | ||
}; | ||
var Lint = require("tslint/lib/lint"); | ||
var Lint = require("tslint"); | ||
var ng2Walker_1 = require("./angular/ng2Walker"); | ||
@@ -15,2 +15,3 @@ var utils_1 = require("./util/utils"); | ||
var templateParser_1 = require("./angular/templates/templateParser"); | ||
var logger_1 = require("./util/logger"); | ||
var CssSelectorTokenizer = require('css-selector-tokenizer'); | ||
@@ -152,7 +153,7 @@ var getSymbolName = function (t) { | ||
if (!match) { | ||
this.addFailure(this.createFailure(this.templateStart + ast.start.offset, ast.end.offset - ast.start.offset, 'Unused styles')); | ||
this.addFailure(this.createFailure(ast.start.offset, ast.end.offset - ast.start.offset, 'Unused styles')); | ||
} | ||
} | ||
catch (e) { | ||
console.error(e); | ||
logger_1.logger.error(e); | ||
} | ||
@@ -210,13 +211,11 @@ return true; | ||
if (d) { | ||
this.visitNg2Component(d.parent, d); | ||
var inlineTemplate = utils_1.getDecoratorPropertyInitializer(d, 'template'); | ||
if (inlineTemplate) { | ||
var meta = this._metadataReader.read(declaration); | ||
this.visitNg2Component(meta); | ||
if (meta.template && meta.template.template) { | ||
try { | ||
if (utils_1.isSimpleTemplateString(inlineTemplate)) { | ||
this.templateAst = | ||
new compiler_1.ElementAst('*', [], [], [], [], [], [], false, templateParser_1.parseTemplate(inlineTemplate.text), 0, null, null); | ||
} | ||
this.templateAst = | ||
new compiler_1.ElementAst('*', [], [], [], [], [], [], false, templateParser_1.parseTemplate(meta.template.template.code), 0, null, null); | ||
} | ||
catch (e) { | ||
console.error('Cannot parse the template', e); | ||
logger_1.logger.error('Cannot parse the template', e); | ||
} | ||
@@ -227,3 +226,3 @@ } | ||
}; | ||
UnusedCssNg2Visitor.prototype.visitNg2StyleHelper = function (style, context, baseStart) { | ||
UnusedCssNg2Visitor.prototype.visitNg2StyleHelper = function (style, context, styleMetadata, baseStart) { | ||
var _this = this; | ||
@@ -234,5 +233,6 @@ if (!style) { | ||
else { | ||
var visitor = new UnusedCssVisitor(this.getSourceFile(), this._originalOptions, context, baseStart); | ||
var file = this.getContextSourceFile(styleMetadata.url, styleMetadata.style.source); | ||
var visitor = new UnusedCssVisitor(file, this._originalOptions, context, styleMetadata, baseStart); | ||
visitor.templateAst = this.templateAst; | ||
var d = utils_1.getComponentDecorator(context); | ||
var d = utils_1.getComponentDecorator(context.controller); | ||
var encapsulation = utils_1.getDecoratorPropertyInitializer(d, 'encapsulation'); | ||
@@ -239,0 +239,0 @@ if (isEncapsulationEnabled(encapsulation)) { |
{ | ||
"name": "codelyzer", | ||
"version": "1.0.0-beta.4", | ||
"version": "2.0.0-beta.0", | ||
"description": "Linting for Angular 2 applications, following angular.io/styleguide.", | ||
@@ -33,3 +33,3 @@ "contributors": [ | ||
"peerDependencies": { | ||
"tslint": "^3.9.0", | ||
"tslint": "~4.0.0", | ||
"@angular/compiler": "~2.2.0", | ||
@@ -39,6 +39,8 @@ "@angular/core": "~2.2.0" | ||
"dependencies": { | ||
"app-root-path": "^2.0.1", | ||
"css-selector-tokenizer": "^0.7.0", | ||
"cssauron": "^1.4.0", | ||
"source-map": "^0.5.6", | ||
"sprintf-js": "^1.0.3" | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
import * as Lint from 'tslint/lib/lint'; | ||
import * as Lint from 'tslint'; | ||
import * as ts from 'typescript'; | ||
@@ -3,0 +3,0 @@ import { Ng2Walker } from './angular/ng2Walker'; |
@@ -7,3 +7,3 @@ "use strict"; | ||
}; | ||
var Lint = require("tslint/lib/lint"); | ||
var Lint = require("tslint"); | ||
var sprintf_js_1 = require("sprintf-js"); | ||
@@ -10,0 +10,0 @@ var ng2Walker_1 = require("./angular/ng2Walker"); |
@@ -1,2 +0,2 @@ | ||
import * as Lint from 'tslint/lib/lint'; | ||
import * as Lint from 'tslint'; | ||
import * as ts from 'typescript'; | ||
@@ -3,0 +3,0 @@ import { Ng2Walker } from './angular/ng2Walker'; |
@@ -7,3 +7,3 @@ "use strict"; | ||
}; | ||
var Lint = require("tslint/lib/lint"); | ||
var Lint = require("tslint"); | ||
var sprintf_js_1 = require("sprintf-js"); | ||
@@ -24,3 +24,3 @@ var SyntaxKind = require("./util/syntaxKind"); | ||
_this.prefix = (value.slice(2) || []).join(','); | ||
_this.prefixChecker = selectorValidator_1.SelectorValidator.multiPrefix(prefixExpression); | ||
_this.prefixChecker = selectorValidator_1.SelectorValidator.prefix(prefixExpression, 'camelCase'); | ||
} | ||
@@ -27,0 +27,0 @@ return _this; |
@@ -1,2 +0,2 @@ | ||
import * as Lint from 'tslint/lib/lint'; | ||
import * as Lint from 'tslint'; | ||
import * as ts from 'typescript'; | ||
@@ -3,0 +3,0 @@ export interface IUsePropertyDecoratorConfig { |
@@ -7,3 +7,3 @@ "use strict"; | ||
}; | ||
var Lint = require("tslint/lib/lint"); | ||
var Lint = require("tslint"); | ||
var ts = require("typescript"); | ||
@@ -10,0 +10,0 @@ var sprintf_js_1 = require("sprintf-js"); |
@@ -60,8 +60,4 @@ [![Build Status](https://travis-ci.org/mgechev/codelyzer.svg?branch=master)](https://travis-ci.org/mgechev/codelyzer) | ||
"rules":{ | ||
"directive-selector-name": [true, "camelCase"], | ||
"component-selector-name": [true, "kebab-case"], | ||
"directive-selector-type": [true, "attribute"], | ||
"component-selector-type": [true, "element"], | ||
"directive-selector-prefix": [true, "sg"], | ||
"component-selector-prefix": [true, "sg"], | ||
"directive-selector": [true, "attribute", "sg", "camelCase"], | ||
"component-selector": [true, "element", "sg", "kebab-case"], | ||
"use-input-property-decorator": true, | ||
@@ -141,2 +137,6 @@ "use-output-property-decorator": true, | ||
## Changelog | ||
You can find it [here](https://github.com/mgechev/codelyzer/blob/master/CHANGELOG.md). | ||
## Recommended configuration | ||
@@ -148,8 +148,4 @@ | ||
{ | ||
"directive-selector-name": [true, "camelCase"], | ||
"component-selector-name": [true, "kebab-case"], | ||
"directive-selector-type": [true, "attribute"], | ||
"component-selector-type": [true, "element"], | ||
"directive-selector-prefix": [true, "sg"], | ||
"component-selector-prefix": [true, "sg"], | ||
"directive-selector": [true, "attribute", "sg", "camelCase"], | ||
"component-selector": [true, "element", "sg", "kebab-case"], | ||
"use-input-property-decorator": true, | ||
@@ -156,0 +152,0 @@ "use-output-property-decorator": true, |
@@ -0,17 +1,40 @@ | ||
import * as Lint from 'tslint'; | ||
import * as ts from 'typescript'; | ||
import * as Lint from 'tslint/lib/lint'; | ||
export declare enum COMPONENT_TYPE { | ||
COMPONENT = 0, | ||
DIRECTIVE = 1, | ||
ANY = 2, | ||
} | ||
export declare abstract class SelectorRule extends Lint.Rules.AbstractRule { | ||
private validator; | ||
private failureString; | ||
private target; | ||
constructor(ruleName: string, value: any, disabledIntervals: Lint.IDisabledInterval[], validator: Function, failureString: string, target?: COMPONENT_TYPE); | ||
isMultiPrefix: boolean; | ||
prefixArguments: string; | ||
cssSelectorProperty: string; | ||
handleType: string; | ||
private typeValidator; | ||
private prefixValidator; | ||
private nameValidator; | ||
private FAILURE_PREFIX; | ||
private isMultiSelectors; | ||
constructor(ruleName: string, value: any, disabledIntervals: Lint.IDisabledInterval[]); | ||
getPrefixFailure(): string; | ||
validateType(selector: string): boolean; | ||
validateName(selector: any): boolean; | ||
validatePrefix(selector: any): boolean; | ||
apply(sourceFile: ts.SourceFile): Lint.RuleFailure[]; | ||
getFailureString(failureConfig: any): string; | ||
validate(selector: string): boolean; | ||
readonly targetType: COMPONENT_TYPE; | ||
abstract getTypeFailure(): any; | ||
abstract getNameFailure(): any; | ||
protected abstract getSinglePrefixFailure(): any; | ||
protected abstract getManyPrefixFailure(): any; | ||
private setNameValidator(name); | ||
private setMultiPrefix(prefix); | ||
private setPrefixArguments(prefix); | ||
private setPrefixValidator(prefix, name); | ||
private setPrefixFailure(); | ||
private setTypeValidator(type); | ||
} | ||
export declare class SelectorValidatorWalker extends Lint.RuleWalker { | ||
private rule; | ||
constructor(sourceFile: ts.SourceFile, rule: SelectorRule); | ||
visitClassDeclaration(node: ts.ClassDeclaration): void; | ||
private validateDecorator(className, decorator); | ||
private validateSelector(className, arg); | ||
private validateProperty(p); | ||
private isSupportedKind(kind); | ||
private extractMainSelector(i); | ||
} |
@@ -7,55 +7,97 @@ "use strict"; | ||
}; | ||
var ts = require("typescript"); | ||
var Lint = require("tslint/lib/lint"); | ||
var Lint = require("tslint"); | ||
var selectorValidator_1 = require("./util/selectorValidator"); | ||
var sprintf_js_1 = require("sprintf-js"); | ||
var compiler = require("@angular/compiler"); | ||
var SyntaxKind = require("./util/syntaxKind"); | ||
(function (COMPONENT_TYPE) { | ||
COMPONENT_TYPE[COMPONENT_TYPE["COMPONENT"] = 0] = "COMPONENT"; | ||
COMPONENT_TYPE[COMPONENT_TYPE["DIRECTIVE"] = 1] = "DIRECTIVE"; | ||
COMPONENT_TYPE[COMPONENT_TYPE["ANY"] = 2] = "ANY"; | ||
})(exports.COMPONENT_TYPE || (exports.COMPONENT_TYPE = {})); | ||
var COMPONENT_TYPE = exports.COMPONENT_TYPE; | ||
; | ||
var SelectorRule = (function (_super) { | ||
__extends(SelectorRule, _super); | ||
function SelectorRule(ruleName, value, disabledIntervals, validator, failureString, target) { | ||
if (target === void 0) { target = COMPONENT_TYPE.ANY; } | ||
var _this = _super.call(this, ruleName, value, disabledIntervals) || this; | ||
_this.validator = validator; | ||
_this.failureString = failureString; | ||
_this.target = target; | ||
function SelectorRule(ruleName, value, disabledIntervals) { | ||
var _this; | ||
var type = value[1]; | ||
var prefix = value[2]; | ||
var name = value[3]; | ||
_this = _super.call(this, ruleName, value, disabledIntervals) || this; | ||
_this.setMultiPrefix(prefix); | ||
_this.setPrefixArguments(prefix); | ||
_this.setPrefixValidator(prefix, name); | ||
_this.setPrefixFailure(); | ||
_this.setTypeValidator(type); | ||
_this.setNameValidator(name); | ||
return _this; | ||
} | ||
SelectorRule.prototype.getPrefixFailure = function () { | ||
return this.FAILURE_PREFIX; | ||
}; | ||
SelectorRule.prototype.validateType = function (selector) { | ||
return this.typeValidator(selector); | ||
}; | ||
SelectorRule.prototype.validateName = function (selector) { | ||
var _this = this; | ||
if (this.isMultiSelectors) { | ||
return selector.some(function (a) { return _this.nameValidator(a); }); | ||
} | ||
else { | ||
return this.nameValidator(selector); | ||
} | ||
}; | ||
SelectorRule.prototype.validatePrefix = function (selector) { | ||
var _this = this; | ||
if (this.isMultiSelectors) { | ||
return selector.some(function (a) { return _this.prefixValidator(a); }); | ||
} | ||
else { | ||
return this.prefixValidator(selector); | ||
} | ||
}; | ||
SelectorRule.prototype.apply = function (sourceFile) { | ||
var documentRegistry = ts.createDocumentRegistry(); | ||
var languageServiceHost = Lint.createLanguageServiceHost('file.ts', sourceFile.getFullText()); | ||
var languageService = ts.createLanguageService(languageServiceHost, documentRegistry); | ||
return this.applyWithWalker(new SelectorNameValidatorWalker(sourceFile, languageService, this)); | ||
return this.applyWithWalker(new SelectorValidatorWalker(sourceFile, this)); | ||
}; | ||
SelectorRule.prototype.getFailureString = function (failureConfig) { | ||
return sprintf_js_1.sprintf(this.failureString, failureConfig.className, this.getOptions().ruleArguments, failureConfig.selector); | ||
return sprintf_js_1.sprintf(failureConfig.fail, failureConfig.className, this.getOptions().ruleArguments, failureConfig.selector); | ||
}; | ||
SelectorRule.prototype.validate = function (selector) { | ||
return this.validator(selector); | ||
SelectorRule.prototype.setNameValidator = function (name) { | ||
if (name === 'camelCase') { | ||
this.nameValidator = selectorValidator_1.SelectorValidator.camelCase; | ||
} | ||
else if (name === 'kebab-case') { | ||
this.nameValidator = selectorValidator_1.SelectorValidator.kebabCase; | ||
} | ||
}; | ||
Object.defineProperty(SelectorRule.prototype, "targetType", { | ||
get: function () { | ||
return this.target; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
SelectorRule.prototype.setMultiPrefix = function (prefix) { | ||
this.isMultiPrefix = typeof prefix === 'string'; | ||
}; | ||
SelectorRule.prototype.setPrefixArguments = function (prefix) { | ||
this.prefixArguments = this.isMultiPrefix ? prefix : prefix.join(','); | ||
}; | ||
SelectorRule.prototype.setPrefixValidator = function (prefix, name) { | ||
var prefixExpression = this.isMultiPrefix ? prefix : (prefix || []).join('|'); | ||
this.prefixValidator = selectorValidator_1.SelectorValidator.prefix(prefixExpression, name); | ||
}; | ||
SelectorRule.prototype.setPrefixFailure = function () { | ||
this.FAILURE_PREFIX = this.isMultiPrefix ? this.getSinglePrefixFailure() : this.getManyPrefixFailure(); | ||
}; | ||
SelectorRule.prototype.setTypeValidator = function (type) { | ||
if (type === 'element') { | ||
this.typeValidator = selectorValidator_1.SelectorValidator.element; | ||
this.isMultiSelectors = false; | ||
this.cssSelectorProperty = 'element'; | ||
} | ||
else if (type === 'attribute') { | ||
this.typeValidator = selectorValidator_1.SelectorValidator.attribute; | ||
this.isMultiSelectors = true; | ||
this.cssSelectorProperty = 'attrs'; | ||
} | ||
}; | ||
return SelectorRule; | ||
}(Lint.Rules.AbstractRule)); | ||
exports.SelectorRule = SelectorRule; | ||
var SelectorNameValidatorWalker = (function (_super) { | ||
__extends(SelectorNameValidatorWalker, _super); | ||
function SelectorNameValidatorWalker(sourceFile, languageService, rule) { | ||
var SelectorValidatorWalker = (function (_super) { | ||
__extends(SelectorValidatorWalker, _super); | ||
function SelectorValidatorWalker(sourceFile, rule) { | ||
var _this = _super.call(this, sourceFile, rule.getOptions()) || this; | ||
_this.rule = rule; | ||
_this.languageService = languageService; | ||
_this.typeChecker = languageService.getProgram().getTypeChecker(); | ||
return _this; | ||
} | ||
SelectorNameValidatorWalker.prototype.visitClassDeclaration = function (node) { | ||
SelectorValidatorWalker.prototype.visitClassDeclaration = function (node) { | ||
(node.decorators || []) | ||
@@ -65,3 +107,3 @@ .forEach(this.validateDecorator.bind(this, node.name.text)); | ||
}; | ||
SelectorNameValidatorWalker.prototype.validateDecorator = function (className, decorator) { | ||
SelectorValidatorWalker.prototype.validateDecorator = function (className, decorator) { | ||
var baseExpr = decorator.expression || {}; | ||
@@ -72,26 +114,45 @@ var expr = baseExpr.expression || {}; | ||
var arg = args[0]; | ||
if (this.rule.targetType === COMPONENT_TYPE.ANY || | ||
name === 'Component' && this.rule.targetType === COMPONENT_TYPE.COMPONENT || | ||
name === 'Directive' && this.rule.targetType === COMPONENT_TYPE.DIRECTIVE) { | ||
if (this.rule.handleType === name) { | ||
this.validateSelector(className, arg); | ||
} | ||
}; | ||
SelectorNameValidatorWalker.prototype.validateSelector = function (className, arg) { | ||
SelectorValidatorWalker.prototype.validateSelector = function (className, arg) { | ||
var _this = this; | ||
if (arg.kind === SyntaxKind.current().ObjectLiteralExpression) { | ||
arg.properties.filter(function (prop) { return prop.name.text === 'selector'; }) | ||
.forEach(function (prop) { | ||
var p = prop; | ||
if (p.initializer && isSupportedKind(p.initializer.kind) && !_this.rule.validate(p.initializer.text)) { | ||
var error = _this.rule.getFailureString({ selector: p.initializer.text, className: className }); | ||
_this.addFailure(_this.createFailure(p.initializer.getStart(), p.initializer.getWidth(), error)); | ||
arg.properties.filter(function (prop) { return _this.validateProperty(prop); }) | ||
.map(function (prop) { return prop.initializer; }) | ||
.forEach(function (i) { | ||
var selectors = _this.extractMainSelector(i); | ||
var validateSelectors = function (cb) { | ||
return !selectors.every(function (selector) { | ||
return !cb(selector[_this.rule.cssSelectorProperty]); | ||
}); | ||
}; | ||
if (!validateSelectors(_this.rule.validateType.bind(_this.rule))) { | ||
var error = sprintf_js_1.sprintf(_this.rule.getTypeFailure(), className, _this.rule.getOptions().ruleArguments[0]); | ||
_this.addFailure(_this.createFailure(i.getStart(), i.getWidth(), error)); | ||
} | ||
else if (!validateSelectors(_this.rule.validateName.bind(_this.rule))) { | ||
var error = sprintf_js_1.sprintf(_this.rule.getNameFailure(), className, _this.rule.getOptions().ruleArguments[2]); | ||
_this.addFailure(_this.createFailure(i.getStart(), i.getWidth(), error)); | ||
} | ||
else if (!validateSelectors(_this.rule.validatePrefix.bind(_this.rule))) { | ||
var error = sprintf_js_1.sprintf(_this.rule.getPrefixFailure(), className, _this.rule.prefixArguments); | ||
_this.addFailure(_this.createFailure(i.getStart(), i.getWidth(), error)); | ||
} | ||
}); | ||
} | ||
function isSupportedKind(kind) { | ||
var current = SyntaxKind.current(); | ||
return [current.StringLiteral, current.NoSubstitutionTemplateLiteral].some(function (kindType) { return kindType === kind; }); | ||
} | ||
}; | ||
return SelectorNameValidatorWalker; | ||
SelectorValidatorWalker.prototype.validateProperty = function (p) { | ||
return p.name.text === 'selector' && p.initializer && this.isSupportedKind(p.initializer.kind); | ||
}; | ||
SelectorValidatorWalker.prototype.isSupportedKind = function (kind) { | ||
var current = SyntaxKind.current(); | ||
return [current.StringLiteral, current.NoSubstitutionTemplateLiteral].some(function (kindType) { return kindType === kind; }); | ||
}; | ||
SelectorValidatorWalker.prototype.extractMainSelector = function (i) { | ||
return compiler.CssSelector.parse(i.text); | ||
}; | ||
return SelectorValidatorWalker; | ||
}(Lint.RuleWalker)); | ||
exports.SelectorValidatorWalker = SelectorValidatorWalker; |
@@ -1,2 +0,2 @@ | ||
import * as Lint from 'tslint/lib/lint'; | ||
import * as Lint from 'tslint'; | ||
import * as ts from 'typescript'; | ||
@@ -3,0 +3,0 @@ export declare class Rule extends Lint.Rules.AbstractRule { |
@@ -7,4 +7,5 @@ "use strict"; | ||
}; | ||
var Lint = require("tslint/lib/lint"); | ||
var Lint = require("tslint"); | ||
var utils_1 = require("./util/utils"); | ||
var classDeclarationUtils_1 = require("./util/classDeclarationUtils"); | ||
var ng2Walker_1 = require("./angular/ng2Walker"); | ||
@@ -41,3 +42,4 @@ var recursiveAngularExpressionVisitor_1 = require("./angular/templates/recursiveAngularExpressionVisitor"); | ||
} | ||
var member = this.context.members.filter(function (m) { return m.name && m.name.text === ast.name; }).pop(); | ||
var allMembers = classDeclarationUtils_1.getDeclaredMethods(this.context.controller).concat(classDeclarationUtils_1.getDeclaredProperties(this.context.controller)); | ||
var member = allMembers.filter(function (m) { return m.name && m.name.text === ast.name; }).pop(); | ||
if (member) { | ||
@@ -51,3 +53,3 @@ var isPublic = !member.modifiers; | ||
var failureString = 'You can bind only to public class members.'; | ||
this.addFailure(this.createFailure(this.basePosition + ast.span.start, width, failureString)); | ||
this.addFailure(this.createFailure(ast.span.start, width, failureString)); | ||
} | ||
@@ -54,0 +56,0 @@ } |
@@ -1,2 +0,2 @@ | ||
import * as Lint from 'tslint/lib/lint'; | ||
import * as Lint from 'tslint'; | ||
import { UsePropertyDecorator } from './propertyDecoratorBase'; | ||
@@ -3,0 +3,0 @@ export declare class Rule extends UsePropertyDecorator { |
@@ -1,2 +0,2 @@ | ||
import * as Lint from 'tslint/lib/lint'; | ||
import * as Lint from 'tslint'; | ||
import { UsePropertyDecorator } from './propertyDecoratorBase'; | ||
@@ -3,0 +3,0 @@ export declare class Rule extends UsePropertyDecorator { |
@@ -1,2 +0,2 @@ | ||
import * as Lint from 'tslint/lib/lint'; | ||
import * as Lint from 'tslint'; | ||
import * as ts from 'typescript'; | ||
@@ -3,0 +3,0 @@ export declare class Rule extends Lint.Rules.AbstractRule { |
@@ -7,3 +7,3 @@ "use strict"; | ||
}; | ||
var Lint = require("tslint/lib/lint"); | ||
var Lint = require("tslint"); | ||
var sprintf_js_1 = require("sprintf-js"); | ||
@@ -10,0 +10,0 @@ var SyntaxKind = require("./util/syntaxKind"); |
@@ -1,2 +0,2 @@ | ||
import * as Lint from 'tslint/lib/lint'; | ||
import * as Lint from 'tslint'; | ||
import { UsePropertyDecorator } from './propertyDecoratorBase'; | ||
@@ -3,0 +3,0 @@ export declare class Rule extends UsePropertyDecorator { |
@@ -1,2 +0,2 @@ | ||
import * as Lint from 'tslint/lib/lint'; | ||
import * as Lint from 'tslint'; | ||
import * as ts from 'typescript'; | ||
@@ -3,0 +3,0 @@ export declare class Rule extends Lint.Rules.AbstractRule { |
@@ -7,3 +7,3 @@ "use strict"; | ||
}; | ||
var Lint = require("tslint/lib/lint"); | ||
var Lint = require("tslint"); | ||
var sprintf_js_1 = require("sprintf-js"); | ||
@@ -10,0 +10,0 @@ var SyntaxKind = require("./util/syntaxKind"); |
import * as ts from 'typescript'; | ||
export declare const getDeclaredPropertyNames: (declaration: ts.ClassDeclaration) => string[]; | ||
export declare const getDeclaredProperties: (declaration: ts.ClassDeclaration) => ts.ClassElement[]; | ||
export declare const getDeclaredPropertyNames: (declaration: ts.ClassDeclaration) => any[]; | ||
export declare const getDeclaredMethods: (declaration: ts.ClassDeclaration) => ts.ClassElement[]; | ||
export declare const getDeclaredMethodNames: (declaration: ts.ClassDeclaration) => string[]; |
"use strict"; | ||
var syntaxKind_1 = require("./syntaxKind"); | ||
var SyntaxKind = syntaxKind_1.current(); | ||
exports.getDeclaredProperties = function (declaration) { | ||
var m = declaration.members; | ||
var ctr = m.filter(function (m) { return m.kind === SyntaxKind.Constructor; }).pop(); | ||
var params = []; | ||
if (ctr) { | ||
params = (ctr.parameters || []) | ||
.filter(function (p) { return p.kind === SyntaxKind.Parameter; }); | ||
} | ||
return m.filter(function (m) { return m.kind === SyntaxKind.PropertyDeclaration || | ||
m.kind === SyntaxKind.GetAccessor || m.kind === SyntaxKind.SetAccessor; }).concat(params); | ||
}; | ||
exports.getDeclaredPropertyNames = function (declaration) { | ||
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; }); | ||
return exports.getDeclaredProperties(declaration).filter(function (p) { return p && p.name; }).map(function (p) { return p.name.text; }); | ||
}; | ||
exports.getDeclaredMethods = function (declaration) { | ||
return declaration.members.filter(function (m) { return m.kind === SyntaxKind.MethodDeclaration; }); | ||
}; | ||
exports.getDeclaredMethodNames = function (declaration) { | ||
return declaration.members.filter(function (m) { return m.kind === SyntaxKind.MethodDeclaration; }) | ||
return exports.getDeclaredMethods(declaration) | ||
.map(function (d) { return d.name.text; }); | ||
}; |
@@ -6,4 +6,3 @@ export declare const SelectorValidator: { | ||
camelCase(selector: string): boolean; | ||
prefix(prefix: string): Function; | ||
multiPrefix(prefixes: string): Function; | ||
prefix(prefix: string, selectorType: string): Function; | ||
}; |
"use strict"; | ||
exports.SelectorValidator = { | ||
attribute: function (selector) { | ||
return /^\[.+\]$/.test(selector); | ||
return selector.length !== 0; | ||
}, | ||
element: function (selector) { | ||
return /^[^\[].+[^\]]$/.test(selector); | ||
return selector !== null; | ||
}, | ||
@@ -15,12 +15,22 @@ kebabCase: function (selector) { | ||
}, | ||
prefix: function (prefix) { | ||
prefix: function (prefix, selectorType) { | ||
var regex = new RegExp("^\\[?(" + prefix + ")"); | ||
return function (selector) { | ||
return new RegExp("^\\[?" + prefix).test(selector); | ||
if (!regex.test(selector)) { | ||
return false; | ||
} | ||
else { | ||
var suffix = selector.replace(regex, ''); | ||
if (selectorType === 'camelCase') { | ||
return !suffix || suffix[0] === suffix[0].toUpperCase(); | ||
} | ||
else if (selectorType === 'kebab-case') { | ||
return !suffix || suffix[0] === '-'; | ||
} | ||
else { | ||
throw new Error('Invalid selector type'); | ||
} | ||
} | ||
}; | ||
}, | ||
multiPrefix: function (prefixes) { | ||
return function (selector) { | ||
return new RegExp("^\\[?(" + prefixes + ")").test(selector); | ||
}; | ||
} | ||
}; |
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
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
307694
102
7841
8
171
2
+ Addedapp-root-path@^2.0.1
+ Addedsource-map@^0.5.6
+ Addedansi-align@1.1.0(transitive)
+ Addedansi-regex@2.1.1(transitive)
+ Addedansi-styles@2.2.1(transitive)
+ Addedapp-root-path@2.2.1(transitive)
+ Addedboxen@0.6.0(transitive)
+ Addedcamelcase@2.1.1(transitive)
+ Addedcapture-stack-trace@1.0.2(transitive)
+ Addedchalk@1.1.3(transitive)
+ Addedcli-boxes@1.0.0(transitive)
+ Addedcode-point-at@1.1.0(transitive)
+ Addedconfigstore@2.1.0(transitive)
+ Addedcore-util-is@1.0.3(transitive)
+ Addedcreate-error-class@3.0.2(transitive)
+ Addeddeep-extend@0.6.0(transitive)
+ Addeddiff@3.5.0(transitive)
+ Addeddot-prop@3.0.0(transitive)
+ Addedduplexer2@0.1.4(transitive)
+ Addederror-ex@1.3.2(transitive)
+ Addedescape-string-regexp@1.0.5(transitive)
+ Addedfilled-array@1.1.0(transitive)
+ Addedgot@5.7.1(transitive)
+ Addedgraceful-fs@4.2.11(transitive)
+ Addedhas-ansi@2.0.0(transitive)
+ Addedimurmurhash@0.1.4(transitive)
+ Addedini@1.3.8(transitive)
+ Addedis-arrayish@0.2.1(transitive)
+ Addedis-finite@1.1.0(transitive)
+ Addedis-fullwidth-code-point@1.0.0(transitive)
+ Addedis-npm@1.0.0(transitive)
+ Addedis-obj@1.0.1(transitive)
+ Addedis-redirect@1.0.0(transitive)
+ Addedis-retry-allowed@1.2.0(transitive)
+ Addedis-stream@1.1.0(transitive)
+ Addedisarray@1.0.0(transitive)
+ Addedlatest-version@2.0.0(transitive)
+ Addedlazy-req@1.1.0(transitive)
+ Addedlowercase-keys@1.0.1(transitive)
+ Addedminimist@1.2.8(transitive)
+ Addedmkdirp@0.5.6(transitive)
+ Addednode-status-codes@1.0.0(transitive)
+ Addednumber-is-nan@1.0.1(transitive)
+ Addedobject-assign@4.1.1(transitive)
+ Addedos-homedir@1.0.2(transitive)
+ Addedos-tmpdir@1.0.2(transitive)
+ Addedosenv@0.1.5(transitive)
+ Addedpackage-json@2.4.0(transitive)
+ Addedparse-json@2.2.0(transitive)
+ Addedpinkie@2.0.4(transitive)
+ Addedpinkie-promise@2.0.1(transitive)
+ Addedprepend-http@1.0.4(transitive)
+ Addedprocess-nextick-args@2.0.1(transitive)
+ Addedrc@1.2.8(transitive)
+ Addedread-all-stream@3.1.0(transitive)
+ Addedreadable-stream@2.3.8(transitive)
+ Addedregistry-auth-token@3.4.0(transitive)
+ Addedregistry-url@3.1.0(transitive)
+ Addedrepeating@2.0.1(transitive)
+ Addedsafe-buffer@5.1.2(transitive)
+ Addedsemver@5.7.2(transitive)
+ Addedsemver-diff@2.1.0(transitive)
+ Addedslide@1.1.6(transitive)
+ Addedsource-map@0.5.7(transitive)
+ Addedstring-width@1.0.2(transitive)
+ Addedstring_decoder@1.1.1(transitive)
+ Addedstrip-ansi@3.0.1(transitive)
+ Addedstrip-json-comments@2.0.1(transitive)
+ Addedsupports-color@2.0.0(transitive)
+ Addedtimed-out@3.1.3(transitive)
+ Addedtslint@4.0.2(transitive)
+ Addedunzip-response@1.0.2(transitive)
+ Addedupdate-notifier@1.0.3(transitive)
+ Addedurl-parse-lax@1.0.0(transitive)
+ Addeduuid@2.0.3(transitive)
+ Addedwidest-line@1.0.0(transitive)
+ Addedwrite-file-atomic@1.3.4(transitive)
+ Addedxdg-basedir@2.0.0(transitive)
- Removeddiff@2.2.3(transitive)
- Removedtslint@3.15.1(transitive)