Skip to content

Commit

Permalink
fix: align to breaking changes introduced by tslint
Browse files Browse the repository at this point in the history
  • Loading branch information
mgechev committed Apr 23, 2017
1 parent ace2c48 commit 49b1e80
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 20 deletions.
4 changes: 1 addition & 3 deletions src/componentClassSuffixRule.ts
Expand Up @@ -39,9 +39,7 @@ export class Rule extends Lint.Rules.AbstractRule {
.fmap(controller => controller.name)
.fmap(name => {
const className = name.text;
if (suffixList.length > 0) {
suffixList = suffixList.slice(1, suffixList.length);
} else {
if (suffixList.length === 0) {
suffixList = ['Component'];
}
if (!Rule.validate(className, suffixList)) {
Expand Down
2 changes: 1 addition & 1 deletion src/directiveClassSuffixRule.ts
Expand Up @@ -44,7 +44,7 @@ export class ClassMetadataWalker extends NgWalker {
visitNgDirective(meta: DirectiveMetadata) {
let name = meta.controller.name;
let className:string = name.text;
const suffix = this.getOptions()[1] || 'Directive';
const suffix = this.getOptions()[0] || 'Directive';
if (!Rule.validate(className, suffix)) {
this.addFailure(
this.createFailure(
Expand Down
15 changes: 9 additions & 6 deletions src/pipeNamingRule.ts
Expand Up @@ -46,14 +46,17 @@ export class Rule extends Lint.Rules.AbstractRule {
constructor(options: IOptions) {
super(options);

const args = options.ruleArguments;
if (args[1] === 'camelCase') {
let args = options.ruleArguments;
if (!(args instanceof Array)) {
args = [args];
}
if (args[0] === 'camelCase') {
this.validator = SelectorValidator.camelCase;
}
if (args.length > 2) {
if (args.length > 1) {
this.hasPrefix = true;
let prefixExpression: string = (args.slice(2) || []).join('|');
this.prefix = (args.slice(2) || []).join(',');
let prefixExpression: string = (args.slice(1) || []).join('|');
this.prefix = (args.slice(1) || []).join(',');
this.prefixChecker = SelectorValidator.prefix(prefixExpression, 'camelCase');
}
}
Expand Down Expand Up @@ -86,7 +89,7 @@ export class ClassMetadataWalker extends NgWalker {
private validateProperties(className:string, pipe:any) {
let argument = this.extractArgument(pipe);
if (argument.kind === SyntaxKind.current().ObjectLiteralExpression) {
argument.properties.filter(n=>n.name.text === 'name')
argument.properties.filter(n => n.name.text === 'name')
.forEach(this.validateProperty.bind(this, className));
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/selectorNameBase.ts
Expand Up @@ -18,9 +18,9 @@ export abstract class SelectorRule extends Lint.Rules.AbstractRule {

constructor(options: IOptions) {
super(options);
const args = options.ruleArguments;
const args = this.getOptions().ruleArguments;

let type: SelectorType[] = args[1] || ['element', 'attribute'];
let type: SelectorType[] = args[0] || ['element', 'attribute'];
if (!(type instanceof Array)) {
type = [type];
}
Expand All @@ -33,13 +33,13 @@ export abstract class SelectorRule extends Lint.Rules.AbstractRule {
}
this.types = internal;

let prefix = args[2] || [];
let prefix = args[1] || [];
if (!(prefix instanceof Array)) {
prefix = [prefix];
}
this.prefixes = prefix;

let style = args[3];
let style = args[2];
if (!(style instanceof Array)) {
style = [style];
}
Expand Down Expand Up @@ -120,10 +120,10 @@ export class SelectorValidatorWalker extends Lint.RuleWalker {
.forEach(i => {
const selectors: compiler.CssSelector[] = this.extractMainSelector(i);
if (!this.rule.validateType(selectors)) {
let error = sprintf(this.rule.getTypeFailure(), className, this.rule.getOptions().ruleArguments[1]);
let error = sprintf(this.rule.getTypeFailure(), className, this.rule.getOptions().ruleArguments[0]);
this.addFailure(this.createFailure(i.getStart(), i.getWidth(), error));
} else if (!this.rule.validateStyle(selectors)) {
let name = this.rule.getOptions().ruleArguments[3];
let name = this.rule.getOptions().ruleArguments[2];
if (name === 'kebab-case') {
name += ' and include dash';
}
Expand Down
2 changes: 1 addition & 1 deletion test/pipeNamingRule.spec.ts
Expand Up @@ -62,7 +62,7 @@ describe('pipe-naming', () => {
message: 'The name of the Pipe decorator of class Test should be named camelCase,' +
' however its value is "foo-bar".',
source,
options: 'camelCase'
options: 'camelCase'
});
});
});
Expand Down
4 changes: 1 addition & 3 deletions test/testHelper.ts
Expand Up @@ -34,9 +34,7 @@ function lint(ruleName: string, source: string, options: any): tslint.LintResult
rulesDirectory: []
};
if (!options) {
options = true;
} else {
options = [true].concat(options);
options = [];
}
const ops: Partial<tslint.IOptions> = { ruleName, ruleArguments: options, disabledIntervals: [] };
configuration.rules.set(ruleName, ops);
Expand Down

0 comments on commit 49b1e80

Please sign in to comment.