Skip to content

Commit

Permalink
refactor: drop rules (#448)
Browse files Browse the repository at this point in the history
* refactor: drop rules

* refactor: drop rules

Fix #264
  • Loading branch information
mgechev authored Oct 29, 2017
1 parent 4d495a0 commit 12159e4
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 1,494 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Create the following `tslint.json` file like:
{
"extends": [ "codelyzer" ],
"rules":{
"angular-whitespace": [true, "check-interpolation", "check-pipe", "check-semicolon"],
"angular-whitespace": [true, "check-interpolation", "check-semicolon"],
"banana-in-box": true,
"templates-no-negated-async": true,
"directive-selector": [true, "attribute", "sg", "camelCase"],
Expand Down
2 changes: 0 additions & 2 deletions src/angular/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,8 @@ export const Config: Config = {
logLevel: BUILD_TYPE === 'dev' ? LogLevel.Debug : LogLevel.None
};


try {
const root = require('app-root-path');
const newConfig = require(root.path + '/.codelyzer');
Object.assign(Config, newConfig);
} catch (e) {}

134 changes: 71 additions & 63 deletions src/angular/ngWalker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { getDecoratorName } from '../util/utils';
const getDecoratorStringArgs = (decorator: ts.Decorator) => {
let baseExpr = <any>decorator.expression || {};
let args = baseExpr.arguments || [];
return args.map(a => (a.kind === ts.SyntaxKind.StringLiteral) ? a.text : null);
return args.map(a => (a.kind === ts.SyntaxKind.StringLiteral ? a.text : null));
};

export interface NgWalkerConfig {
Expand All @@ -37,21 +37,23 @@ export interface NgWalkerConfig {
}

export class NgWalker extends Lint.RuleWalker {

constructor(sourceFile: ts.SourceFile,
protected _originalOptions: Lint.IOptions,
private _config?: NgWalkerConfig,
protected _metadataReader?: MetadataReader) {

constructor(
sourceFile: ts.SourceFile,
protected _originalOptions: Lint.IOptions,
private _config?: NgWalkerConfig,
protected _metadataReader?: MetadataReader
) {
super(sourceFile, _originalOptions);

this._metadataReader = this._metadataReader || ngWalkerFactoryUtils.defaultMetadataReader();
this._config = Object.assign({
templateVisitorCtrl: BasicTemplateAstVisitor,
expressionVisitorCtrl: RecursiveAngularExpressionVisitor,
cssVisitorCtrl: BasicCssAstVisitor
}, this._config || {});

this._config = Object.assign(
{
templateVisitorCtrl: BasicTemplateAstVisitor,
expressionVisitorCtrl: RecursiveAngularExpressionVisitor,
cssVisitorCtrl: BasicCssAstVisitor
},
this._config || {}
);
}

visitClassDeclaration(declaration: ts.ClassDeclaration) {
Expand All @@ -78,41 +80,45 @@ export class NgWalker extends Lint.RuleWalker {
protected visitMethodDecorator(decorator: ts.Decorator) {
let name = getDecoratorName(decorator);
if (name === 'HostListener') {
this.visitNgHostListener(<ts.MethodDeclaration>decorator.parent,
decorator, getDecoratorStringArgs(decorator));
this.visitNgHostListener(<ts.MethodDeclaration>decorator.parent, decorator, getDecoratorStringArgs(decorator));
}
}

protected visitPropertyDecorator(decorator: ts.Decorator) {
let name = getDecoratorName(decorator);
switch (name) {
case 'Input':
this.visitNgInput(<ts.PropertyDeclaration>decorator.parent,
decorator, getDecoratorStringArgs(decorator));
this.visitNgInput(<ts.PropertyDeclaration>decorator.parent, decorator, getDecoratorStringArgs(decorator));
break;
case 'Output':
this.visitNgOutput(<ts.PropertyDeclaration>decorator.parent,
decorator, getDecoratorStringArgs(decorator));
this.visitNgOutput(<ts.PropertyDeclaration>decorator.parent, decorator, getDecoratorStringArgs(decorator));
break;
case 'HostBinding':
this.visitNgHostBinding(<ts.PropertyDeclaration>decorator.parent,
decorator, getDecoratorStringArgs(decorator));
this.visitNgHostBinding(<ts.PropertyDeclaration>decorator.parent, decorator, getDecoratorStringArgs(decorator));
break;
case 'ContentChild':
this.visitNgContentChild(<ts.PropertyDeclaration>decorator.parent,
decorator, getDecoratorStringArgs(decorator));
this.visitNgContentChild(
<ts.PropertyDeclaration>decorator.parent,
decorator,
getDecoratorStringArgs(decorator)
);
break;
case 'ContentChildren':
this.visitNgContentChildren(<ts.PropertyDeclaration>decorator.parent,
decorator, getDecoratorStringArgs(decorator));
this.visitNgContentChildren(
<ts.PropertyDeclaration>decorator.parent,
decorator,
getDecoratorStringArgs(decorator)
);
break;
case 'ViewChild':
this.visitNgViewChild(<ts.PropertyDeclaration>decorator.parent,
decorator, getDecoratorStringArgs(decorator));
this.visitNgViewChild(<ts.PropertyDeclaration>decorator.parent, decorator, getDecoratorStringArgs(decorator));
break;
case 'ViewChildren':
this.visitNgViewChildren(<ts.PropertyDeclaration>decorator.parent,
decorator, getDecoratorStringArgs(decorator));
this.visitNgViewChildren(
<ts.PropertyDeclaration>decorator.parent,
decorator,
getDecoratorStringArgs(decorator)
);
break;
}
}
Expand All @@ -124,18 +130,18 @@ export class NgWalker extends Lint.RuleWalker {
this.visitNgInjectable(<ts.ClassDeclaration>decorator.parent, decorator);
}


if (name === 'Pipe') {
this.visitNgPipe(<ts.ClassDeclaration>decorator.parent, decorator);
}

// Not invoked @Component or @Pipe, or @Directive
if (!(<ts.CallExpression>decorator.expression).arguments ||
if (
!(<ts.CallExpression>decorator.expression).arguments ||
!(<ts.CallExpression>decorator.expression).arguments.length ||
!(<ts.ObjectLiteralExpression>(<ts.CallExpression>decorator.expression).arguments[0]).properties) {
!(<ts.ObjectLiteralExpression>(<ts.CallExpression>decorator.expression).arguments[0]).properties
) {
return;
}

}

protected visitNgComponent(metadata: ComponentMetadata) {
Expand All @@ -146,8 +152,7 @@ export class NgWalker extends Lint.RuleWalker {
pos = node.pos + 1;
try {
pos = node.getStart() + 1;
} catch (e) {
}
} catch (e) {}
}
return pos;
};
Expand All @@ -172,61 +177,65 @@ export class NgWalker extends Lint.RuleWalker {
}
}

protected visitNgDirective(metadata: DirectiveMetadata) {
}
protected visitNgDirective(metadata: DirectiveMetadata) {}

protected visitNgPipe(controller: ts.ClassDeclaration, decorator: ts.Decorator) {
}
protected visitNgPipe(controller: ts.ClassDeclaration, decorator: ts.Decorator) {}

protected visitNgInjectable(classDeclaration: ts.ClassDeclaration, decorator: ts.Decorator) {
}
protected visitNgInjectable(classDeclaration: ts.ClassDeclaration, decorator: ts.Decorator) {}

protected visitNgInput(property: ts.PropertyDeclaration, input: ts.Decorator, args: string[]) {
}
protected visitNgInput(property: ts.PropertyDeclaration, input: ts.Decorator, args: string[]) {}

protected visitNgOutput(property: ts.PropertyDeclaration, output: ts.Decorator, args: string[]) {
}
protected visitNgOutput(property: ts.PropertyDeclaration, output: ts.Decorator, args: string[]) {}

protected visitNgHostBinding(property: ts.PropertyDeclaration, decorator: ts.Decorator, args: string[]) {
}
protected visitNgHostBinding(property: ts.PropertyDeclaration, decorator: ts.Decorator, args: string[]) {}

protected visitNgHostListener(method: ts.MethodDeclaration, decorator: ts.Decorator, args: string[]) {
}
protected visitNgHostListener(method: ts.MethodDeclaration, decorator: ts.Decorator, args: string[]) {}

protected visitNgContentChild(property: ts.PropertyDeclaration, input: ts.Decorator, args: string[]) {
}
protected visitNgContentChild(property: ts.PropertyDeclaration, input: ts.Decorator, args: string[]) {}

protected visitNgContentChildren(property: ts.PropertyDeclaration, input: ts.Decorator, args: string[]) {
}
protected visitNgContentChildren(property: ts.PropertyDeclaration, input: ts.Decorator, args: string[]) {}

protected visitNgViewChild(property: ts.PropertyDeclaration, input: ts.Decorator, args: string[]) {
}
protected visitNgViewChild(property: ts.PropertyDeclaration, input: ts.Decorator, args: string[]) {}

protected visitNgViewChildren(property: ts.PropertyDeclaration, input: ts.Decorator, args: string[]) {
}
protected visitNgViewChildren(property: ts.PropertyDeclaration, input: ts.Decorator, args: string[]) {}

protected visitNgTemplateHelper(roots: compiler.TemplateAst[], context: ComponentMetadata, baseStart: number) {
if (!roots || !roots.length) {
return;
} else {
const sourceFile = this.getContextSourceFile(context.template.url, context.template.template.source);
const referenceVisitor = new ReferenceCollectorVisitor();
const visitor =
new this._config.templateVisitorCtrl(
sourceFile, this._originalOptions, context, baseStart, this._config.expressionVisitorCtrl);
const visitor = new this._config.templateVisitorCtrl(
sourceFile,
this._originalOptions,
context,
baseStart,
this._config.expressionVisitorCtrl
);
compiler.templateVisitAll(referenceVisitor, roots, null);
visitor._variables = referenceVisitor.variables;
roots.forEach(r => visitor.visit(r, context.controller));
visitor.getFailures().forEach(f => this.addFailure(f));
}
}

protected visitNgStyleHelper(style: CssAst, context: ComponentMetadata, styleMetadata: StyleMetadata, baseStart: number) {
protected visitNgStyleHelper(
style: CssAst,
context: ComponentMetadata,
styleMetadata: StyleMetadata,
baseStart: number
) {
if (!style) {
return;
} else {
const sourceFile = this.getContextSourceFile(styleMetadata.url, styleMetadata.style.source);
const visitor = new this._config.cssVisitorCtrl(sourceFile, this._originalOptions, context, styleMetadata, baseStart);
const visitor = new this._config.cssVisitorCtrl(
sourceFile,
this._originalOptions,
context,
styleMetadata,
baseStart
);
style.visit(visitor);
visitor.getFailures().forEach(f => this.addFailure(f));
}
Expand All @@ -246,4 +255,3 @@ export class NgWalker extends Lint.RuleWalker {
return sf;
}
}

3 changes: 0 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,13 @@ export { Rule as DirectiveClassSuffixRule } from './directiveClassSuffixRule';
export { Rule as DirectiveSelectorRule } from './directiveSelectorRule';
export { Rule as I18nRule } from './i18nRule';
export { Rule as ImportDestructuringSpacingRule } from './importDestructuringSpacingRule';
export { Rule as InvokeInjectableRule } from './invokeInjectableRule';
export { Rule as NoAccessMissingMemberRule } from './noAccessMissingMemberRule';
export { Rule as NoAttributeParameterDecoratorRule } from './noAttributeParameterDecoratorRule';
export { Rule as NoForwardRefRule } from './noForwardRefRule';
export { Rule as NoInputRenameRule } from './noInputRenameRule';
export { Rule as NoOutputRenameRule } from './noOutputRenameRule';
export { Rule as NoUnusedCssRule } from './noUnusedCssRule';
export { Rule as PipeImpureRule } from './pipeImpureRule';
export { Rule as PipeNamingRule } from './pipeNamingRule';
export { Rule as TemplatesUsePublicRule } from './templatesUsePublicRule';
export { Rule as UseHostPropertyDecoratorRule } from './useHostPropertyDecoratorRule';
export { Rule as UseInputPropertyDecoratorRule } from './useInputPropertyDecoratorRule';
export { Rule as UseLifeCycleInterfaceRule } from './useLifeCycleInterfaceRule';
Expand Down
38 changes: 0 additions & 38 deletions src/invokeInjectableRule.ts

This file was deleted.

Loading

0 comments on commit 12159e4

Please sign in to comment.