Skip to content

Commit bf78d22

Browse files
committed
fix(pipenaming): use camelCase
1 parent 6f985f9 commit bf78d22

17 files changed

+482
-482
lines changed

src/noAttributeParameterDecoratorRule.ts

+26-26
Original file line numberDiff line numberDiff line change
@@ -5,43 +5,43 @@ import {sprintf} from 'sprintf-js';
55
export class Rule extends Lint.Rules.AbstractRule {
66

77
public apply(sourceFile:ts.SourceFile):Lint.RuleFailure[] {
8-
return this.applyWithWalker(
9-
new ConstructorMetadataWalker(sourceFile,
10-
this.getOptions()));
8+
return this.applyWithWalker(
9+
new ConstructorMetadataWalker(sourceFile,
10+
this.getOptions()));
1111
}
1212

1313
static FAILURE_STRING:string = 'In the constructor of class "%s",' +
14-
' the parameter "%s" uses the @Attribute decorator, ' +
15-
'which is considered as a bad practice. Please,' +
16-
' consider construction of type "@Input() %s: string"';
14+
' the parameter "%s" uses the @Attribute decorator, ' +
15+
'which is considered as a bad practice. Please,' +
16+
' consider construction of type "@Input() %s: string"';
1717

1818
}
1919

2020
export class ConstructorMetadataWalker extends Lint.RuleWalker {
2121

2222
visitConstructorDeclaration(node:ts.ConstructorDeclaration) {
23-
let parentName = (<ts.ClassDeclaration>node.parent).name.text;
24-
(node.parameters || []).forEach(this.validateParameter.bind(this, parentName));
25-
super.visitConstructorDeclaration(node);
23+
let parentName = (<ts.ClassDeclaration>node.parent).name.text;
24+
(node.parameters || []).forEach(this.validateParameter.bind(this, parentName));
25+
super.visitConstructorDeclaration(node);
2626
}
2727

2828
validateParameter(className:string, parameter) {
29-
let parameterName = (<ts.Identifier>parameter.name).text;
30-
if (parameter.decorators) {
31-
parameter.decorators.forEach((decorator)=> {
32-
let baseExpr = <any>decorator.expression || {};
33-
let expr = baseExpr.expression || {};
34-
let name = expr.text;
35-
if (name == 'Attribute') {
36-
let failureConfig:string[] = [className, parameterName, parameterName];
37-
failureConfig.unshift(Rule.FAILURE_STRING);
38-
this.addFailure(
39-
this.createFailure(
40-
parameter.getStart(),
41-
parameter.getWidth(),
42-
sprintf.apply(this, failureConfig)));
43-
}
44-
})
45-
}
29+
let parameterName = (<ts.Identifier>parameter.name).text;
30+
if (parameter.decorators) {
31+
parameter.decorators.forEach((decorator)=> {
32+
let baseExpr = <any>decorator.expression || {};
33+
let expr = baseExpr.expression || {};
34+
let name = expr.text;
35+
if (name == 'Attribute') {
36+
let failureConfig:string[] = [className, parameterName, parameterName];
37+
failureConfig.unshift(Rule.FAILURE_STRING);
38+
this.addFailure(
39+
this.createFailure(
40+
parameter.getStart(),
41+
parameter.getWidth(),
42+
sprintf.apply(this, failureConfig)));
43+
}
44+
})
45+
}
4646
}
4747
}

src/noForwardRefRule.ts

+18-18
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import {sprintf} from 'sprintf-js';
55
export class Rule extends Lint.Rules.AbstractRule {
66

77
public apply(sourceFile:ts.SourceFile):Lint.RuleFailure[] {
8-
return this.applyWithWalker(
9-
new ExpressionCallMetadataWalker(sourceFile,
10-
this.getOptions()));
8+
return this.applyWithWalker(
9+
new ExpressionCallMetadataWalker(sourceFile,
10+
this.getOptions()));
1111
}
1212

1313
static FAILURE_STRING:string = 'Avoid using forwardRef in class "%s"';
@@ -16,24 +16,24 @@ export class Rule extends Lint.Rules.AbstractRule {
1616
export class ExpressionCallMetadataWalker extends Lint.RuleWalker {
1717

1818
visitCallExpression(node:ts.CallExpression) {
19-
this.validateCallExpression(node);
20-
super.visitCallExpression(node);
19+
this.validateCallExpression(node);
20+
super.visitCallExpression(node);
2121
}
2222

2323
private validateCallExpression(callExpression) {
24-
if (callExpression.expression.text === 'forwardRef') {
25-
let currentNode:any = callExpression;
26-
while (currentNode.parent.parent) {
27-
currentNode = currentNode.parent;
28-
}
29-
let failureConfig:string[] = [currentNode.name.text];
30-
failureConfig.unshift(Rule.FAILURE_STRING);
31-
this.addFailure(
32-
this.createFailure(
33-
callExpression.getStart(),
34-
callExpression.getWidth(),
35-
sprintf.apply(this, failureConfig)));
36-
}
24+
if (callExpression.expression.text === 'forwardRef') {
25+
let currentNode:any = callExpression;
26+
while (currentNode.parent.parent) {
27+
currentNode = currentNode.parent;
28+
}
29+
let failureConfig:string[] = [currentNode.name.text];
30+
failureConfig.unshift(Rule.FAILURE_STRING);
31+
this.addFailure(
32+
this.createFailure(
33+
callExpression.getStart(),
34+
callExpression.getWidth(),
35+
sprintf.apply(this, failureConfig)));
36+
}
3737
}
3838

3939
}

src/noInputRenameRule.ts

+16-16
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,30 @@ import {Ng2Walker} from "./util/ng2Walker";
66
export class Rule extends Lint.Rules.AbstractRule {
77

88
public apply(sourceFile:ts.SourceFile):Lint.RuleFailure[] {
9-
return this.applyWithWalker(
10-
new InputMetadataWalker(sourceFile,
11-
this.getOptions()));
9+
return this.applyWithWalker(
10+
new InputMetadataWalker(sourceFile,
11+
this.getOptions()));
1212
}
1313

1414
static FAILURE_STRING:string = 'In the class "%s", the directive ' +
15-
'input property "%s" should not be renamed.' +
16-
'Please, consider the following use "@Input() %s: string"';
15+
'input property "%s" should not be renamed.' +
16+
'Please, consider the following use "@Input() %s: string"';
1717
}
1818

1919

2020
export class InputMetadataWalker extends Ng2Walker {
2121

2222
visitNg2Input(property:ts.PropertyDeclaration, input:ts.Decorator, args:string[]) {
23-
let className = (<any>property).parent.name.text;
24-
let memberName = (<any>property.name).text;
25-
if (args.length != 0 && memberName != args[0]) {
26-
let failureConfig:string[] = [className, memberName, memberName];
27-
failureConfig.unshift(Rule.FAILURE_STRING);
28-
this.addFailure(
29-
this.createFailure(
30-
property.getStart(),
31-
property.getWidth(),
32-
sprintf.apply(this, failureConfig)));
33-
}
23+
let className = (<any>property).parent.name.text;
24+
let memberName = (<any>property.name).text;
25+
if (args.length != 0 && memberName != args[0]) {
26+
let failureConfig:string[] = [className, memberName, memberName];
27+
failureConfig.unshift(Rule.FAILURE_STRING);
28+
this.addFailure(
29+
this.createFailure(
30+
property.getStart(),
31+
property.getWidth(),
32+
sprintf.apply(this, failureConfig)));
33+
}
3434
}
3535
}

src/noOutputRenameRule.ts

+16-16
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,30 @@ import {Ng2Walker} from "./util/ng2Walker";
66
export class Rule extends Lint.Rules.AbstractRule {
77

88
public apply(sourceFile:ts.SourceFile):Lint.RuleFailure[] {
9-
return this.applyWithWalker(
10-
new OutputMetadataWalker(sourceFile,
11-
this.getOptions()));
9+
return this.applyWithWalker(
10+
new OutputMetadataWalker(sourceFile,
11+
this.getOptions()));
1212
}
1313

1414
static FAILURE_STRING:string = 'In the class "%s", the directive output ' +
15-
'property "%s" should not be renamed.' +
16-
'Please, consider the following use "@Output() %s = new EventEmitter();"';
15+
'property "%s" should not be renamed.' +
16+
'Please, consider the following use "@Output() %s = new EventEmitter();"';
1717
}
1818

1919

2020
export class OutputMetadataWalker extends Ng2Walker {
2121

2222
visitNg2Output(property:ts.PropertyDeclaration, output:ts.Decorator, args:string[]) {
23-
let className = (<any>property).parent.name.text;
24-
let memberName = (<any>property.name).text;
25-
if (args.length != 0 && memberName != args[0]) {
26-
let failureConfig:string[] = [className, memberName, memberName];
27-
failureConfig.unshift(Rule.FAILURE_STRING);
28-
this.addFailure(
29-
this.createFailure(
30-
property.getStart(),
31-
property.getWidth(),
32-
sprintf.apply(this, failureConfig)));
33-
}
23+
let className = (<any>property).parent.name.text;
24+
let memberName = (<any>property.name).text;
25+
if (args.length != 0 && memberName != args[0]) {
26+
let failureConfig:string[] = [className, memberName, memberName];
27+
failureConfig.unshift(Rule.FAILURE_STRING);
28+
this.addFailure(
29+
this.createFailure(
30+
property.getStart(),
31+
property.getWidth(),
32+
sprintf.apply(this, failureConfig)));
33+
}
3434
}
3535
}

src/pipeNamingRule.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ export class Rule extends Lint.Rules.AbstractRule {
1414

1515
constructor(ruleName:string, value:any, disabledIntervals:Lint.IDisabledInterval[]) {
1616
super(ruleName, value, disabledIntervals);
17-
if (value[1] === 'kebab-case') {
18-
this.validator = SelectorValidator.kebabCase;
17+
if (value[1] === 'camelCase') {
18+
this.validator = SelectorValidator.camelCase;
1919
}
2020
if (value[2]) {
2121
this.hasPrefix = true;
@@ -38,10 +38,10 @@ export class Rule extends Lint.Rules.AbstractRule {
3838
}
3939

4040
static FAILURE_WITHOUT_PREFIX:string = 'The name of the Pipe decorator of class %s should' +
41-
' be named kebab-case, however its value is "%s".';
41+
' be named camelCase, however its value is "%s".';
4242

4343
static FAILURE_WITH_PREFIX:string = 'The name of the Pipe decorator of class %s should' +
44-
' be named kebab-case with prefix %s, however its value is "%s".';
44+
' be named camelCase with prefix %s, however its value is "%s".';
4545
}
4646

4747
export class ClassMetadataWalker extends Lint.RuleWalker {

src/useLifeCycleInterfaceRule.ts

+48-48
Original file line numberDiff line numberDiff line change
@@ -6,79 +6,79 @@ import SyntaxKind = require('./util/syntaxKind');
66
export class Rule extends Lint.Rules.AbstractRule {
77

88
public apply(sourceFile:ts.SourceFile):Lint.RuleFailure[] {
9-
return this.applyWithWalker(
10-
new ClassMetadataWalker(sourceFile,
11-
this.getOptions()));
9+
return this.applyWithWalker(
10+
new ClassMetadataWalker(sourceFile,
11+
this.getOptions()));
1212
}
1313

1414
static FAILURE_SINGLE:string = 'In class %s the method %s is a life cycle hook' +
15-
' and should implement the %s interface';
15+
' and should implement the %s interface';
1616

1717
static FAILURE_MANY = 'In class %s the methods - %s' +
18-
' are life cycle hooks and should implement the interfaces: %s';
18+
' are life cycle hooks and should implement the interfaces: %s';
1919

2020
static HOOKS_PREFIX = 'ng';
2121

2222
static LIFE_CYCLE_HOOKS_NAMES:Array<any> = [
23-
"OnChanges",
24-
"OnInit",
25-
"DoCheck",
26-
"AfterContentInit",
27-
"AfterContentChecked",
28-
"AfterViewInit",
29-
"AfterViewChecked",
30-
"OnDestroy"
23+
"OnChanges",
24+
"OnInit",
25+
"DoCheck",
26+
"AfterContentInit",
27+
"AfterContentChecked",
28+
"AfterViewInit",
29+
"AfterViewChecked",
30+
"OnDestroy"
3131
]
3232

3333
}
3434

3535
export class ClassMetadataWalker extends Lint.RuleWalker {
3636

3737
visitClassDeclaration(node:ts.ClassDeclaration) {
38-
let syntaxKind = SyntaxKind.current();
39-
let className = node.name.text;
38+
let syntaxKind = SyntaxKind.current();
39+
let className = node.name.text;
4040

41-
let interfaces = [];
42-
if (node.heritageClauses) {
43-
let interfacesClause = node.heritageClauses.filter(h=>h.token === syntaxKind.ImplementsKeyword);
44-
if (interfacesClause.length !== 0) {
45-
interfaces = interfacesClause[0].types.map(t=>(<any>t.expression).text);
46-
}
47-
}
41+
let interfaces = [];
42+
if (node.heritageClauses) {
43+
let interfacesClause = node.heritageClauses.filter(h=>h.token === syntaxKind.ImplementsKeyword);
44+
if (interfacesClause.length !== 0) {
45+
interfaces = interfacesClause[0].types.map(t=>(<any>t.expression).text);
46+
}
47+
}
4848

49-
let missing:Array<string> = this.extractMissing(node.members, syntaxKind, interfaces);
49+
let missing:Array<string> = this.extractMissing(node.members, syntaxKind, interfaces);
5050

51-
if (missing.length !== 0) {
52-
this.addFailure(
53-
this.createFailure(
54-
node.getStart(),
55-
node.getWidth(),
56-
sprintf.apply(this, this.formatFailure(className, missing))));
57-
}
58-
super.visitClassDeclaration(node);
51+
if (missing.length !== 0) {
52+
this.addFailure(
53+
this.createFailure(
54+
node.getStart(),
55+
node.getWidth(),
56+
sprintf.apply(this, this.formatFailure(className, missing))));
57+
}
58+
super.visitClassDeclaration(node);
5959
}
6060

6161

6262
private extractMissing(members:ts.NodeArray<ts.ClassElement>,
63-
syntaxKind:SyntaxKind.SyntaxKind,
64-
interfaces:Array<string>):Array<string> {
65-
let ngMembers = members.filter(m=>m.kind === syntaxKind.MethodDeclaration)
66-
.map(m=>(<any>m.name).text)
67-
.filter(n=>n.substr(0, 2) === Rule.HOOKS_PREFIX)
68-
.map(n=>n.substr(2, n.lenght))
69-
.filter(n=>Rule.LIFE_CYCLE_HOOKS_NAMES.indexOf(n) !== -1);
70-
return ngMembers.filter(m=>interfaces.indexOf(m) === -1);
63+
syntaxKind:SyntaxKind.SyntaxKind,
64+
interfaces:Array<string>):Array<string> {
65+
let ngMembers = members.filter(m=>m.kind === syntaxKind.MethodDeclaration)
66+
.map(m=>(<any>m.name).text)
67+
.filter(n=>n.substr(0, 2) === Rule.HOOKS_PREFIX)
68+
.map(n=>n.substr(2, n.lenght))
69+
.filter(n=>Rule.LIFE_CYCLE_HOOKS_NAMES.indexOf(n) !== -1);
70+
return ngMembers.filter(m=>interfaces.indexOf(m) === -1);
7171
}
7272

7373
private formatFailure(className:string, missing:Array<string>):Array<string> {
74-
let failureConfig:Array<string>;
75-
if (missing.length === 1) {
76-
failureConfig = [Rule.FAILURE_SINGLE, className, Rule.HOOKS_PREFIX + missing[0], missing[0]];
77-
} else {
78-
let joinedNgMissing:string = missing.map(m=>Rule.HOOKS_PREFIX + m).join(', ');
79-
let joinedMissingInterfaces = missing.join(', ');
80-
failureConfig = [Rule.FAILURE_MANY, className, joinedNgMissing, joinedMissingInterfaces];
81-
}
82-
return failureConfig;
74+
let failureConfig:Array<string>;
75+
if (missing.length === 1) {
76+
failureConfig = [Rule.FAILURE_SINGLE, className, Rule.HOOKS_PREFIX + missing[0], missing[0]];
77+
} else {
78+
let joinedNgMissing:string = missing.map(m=>Rule.HOOKS_PREFIX + m).join(', ');
79+
let joinedMissingInterfaces = missing.join(', ');
80+
failureConfig = [Rule.FAILURE_MANY, className, joinedNgMissing, joinedMissingInterfaces];
81+
}
82+
return failureConfig;
8383
}
8484
}

0 commit comments

Comments
 (0)