Skip to content

Commit

Permalink
Applied stricter tslint settings, reproducing and/or fixing small issues
Browse files Browse the repository at this point in the history
  • Loading branch information
loedeman committed Sep 1, 2017
1 parent 9ff3ead commit 8b3a230
Show file tree
Hide file tree
Showing 29 changed files with 208 additions and 60 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "automapper-ts",
"version": "1.8.2",
"version": "1.8.3",
"description": "A convention-based object-object mapper in JavaScript, written in TypeScript. Ported from the original C# AutoMapper library at https://github.com/AutoMapper/AutoMapper.",
"keywords": [
"automapper",
Expand Down
2 changes: 1 addition & 1 deletion dist/automapper-classes.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// [bundle remove start]
/// <reference path="automapper-interfaces.d.ts" />
// [bundle remove end]
// Type definitions for AutoMapper.js 1.8.2
// Type definitions for AutoMapper.js 1.8.3
// Project: https://github.com/loedeman/AutoMapper
// Definitions by: Bert Loedeman <https://github.com/loedeman>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
Expand Down
2 changes: 1 addition & 1 deletion dist/automapper-declaration.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/// <reference path="automapper-classes.d.ts" />

// Type definitions for AutoMapper.js 1.8.2
// Type definitions for AutoMapper.js 1.8.3
// Project: https://github.com/loedeman/AutoMapper
// Definitions by: Bert Loedeman <https://github.com/loedeman>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
Expand Down
2 changes: 1 addition & 1 deletion dist/automapper-interfaces.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// [bundle remove start]
// Type definitions for AutoMapper.js 1.8.2
// Type definitions for AutoMapper.js 1.8.3
// Project: https://github.com/loedeman/AutoMapper
// Definitions by: Bert Loedeman <https://github.com/loedeman>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
Expand Down
2 changes: 1 addition & 1 deletion dist/automapper.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Type definitions for AutoMapper.js 1.8.2
// Type definitions for AutoMapper.js 1.8.3
// Project: https://github.com/loedeman/AutoMapper
// Definitions by: Bert Loedeman <https://github.com/loedeman>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
Expand Down
4 changes: 2 additions & 2 deletions dist/automapper.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dist/automapper.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion gulp.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
var GulpConfig = (function () {

function gulpConfig() {
this.libraryVersion = '1.8.2';
this.libraryVersion = '1.8.3';
// folder definitions
this.baseFolder = './';

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "automapper-ts",
"version": "1.8.2",
"version": "1.8.3",
"description": "A convention-based object-object mapper in JavaScript, written in TypeScript. Ported from the original C# AutoMapper library at https://github.com/AutoMapper/AutoMapper.",
"keywords": [
"automapper",
Expand Down
2 changes: 1 addition & 1 deletion src/js/AsyncAutoMapper.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/js/AutoMapper.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/js/AutoMapperHelper.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/js/AutoMapperValidator.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/js/naming-conventions/CamelCaseNamingConvention.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions src/ts/AsyncAutoMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ module AutoMapperJs {

public createMapForMember(mapping: IMapping, property: ISourceProperty): void {
mapping.async = true;
mapping.mapItemFunction = (m: IMapping, srcObj: any, dstObj: any, cb: IMapCallback) => this.mapItem(m, srcObj, dstObj, cb);
mapping.mapItemFunction = (m: IMapping, srcObj: any, dstObj: any, cb: IMapCallback): void => this.mapItem(m, srcObj, dstObj, cb);
// property.async = true;
// property.conversionValuesAndFunctions.push(func);
}

public createMapConvertUsing(mapping: IMapping, converterFunction: (ctx: IResolutionContext, cb: IMapCallback) => void): void {
mapping.async = true;
mapping.typeConverterFunction = converterFunction;
mapping.mapItemFunction = (m: IMapping, srcObj: any, dstObj: any, cb: IMapCallback) => this.mapItemUsingTypeConverter(m, srcObj, dstObj, cb);
mapping.mapItemFunction = (m: IMapping, srcObj: any, dstObj: any, cb: IMapCallback): void => this.mapItemUsingTypeConverter(m, srcObj, dstObj, cb);
}

public map(m: { [key: string]: IMapping }, srcKey: string | (new () => any)): (dstKey: string | (new () => any), srcObj: any, cb: IMapCallback) => void;
Expand All @@ -55,11 +55,11 @@ module AutoMapperJs {
return;
// provide performance optimized (preloading) currying support.
case 4:
return (cb: IMapCallback) => this.mapWithMapping(super.getMapping(mappings, sourceKey, destinationKey), sourceObject, cb);
return (cb: IMapCallback): void => this.mapWithMapping(super.getMapping(mappings, sourceKey, destinationKey), sourceObject, cb);
case 3:
return (srcObj: any, cb: IMapCallback) => this.mapWithMapping(super.getMapping(mappings, sourceKey, destinationKey), srcObj, cb);
return (srcObj: any, cb: IMapCallback): void => this.mapWithMapping(super.getMapping(mappings, sourceKey, destinationKey), srcObj, cb);
case 2:
return (dstKey: string | (new () => any), srcObj: any, cb: IMapCallback) => this.map(mappings, sourceKey, dstKey, srcObj, cb);
return (dstKey: string | (new () => any), srcObj: any, cb: IMapCallback): void => this.map(mappings, sourceKey, dstKey, srcObj, cb);
default:
throw new Error('The AsyncAutoMapper.map function expects between 2 and 5 parameters, you provided ' + arguments.length + '.');
}
Expand Down
10 changes: 5 additions & 5 deletions src/ts/AutoMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,14 @@ module AutoMapperJs {

// provide performance optimized (preloading) currying support.
if (arguments.length === 2) {
return (srcObj: any) => this.mapInternal(super.getMapping(this._mappings, sourceKeyOrType, destinationKeyOrType), srcObj);
return (srcObj: any): any => this.mapInternal(super.getMapping(this._mappings, sourceKeyOrType, destinationKeyOrType), srcObj);
}

if (arguments.length === 1) {
return (dstKey: string | (new () => any), srcObj: any) => this.map(sourceKeyOrType, dstKey, srcObj);
return (dstKey: string | (new () => any), srcObj: any): any => this.map(sourceKeyOrType, dstKey, srcObj);
}

return (srcKey: string | (new () => any), dstKey: string | (new () => any), srcObj: any) => this.map(srcKey, dstKey, srcObj);
return (srcKey: string | (new () => any), dstKey: string | (new () => any), srcObj: any): any => this.map(srcKey, dstKey, srcObj);
}

/**
Expand Down Expand Up @@ -167,7 +167,7 @@ module AutoMapperJs {
}

private createMapConvertUsing(mapping: IMapping, tcClassOrFunc: convertUsingClassOrInstanceOrFunction): void {
var configureSynchronousConverterFunction = (converterFunc: any) => {
var configureSynchronousConverterFunction = (converterFunc: any): void => {
if (!converterFunc || AutoMapperHelper.getFunctionParameters(converterFunc.toString()).length !== 1) {
throw new Error('The function provided does not provide exactly one (resolutionContext) parameter.');
}
Expand Down Expand Up @@ -703,7 +703,7 @@ module AutoMapperJs {
}

// Add AutoMapper to the application's global scope. Of course, you could still use Core.AutoMapper.getInstance() as well.
var automapper: AutoMapperJs.AutoMapper = ((app: any) => {
var automapper: AutoMapperJs.AutoMapper = ((app: any): AutoMapperJs.AutoMapper => {
app.automapper = AutoMapperJs.AutoMapper.getInstance();
return app.automapper;
})(this);
1 change: 1 addition & 0 deletions src/ts/AutoMapperHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ module AutoMapperJs {
const argumentNames = /([^\s,]+)/g;

var functionString = functionStr.replace(stripComments, '');

var functionParameterNames = functionString.slice(functionString.indexOf('(') + 1, functionString.indexOf(')')).match(argumentNames);
if (functionParameterNames === null) {
functionParameterNames = new Array<string>();
Expand Down
2 changes: 1 addition & 1 deletion src/ts/AutoMapperValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ module AutoMapperJs {
throw new Error(`Mapping '${mappingKey}' cannot be validated, since mapping.sourceType or mapping.destinationType are unspecified.`);
}

var tryHandle = (errorMessage: string) => {
var tryHandle = (errorMessage: string): void => {
if (errorMessage) {
throw new Error(`Mapping '${mappingKey}' is invalid: ${errorMessage} (source: '${sourceClassName}', destination: '${destinationClassName}').`);
}
Expand Down
2 changes: 1 addition & 1 deletion src/ts/naming-conventions/CamelCaseNamingConvention.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module AutoMapperJs {

public transformPropertyName(sourcePropertyNameParts: string[]): string {
// Transform the splitted parts.
var result: string = '';
var result = '';

for (var index = 0, length = sourcePropertyNameParts.length; index < length; index++) {
if (index === 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/ts/naming-conventions/PascalCaseNamingConvention.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module AutoMapperJs {

public transformPropertyName(sourcePropertyNameParts: string[]): string {
// Transform the splitted parts.
var result: string = '';
var result = '';

for (var index = 0, length = sourcePropertyNameParts.length; index < length; index++) {
result += sourcePropertyNameParts[index].charAt(0).toUpperCase() +
Expand Down
9 changes: 9 additions & 0 deletions test/tests/js/automapper-assertconfig-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ var AutoMapperJs;
// act and assert
automapper.assertConfigurationIsValid();
});
// // TODO Should work!
// it('should set strictMode to \'true\' when no value is provided and validate (with valid mappings)', () => {
// // arrange
// automapper
// .createMap(AssertConfigPropertiesProp, AssertConfigPropertiesProp2)
// .forMember('prop2', (opts: AutoMapperJs.IMemberConfigurationOptions) => opts.mapFrom('prop'));
// // act and assert
// automapper.assertConfigurationIsValid();
// });
// it('should set strictMode to \'true\' when no value is provided and validate (with valid nested mappings)', () => {
// // arrange
// automapper.createMap(AssertConfigPropertiesNestedProp, AssertConfigPropertiesProp)
Expand Down
15 changes: 12 additions & 3 deletions test/tests/js/automapper-createmap-formember-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ var AutoMapperJs;
// assert
var properties = TestHelper.assertAndGetProperty(fromKey, toKey);
expect(properties.length).toBe(1);
var destination = TestHelper.createDestinationProperty('prop', 'prop', 'prop', null, [{ transformationType: 2, memberConfigurationOptionsFunc: ignoreFunc }], true, false);
var destination = TestHelper.createDestinationProperty('prop', 'prop', 'prop', null, [{
transformationType: 2,
memberConfigurationOptionsFunc: ignoreFunc
}], true, false);
var source = TestHelper.createSourceProperty('prop', 'prop', 'prop', null, destination);
expect(properties[0]).toEqualData(source);
});
Expand Down Expand Up @@ -75,9 +78,15 @@ var AutoMapperJs;
// assert
var properties = TestHelper.assertAndGetProperty(fromKey, toKey);
expect(properties.length).toBe(2);
var destination1 = TestHelper.createDestinationProperty('prop1', 'prop2', 'prop1', null, [{ transformationType: 2, memberConfigurationOptionsFunc: mapFromFunc }], false, false);
var destination1 = TestHelper.createDestinationProperty('prop1', 'prop2', 'prop1', null, [{
transformationType: 2,
memberConfigurationOptionsFunc: mapFromFunc
}], false, false);
var source1 = TestHelper.createSourceProperty('prop2', 'prop2', 'prop1', null, destination1);
var destination2 = TestHelper.createDestinationProperty('prop2', 'prop2', 'prop2', null, [{ transformationType: 2, memberConfigurationOptionsFunc: ignoreFunc }], true, false);
var destination2 = TestHelper.createDestinationProperty('prop2', 'prop2', 'prop2', null, [{
transformationType: 2,
memberConfigurationOptionsFunc: ignoreFunc
}], true, false);
var source2 = TestHelper.createSourceProperty('prop2', 'prop2', 'prop2', null, destination2);
expect(properties[0]).toEqualData(source1);
expect(properties[1]).toEqualData(source2);
Expand Down
Loading

0 comments on commit 8b3a230

Please sign in to comment.