refactor: apply stricter ts-lint rules

This commit is contained in:
Michel Jonathan Schmitz
2019-07-15 13:14:20 +02:00
parent fee004c79f
commit 355da9e8c4
7 changed files with 23 additions and 17 deletions

View File

@@ -17,10 +17,11 @@ import * as commander from 'commander';
import {readFileSync} from 'fs'; import {readFileSync} from 'fs';
import {join} from 'path'; import {join} from 'path';
import {executeConnector, isValidSCNamespace} from './common'; import {executeConnector, isValidSCNamespace} from './common';
import {MinimalConnector} from './MinimalConnector'; import {MinimalConnector} from './minimal-connector';
const connectorVersion = JSON.parse( const connectorVersion = JSON.parse(
readFileSync(join(__dirname, '..', 'package.json')).toString(), readFileSync(join(__dirname, '..', 'package.json'))
.toString(),
).version; ).version;
process.on('unhandledRejection', (error) => { process.on('unhandledRejection', (error) => {

View File

@@ -12,14 +12,14 @@
* You should have received a copy of the GNU General Public License along with * You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>. * this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
import {ConnectorClient} from '@openstapps/api/lib/connectorClient'; import {ConnectorClient} from '@openstapps/api/lib/connector-client';
import {HttpClient} from '@openstapps/api/lib/httpClient'; import {HttpClient} from '@openstapps/api/lib/http-client';
import { import {
SCLicensePlate, SCLicensePlate,
SCNamespaces, SCNamespaces,
SCThings, SCThings,
} from '@openstapps/core'; } from '@openstapps/core';
import {Connector} from './Connector'; import {Connector} from './connector';
/** /**
* Checks if the input is a valid SCNamespace * Checks if the input is a valid SCNamespace
@@ -27,7 +27,8 @@ import {Connector} from './Connector';
* @param input Name of the potential SCNamespace * @param input Name of the potential SCNamespace
*/ */
export function isValidSCNamespace(input: string): input is SCLicensePlate { export function isValidSCNamespace(input: string): input is SCLicensePlate {
return Object.keys(SCNamespaces).indexOf(input) > 0; return Object.keys(SCNamespaces)
.indexOf(input) > 0;
} }
/** /**
@@ -38,7 +39,7 @@ export function isValidSCNamespace(input: string): input is SCLicensePlate {
* @param itemIdentifier Identifying representation of the item * @param itemIdentifier Identifying representation of the item
* @param licensePlate License plate of the school * @param licensePlate License plate of the school
*/ */
export function createUUID(itemIdentifier: any, licensePlate: SCLicensePlate): string { export function createUUID(itemIdentifier: unknown, licensePlate: SCLicensePlate): string {
return ConnectorClient.makeUUID(JSON.stringify(itemIdentifier), licensePlate); return ConnectorClient.makeUUID(JSON.stringify(itemIdentifier), licensePlate);
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2018, 2019 StApps * Copyright (C) 2019 StApps
* This program is free software: you can redistribute it and/or modify it * This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free * under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3. * Software Foundation, version 3.
@@ -14,14 +14,16 @@
*/ */
import {SCLicensePlate, SCMessage, SCThingRemoteOrigin, SCThingType} from '@openstapps/core'; import {SCLicensePlate, SCMessage, SCThingRemoteOrigin, SCThingType} from '@openstapps/core';
import {createUUID} from './common'; import {createUUID} from './common';
import {Connector} from './Connector'; import {Connector} from './connector';
/** /**
* Example connector * Example connector
*/ */
export class MinimalConnector extends Connector<SCMessage> { export class MinimalConnector extends Connector<SCMessage> {
// for quick access to the type /**
private type: SCThingType.Message = SCThingType.Message; * Type of the things handled in the connector for quick access to the type
*/
private readonly type: SCThingType.Message = SCThingType.Message;
/** /**
* Constructor for the MinimalConnector * Constructor for the MinimalConnector
@@ -40,6 +42,7 @@ export class MinimalConnector extends Connector<SCMessage> {
const customRemoteOrigin = this.createRemoteOrigin(); const customRemoteOrigin = this.createRemoteOrigin();
// may add a maintainer or other attributes here // may add a maintainer or other attributes here
customRemoteOrigin.url = 'http://your.backend.url'; customRemoteOrigin.url = 'http://your.backend.url';
return customRemoteOrigin; return customRemoteOrigin;
} }
@@ -51,7 +54,7 @@ export class MinimalConnector extends Connector<SCMessage> {
{ {
audiences: ['students', 'employees'], audiences: ['students', 'employees'],
description: 'Some description 1', description: 'Some description 1',
message: 'Some message 1', messageBody: 'Some message 1',
name: 'Some name 1', name: 'Some name 1',
origin: this.createCustomRemoteOrigin(), origin: this.createCustomRemoteOrigin(),
type: this.type, type: this.type,
@@ -60,7 +63,7 @@ export class MinimalConnector extends Connector<SCMessage> {
{ {
audiences: ['students', 'employees'], audiences: ['students', 'employees'],
description: 'Some description 2', description: 'Some description 2',
message: 'Some message 2', messageBody: 'Some message 2',
name: 'Some name 2', name: 'Some name 2',
origin: this.createCustomRemoteOrigin(), origin: this.createCustomRemoteOrigin(),
type: this.type, type: this.type,
@@ -69,13 +72,14 @@ export class MinimalConnector extends Connector<SCMessage> {
{ {
audiences: ['students', 'employees'], audiences: ['students', 'employees'],
description: 'Some description 3', description: 'Some description 3',
message: 'Some message 3', messageBody: 'Some message 3',
name: 'Some name 3', name: 'Some name 3',
origin: this.createCustomRemoteOrigin(), origin: this.createCustomRemoteOrigin(),
type: this.type, type: this.type,
uid: createUUID({id: 'message_3'}, this.licensePlate), uid: createUUID({id: 'message_3'}, this.licensePlate),
}, },
]; ];
return importedItems; return importedItems;
} }
} }

View File

@@ -15,7 +15,7 @@
import {SCThingType, SCBulkResponse, SCLicensePlate} from '@openstapps/core'; import {SCThingType, SCBulkResponse, SCLicensePlate} from '@openstapps/core';
import {expect} from 'chai'; import {expect} from 'chai';
import {suite, test} from 'mocha-typescript'; import {suite, test} from 'mocha-typescript';
import {MinimalConnector} from '../src/MinimalConnector'; import {MinimalConnector} from '../src/minimal-connector';
import {createUUID, executeConnector, isValidSCNamespace} from '../src/common'; import {createUUID, executeConnector, isValidSCNamespace} from '../src/common';
import nock = require('nock'); import nock = require('nock');

View File

@@ -15,7 +15,7 @@
import {SCThingOriginType} from '@openstapps/core'; import {SCThingOriginType} from '@openstapps/core';
import {expect} from 'chai'; import {expect} from 'chai';
import {suite, test} from 'mocha-typescript'; import {suite, test} from 'mocha-typescript';
import {MinimalConnector} from '../src/MinimalConnector'; import {MinimalConnector} from '../src/minimal-connector';
@suite @suite
export class ConnectorSpec { export class ConnectorSpec {

View File

@@ -17,7 +17,7 @@ import {Validator} from '@openstapps/core-tools/lib/validate';
import {expect} from 'chai'; import {expect} from 'chai';
import {suite, test} from 'mocha-typescript'; import {suite, test} from 'mocha-typescript';
import {join} from 'path'; import {join} from 'path';
import {MinimalConnector} from '../src/MinimalConnector'; import {MinimalConnector} from '../src/minimal-connector';
@suite @suite
export class MinimalConnectorSpec { export class MinimalConnectorSpec {