Skip to content

Commit

Permalink
chore(package): update deps, fix broken lint rules
Browse files Browse the repository at this point in the history
  • Loading branch information
jdanyow committed Jan 15, 2017
1 parent 4fbf24e commit 47f4f8b
Show file tree
Hide file tree
Showing 21 changed files with 92 additions and 96 deletions.
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,17 @@
"concurrently": "^3.1.0",
"conventional-changelog-cli": "^1.2.0",
"copyfiles": "^1.0.0",
"cross-env": "^3.1.0",
"cross-env": "^3.1.4",
"jasmine-core": "^2.5.2",
"karma": "^1.3.0",
"karma": "^1.4.0",
"karma-chrome-launcher": "^2.0.0",
"karma-ie-launcher": "^1.0.0",
"karma-jasmine": "^1.1.0",
"karma-requirejs": "^1.1.0",
"requirejs": "^2.2.0",
"requirejs-text": "^2.0.12",
"requirejs": "^2.3.2",
"requirejs-text": "^2.0.15",
"rimraf": "^2.5.4",
"tslint": "^4.2.0",
"tslint": "^4.3.1",
"typedoc": "^0.5.5",
"typescript": "^2.1.5"
},
Expand Down
2 changes: 1 addition & 1 deletion src/implementation/rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export interface Rule<TObject, TValue> {
property: RuleProperty;
condition: (value: TValue, object?: TObject) => boolean | Promise<boolean>;
config: Object;
when: { (object: TObject): boolean } | null;
when: ((object: TObject) => boolean) | null;
messageKey: string;
message: Expression | null;
sequence: number;
Expand Down
3 changes: 2 additions & 1 deletion src/implementation/standard-validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class StandardValidator extends Validator {
constructor(messageProvider: ValidationMessageProvider, resources: ViewResources) {
super();
this.messageProvider = messageProvider;
this.lookupFunctions = (<any>resources).lookupFunctions;
this.lookupFunctions = (resources as any).lookupFunctions;
this.getDisplayName = messageProvider.getDisplayName.bind(messageProvider);
}

Expand Down Expand Up @@ -62,6 +62,7 @@ export class StandardValidator extends Validator {

private getMessage(rule: Rule<any, any>, object: any, value: any): string {
const expression: Expression = rule.message || this.messageProvider.getMessage(rule.messageKey);
// tslint:disable-next-line:prefer-const
let { name: propertyName, displayName } = rule.property;
if (propertyName !== null) {
displayName = this.messageProvider.getDisplayName(propertyName, displayName);
Expand Down
17 changes: 7 additions & 10 deletions src/implementation/validation-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ import { isString } from './util';

import * as LogManager from 'aurelia-logging';

export interface PropertyAccessor<TObject, TValue> {
(object: TObject): TValue;
}
export type PropertyAccessor<TObject, TValue> = (object: TObject) => TValue;

export class ValidationParser {
public static inject = [Parser, BindingLanguage];
Expand All @@ -35,19 +33,19 @@ export class ValidationParser {
return this.cache[message];
}

const parts: (Expression | string)[] | null = (<any>this.bindinqLanguage).parseInterpolation(null, message);
const parts: (Expression | string)[] | null = (this.bindinqLanguage as any).parseInterpolation(null, message);
if (parts === null) {
return new LiteralString(message);
}
let expression: Expression = new LiteralString(<string>parts[0]);
let expression: Expression = new LiteralString(parts[0] as string);
for (let i = 1; i < parts.length; i += 2) {
expression = new Binary(
'+',
expression,
new Binary(
'+',
this.coalesce(<Expression>parts[i]),
new LiteralString(<string>parts[i + 1])
this.coalesce(parts[i] as Expression),
new LiteralString(parts[i + 1] as string)
)
);
}
Expand All @@ -61,7 +59,7 @@ export class ValidationParser {

public parseProperty<TObject, TValue>(property: string | PropertyAccessor<TObject, TValue>): RuleProperty {
if (isString(property)) {
return { name: <string>property, displayName: null };
return { name: property as string, displayName: null };
}
const accessor = this.getAccessorExpression(property.toString());
if (accessor instanceof AccessScope
Expand Down Expand Up @@ -114,9 +112,8 @@ export class MessageExpressionValidator extends Unparser {
}
if (['displayName', 'propertyName', 'value', 'object', 'config', 'getDisplayName'].indexOf(access.name) !== -1) {
LogManager.getLogger('aurelia-validation')
/* tslint:disable:max-line-length */
// tslint:disable-next-line:max-line-length
.warn(`Did you mean to use "$${access.name}" instead of "${access.name}" in this validation message template: "${this.originalMessage}"?`);
/* tslint:enable:max-line-length */
}
}
}
12 changes: 6 additions & 6 deletions src/implementation/validation-rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export class FluentRuleCustomizer<TObject, TValue> {
* Target a property with validation rules.
* @param property The property to target. Can be the property name or a property accessor function.
*/
public ensure<TValue2>(subject: string | { (model: TObject): TValue2; }) {
public ensure<TValue2>(subject: string | ((model: TObject) => TValue2)) {
return this.fluentEnsure.ensure<TValue2>(subject);
}

Expand Down Expand Up @@ -248,9 +248,9 @@ export class FluentRules<TObject, TValue> {
let rule = FluentRules.customRules[name];
if (!rule) {
// standard rule?
rule = (<any>this)[name];
rule = (this as any)[name];
if (rule instanceof Function) {
return <FluentRuleCustomizer<TObject, TValue>>rule.call(this, ...args);
return rule.call(this, ...args);
}
throw new Error(`Rule with name "${name}" does not exist.`);
}
Expand All @@ -268,7 +268,7 @@ export class FluentRules<TObject, TValue> {
value =>
value !== null
&& value !== undefined
&& !(isString(value) && !/\S/.test(<any>value))
&& !(isString(value) && !/\S/.test(value as any))
).withMessageKey('required');
}

Expand All @@ -279,7 +279,7 @@ export class FluentRules<TObject, TValue> {
*/
public matches(regex: RegExp) {
return this.satisfies(
value => value === null || value === undefined || (<any>value).length === 0 || regex.test(<any>value))
value => value === null || value === undefined || (value as any).length === 0 || regex.test(value as any))
.withMessageKey('matches');
}

Expand Down Expand Up @@ -341,7 +341,7 @@ export class FluentRules<TObject, TValue> {
*/
public equals(expectedValue: TValue) {
return this.satisfies(
value => value === null || value === undefined || <any>value === '' || value === expectedValue,
value => value === null || value === undefined || value as any === '' || value === expectedValue,
{ expectedValue })
.withMessageKey('equals');
}
Expand Down
2 changes: 1 addition & 1 deletion src/property-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from 'aurelia-binding';

function getObject(expression: Expression, objectExpression: Expression, source: any): null | undefined | Object {
let value = objectExpression.evaluate(source, <any>null);
const value = objectExpression.evaluate(source, null as any);
if (value === null || value === undefined || value instanceof Object) {
return value;
}
Expand Down
7 changes: 4 additions & 3 deletions src/validate-binding-behavior-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ export abstract class ValidateBindingBehaviorBase {
return target;
}
// custom element or custom attribute
// tslint:disable-next-line:prefer-const
for (let i = 0, ii = view.controllers.length; i < ii; i++) {
let controller: any = view.controllers[i];
const controller: any = view.controllers[i];
if (controller.viewModel === target) {
const element = controller.container.get(DOM.Element);
if (element) {
Expand Down Expand Up @@ -61,7 +62,7 @@ export abstract class ValidateBindingBehaviorBase {
if (trigger & validateTrigger.change) {
binding.standardUpdateSource = binding.updateSource;
// tslint:disable-next-line:only-arrow-functions
binding.updateSource = function (value: any) {
binding.updateSource = function(value: any) {
this.standardUpdateSource(value);
this.validationController.validateBinding(this);
};
Expand All @@ -79,7 +80,7 @@ export abstract class ValidateBindingBehaviorBase {
if (trigger !== validateTrigger.manual) {
binding.standardUpdateTarget = binding.updateTarget;
// tslint:disable-next-line:only-arrow-functions
binding.updateTarget = function (value: any) {
binding.updateTarget = function(value: any) {
this.standardUpdateTarget(value);
this.validationController.resetBinding(this);
};
Expand Down
4 changes: 2 additions & 2 deletions src/validation-controller-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class ValidationControllerFactory {
*/
public create(validator?: Validator) {
if (!validator) {
validator = <Validator>this.container.get(Validator);
validator = this.container.get(Validator) as Validator;
}
return new ValidationController(validator);
}
Expand All @@ -33,4 +33,4 @@ export class ValidationControllerFactory {
}
}

(<any>ValidationControllerFactory)['protocol:aurelia:resolver'] = true;
(ValidationControllerFactory as any)['protocol:aurelia:resolver'] = true;
29 changes: 15 additions & 14 deletions src/validation-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export class ValidationController {
this.renderers.push(renderer);
renderer.render({
kind: 'validate',
render: this.results.map(result => ({ result, elements: <Element[]>this.elements.get(result) })),
render: this.results.map(result => ({ result, elements: this.elements.get(result) as Element[] })),
unrender: []
});
}
Expand All @@ -113,7 +113,7 @@ export class ValidationController {
renderer.render({
kind: 'reset',
render: [],
unrender: this.results.map(result => ({ result, elements: <Element[]>this.elements.get(result) }))
unrender: this.results.map(result => ({ result, elements: this.elements.get(result) as Element[] }))
});
}

Expand Down Expand Up @@ -167,6 +167,7 @@ export class ValidationController {
// Get a function that will process the validation instruction.
let execute: () => Promise<ValidateResult[]>;
if (instruction) {
// tslint:disable-next-line:prefer-const
let { object, propertyName, rules } = instruction;
// if rules were not specified, check the object map.
rules = rules || this.objects.get(object);
Expand All @@ -182,11 +183,11 @@ export class ValidationController {
// validate all objects and bindings.
execute = () => {
const promises: Promise<ValidateResult[]>[] = [];
for (let [object, rules] of Array.from(this.objects)) {
for (const [object, rules] of Array.from(this.objects)) {
promises.push(this.validator.validateObject(object, rules));
}
for (let [binding, { rules }] of Array.from(this.bindings)) {
const propertyInfo = getPropertyInfo(<Expression>binding.sourceExpression, (<any>binding).source);
for (const [binding, { rules }] of Array.from(this.bindings)) {
const propertyInfo = getPropertyInfo(binding.sourceExpression as Expression, binding.source);
if (!propertyInfo || this.objects.has(propertyInfo.object)) {
continue;
}
Expand All @@ -198,7 +199,7 @@ export class ValidationController {

// Wait for any existing validation to finish, execute the instruction, render the results.
this.validating = true;
let returnPromise: Promise<ControllerValidateResult> = this.finishValidating
const returnPromise: Promise<ControllerValidateResult> = this.finishValidating
.then(execute)
.then((newResults: ValidateResult[]) => {
const predicate = this.getInstructionPredicate(instruction);
Expand Down Expand Up @@ -243,8 +244,8 @@ export class ValidationController {
*/
private getAssociatedElements({ object, propertyName }: ValidateResult): Element[] {
const elements: Element[] = [];
for (let [binding, { target }] of Array.from(this.bindings)) {
const propertyInfo = getPropertyInfo(<Expression>binding.sourceExpression, (<any>binding).source);
for (const [binding, { target }] of Array.from(this.bindings)) {
const propertyInfo = getPropertyInfo(binding.sourceExpression as Expression, binding.source);
if (propertyInfo && propertyInfo.object === object && propertyInfo.propertyName === propertyName) {
elements.push(target);
}
Expand All @@ -267,9 +268,9 @@ export class ValidationController {
newResults = newResults.slice(0);

// create unrender instructions from the old results.
for (let oldResult of oldResults) {
for (const oldResult of oldResults) {
// get the elements associated with the old result.
const elements = <Element[]>this.elements.get(oldResult);
const elements = this.elements.get(oldResult) as Element[];

// remove the old result from the element map.
this.elements.delete(oldResult);
Expand Down Expand Up @@ -311,7 +312,7 @@ export class ValidationController {
}

// create render instructions from the remaining new results.
for (let result of newResults) {
for (const result of newResults) {
const elements = this.getAssociatedElements(result);
instruction.render.push({ result, elements });
this.elements.set(result, elements);
Expand All @@ -322,7 +323,7 @@ export class ValidationController {
}

// render.
for (let renderer of this.renderers) {
for (const renderer of this.renderers) {
renderer.render(instruction);
}
}
Expand All @@ -334,7 +335,7 @@ export class ValidationController {
if (!binding.isBound) {
return;
}
let propertyInfo = getPropertyInfo(<Expression>binding.sourceExpression, (<any>binding).source);
const propertyInfo = getPropertyInfo(binding.sourceExpression as Expression, binding.source);
let rules = undefined;
const registeredBinding = this.bindings.get(binding);
if (registeredBinding) {
Expand All @@ -353,7 +354,7 @@ export class ValidationController {
*/
public resetBinding(binding: Binding) {
const registeredBinding = this.bindings.get(binding);
let propertyInfo = getPropertyInfo(<Expression>binding.sourceExpression, (<any>binding).source);
let propertyInfo = getPropertyInfo(binding.sourceExpression as Expression, binding.source);
if (!propertyInfo && registeredBinding) {
propertyInfo = registeredBinding.propertyInfo;
}
Expand Down
6 changes: 3 additions & 3 deletions src/validation-errors-custom-attribute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class ValidationErrorsCustomAttribute implements ValidationRenderer {

private errorsInternal: RenderedError[] = [];

constructor(private boundaryElement: Element, private controllerAccessor: { (): ValidationController; }) {
constructor(private boundaryElement: Element, private controllerAccessor: () => ValidationController) {
}

public sort() {
Expand All @@ -40,14 +40,14 @@ export class ValidationErrorsCustomAttribute implements ValidationRenderer {
}

public render(instruction: RenderInstruction) {
for (let { result } of instruction.unrender) {
for (const { result } of instruction.unrender) {
const index = this.errorsInternal.findIndex(x => x.error === result);
if (index !== -1) {
this.errorsInternal.splice(index, 1);
}
}

for (let { result, elements } of instruction.render) {
for (const { result, elements } of instruction.render) {
if (result.valid) {
continue;
}
Expand Down
4 changes: 2 additions & 2 deletions src/validation-renderer-custom-attribute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class ValidationRendererCustomAttribute {

public unbind() {
this.controller.removeRenderer(this.renderer);
this.controller = <any>null;
this.renderer = <any>null;
this.controller = null as any;
this.renderer = null as any;
}
}
20 changes: 10 additions & 10 deletions test/basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@ describe('end to end', () => {

let viewModel: RegistrationForm;

let renderer = { render: jasmine.createSpy() };
const renderer = { render: jasmine.createSpy() };

(<Promise<any>>component.create(<any>bootstrap))
component.create(bootstrap as any)
// grab some references.
.then(() => {
viewModel = component.viewModel;
viewModel.controller.addRenderer(renderer);
firstName = <HTMLInputElement>component.element.querySelector('#firstName');
lastName = <HTMLInputElement>component.element.querySelector('#lastName');
number1 = <HTMLInputElement>component.element.querySelector('#number1');
number2 = <HTMLInputElement>component.element.querySelector('#number2');
password = <HTMLInputElement>component.element.querySelector('#password');
confirmPassword = <HTMLInputElement>component.element.querySelector('#confirmPassword');
firstName = component.element.querySelector('#firstName') as HTMLInputElement;
lastName = component.element.querySelector('#lastName') as HTMLInputElement;
number1 = component.element.querySelector('#number1') as HTMLInputElement;
number2 = component.element.querySelector('#number2') as HTMLInputElement;
password = component.element.querySelector('#password') as HTMLInputElement;
confirmPassword = component.element.querySelector('#confirmPassword') as HTMLInputElement;
})
// initially there should not be any errors
.then(() => expect(viewModel.controller.errors.length).toBe(0))
Expand Down Expand Up @@ -111,15 +111,15 @@ describe('end to end', () => {
// confirm there's an error.
.then(() => expect(viewModel.controller.errors.length).toBe(2))
// change the number2 field- this should trigger validation.
.then(() => change(<HTMLInputElement>number2.firstElementChild, '-1'))
.then(() => change(number2.firstElementChild as HTMLInputElement, '-1'))
// confirm there's an error.
.then(() => expect(viewModel.controller.errors.length).toBe(3))
// change the number1 field- this should trigger validation.
.then(() => change(number1, '32'))
// confirm the error was reset.
.then(() => expect(viewModel.controller.errors.length).toBe(2))
// change the number2 field- this should trigger validation.
.then(() => change(<HTMLInputElement>number2.firstElementChild, '23'))
.then(() => change(number2.firstElementChild as HTMLInputElement, '23'))
// confirm the error was reset.
.then(() => expect(viewModel.controller.errors.length).toBe(1))
// change the numbers back to invalid values.
Expand Down
Loading

0 comments on commit 47f4f8b

Please sign in to comment.