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 {join} from 'path';
import {executeConnector, isValidSCNamespace} from './common';
import {MinimalConnector} from './MinimalConnector';
import {MinimalConnector} from './minimal-connector';
const connectorVersion = JSON.parse(
readFileSync(join(__dirname, '..', 'package.json')).toString(),
readFileSync(join(__dirname, '..', 'package.json'))
.toString(),
).version;
process.on('unhandledRejection', (error) => {

View File

@@ -12,14 +12,14 @@
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {ConnectorClient} from '@openstapps/api/lib/connectorClient';
import {HttpClient} from '@openstapps/api/lib/httpClient';
import {ConnectorClient} from '@openstapps/api/lib/connector-client';
import {HttpClient} from '@openstapps/api/lib/http-client';
import {
SCLicensePlate,
SCNamespaces,
SCThings,
} from '@openstapps/core';
import {Connector} from './Connector';
import {Connector} from './connector';
/**
* Checks if the input is a valid SCNamespace
@@ -27,7 +27,8 @@ import {Connector} from './Connector';
* @param input Name of the potential SCNamespace
*/
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 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);
}

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
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
@@ -14,14 +14,16 @@
*/
import {SCLicensePlate, SCMessage, SCThingRemoteOrigin, SCThingType} from '@openstapps/core';
import {createUUID} from './common';
import {Connector} from './Connector';
import {Connector} from './connector';
/**
* Example connector
*/
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
@@ -40,6 +42,7 @@ export class MinimalConnector extends Connector<SCMessage> {
const customRemoteOrigin = this.createRemoteOrigin();
// may add a maintainer or other attributes here
customRemoteOrigin.url = 'http://your.backend.url';
return customRemoteOrigin;
}
@@ -51,7 +54,7 @@ export class MinimalConnector extends Connector<SCMessage> {
{
audiences: ['students', 'employees'],
description: 'Some description 1',
message: 'Some message 1',
messageBody: 'Some message 1',
name: 'Some name 1',
origin: this.createCustomRemoteOrigin(),
type: this.type,
@@ -60,7 +63,7 @@ export class MinimalConnector extends Connector<SCMessage> {
{
audiences: ['students', 'employees'],
description: 'Some description 2',
message: 'Some message 2',
messageBody: 'Some message 2',
name: 'Some name 2',
origin: this.createCustomRemoteOrigin(),
type: this.type,
@@ -69,13 +72,14 @@ export class MinimalConnector extends Connector<SCMessage> {
{
audiences: ['students', 'employees'],
description: 'Some description 3',
message: 'Some message 3',
messageBody: 'Some message 3',
name: 'Some name 3',
origin: this.createCustomRemoteOrigin(),
type: this.type,
uid: createUUID({id: 'message_3'}, this.licensePlate),
},
];
return importedItems;
}
}

View File

@@ -15,7 +15,7 @@
import {SCThingType, SCBulkResponse, SCLicensePlate} from '@openstapps/core';
import {expect} from 'chai';
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 nock = require('nock');

View File

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

View File

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