Stricter linting rules

Parameter and return types are required now
This commit is contained in:
FinnStutzenstein 2018-09-07 13:12:59 +02:00
parent 0abd36b75c
commit 9bb44f13bd
32 changed files with 85 additions and 84 deletions

View File

@ -25,7 +25,7 @@ export class AppComponent {
* the bootstrapped module.
* @param moduleRef Reference to the bootstrapped AppModule
*/
public static bootstrapDone(moduleRef: NgModuleRef<AppModule>) {
public static bootstrapDone(moduleRef: NgModuleRef<AppModule>): void {
AppComponent.bootstrapDoneSubject.next(moduleRef);
}

View File

@ -18,7 +18,7 @@ import { LoginModule } from './site/login/login.module';
* For the translation module. Loads a Custom 'translation loader' and provides it as loader.
* @param http Just the HttpClient to load stuff
*/
export function HttpLoaderFactory(http: HttpClient) {
export function HttpLoaderFactory(http: HttpClient): PruningTranslationLoader {
return new PruningTranslationLoader(http);
}
/**

View File

@ -37,7 +37,7 @@ export class PruningTranslationLoader implements TranslateLoader {
* Falls back to the default language or simply copy the content of the key.
* @param any the content of any language file.
*/
private process(object: any) {
private process(object: any): any {
const newObject = {};
for (const key in object) {
if (object.hasOwnProperty(key)) {

View File

@ -37,7 +37,7 @@ export class AutoupdateService extends OpenSlidesComponent {
*
* Saves models in DataStore.
*/
public storeResponse(socketResponse): void {
public storeResponse(socketResponse: any): void {
// Reorganize the autoupdate: groupy by action, then by collection. The final
// entries are the single autoupdate objects.
const autoupdate = {
@ -76,7 +76,7 @@ export class AutoupdateService extends OpenSlidesComponent {
*
* TODO: Wait for changeIds to be implemented on the server.
*/
public requestChanges() {
public requestChanges(): void {
console.log('requesting changed objects');
// this.websocketService.send('changeIdRequest', this.DS.maxChangeId);
}

View File

@ -15,7 +15,7 @@ export class CollectionStringModelMapperService {
* @param collectionString
* @param type
*/
public static registerCollectionElement(collectionString: string, type: ModelConstructor<BaseModel>) {
public static registerCollectionElement(collectionString: string, type: ModelConstructor<BaseModel>): void {
CollectionStringModelMapperService.collectionStringsTypeMapping[collectionString] = type;
}

View File

@ -305,17 +305,9 @@ export class DataStoreService {
*
* @param Type The desired BaseModel type to be read from the dataStore
* @param ...ids An or multiple IDs or a list of IDs of BaseModels. use spread operator ("...") for arrays
* @example this.DS.remove(User, myUser.id, 3, 4)
* @example this.DS.remove('users/user', myUser.id, 3, 4)
*/
public remove(collectionType, ...ids: number[]): void {
let collectionString: string;
if (typeof collectionType === 'string') {
collectionString = collectionType;
} else {
const tempObject = new collectionType();
collectionString = tempObject.collectionString;
}
public remove(collectionString: string, ...ids: number[]): void {
const maxChangeId = 0;
ids.forEach(id => {
if (this.modelStore[collectionString]) {
@ -338,7 +330,7 @@ export class DataStoreService {
* Updates the cache by inserting the serialized DataStore. Also changes the chageId, if it's larger
* @param maxChangeId
*/
private storeToCache(maxChangeId: number) {
private storeToCache(maxChangeId: number): void {
this.cacheService.set(DataStoreService.cachePrefix + 'DS', this.JsonStore);
if (maxChangeId > this._maxChangeId) {
this._maxChangeId = maxChangeId;

View File

@ -84,7 +84,7 @@ export class OpenSlidesService extends OpenSlidesComponent {
/**
* Init DS from cache and after this start the websocket service.
*/
private setupDataStoreAndWebSocket() {
private setupDataStoreAndWebSocket(): void {
this.DS.initFromCache().then((changeId: number) => {
this.websocketService.connect(
false,

View File

@ -69,7 +69,7 @@ export class OperatorService extends OpenSlidesComponent {
/**
* The subject that can be observed by other instances using observing functions.
*/
private operatorSubject: BehaviorSubject<any> = new BehaviorSubject<any>(null);
private operatorSubject: BehaviorSubject<User> = new BehaviorSubject<User>(null);
/**
* @param http HttpClient
@ -82,7 +82,7 @@ export class OperatorService extends OpenSlidesComponent {
* Setup the subscription of the DataStore.Update the user and it's
* permissions if the user or groups changes.
*/
public setupSubscription() {
public setupSubscription(): void {
this.DS.changeObservable.subscribe(newModel => {
if (this._user) {
if (newModel instanceof Group) {
@ -120,7 +120,7 @@ export class OperatorService extends OpenSlidesComponent {
* Services an components can use it to get informed when something changes in
* the operator
*/
public getObservable() {
public getObservable(): Observable<User> {
return this.operatorSubject.asObservable();
}

View File

@ -40,7 +40,7 @@ export class ViewportService {
* Needs to be called (exactly) once.
* Will observe breakpoints and updates the _isMobile variable
*/
public checkForChange() {
public checkForChange(): void {
this.breakpointObserver
.observe([Breakpoints.Small, Breakpoints.HandsetPortrait])
.subscribe((state: BreakpointState) => {
@ -52,7 +52,7 @@ export class ViewportService {
});
}
public get isMobile() {
public get isMobile(): boolean {
return this._isMobile;
}
}

View File

@ -83,7 +83,7 @@ export class WebsocketService {
*
* Uses NgZone to let all callbacks run in the angular context.
*/
public connect(retry = false, changeId?: number): void {
public connect(retry: boolean = false, changeId?: number): void {
if (this.websocket) {
return;
}

View File

@ -54,7 +54,7 @@ export abstract class OpenSlidesComponent {
* TODO: could have more features
* @return an observable error
*/
public handleError<T>() {
public handleError<T>(): (error: any) => Observable<T> {
return (error: any): Observable<T> => {
console.error(error);
return of(error);

View File

@ -8,5 +8,5 @@ import { Component, OnInit } from '@angular/core';
export class ProjectorContainerComponent implements OnInit {
public constructor() {}
public ngOnInit() {}
public ngOnInit(): void {}
}

View File

@ -12,7 +12,7 @@ export class ProjectorComponent extends BaseComponent implements OnInit {
super(titleService);
}
public ngOnInit() {
public ngOnInit(): void {
super.setTitle('Projector');
}
}

View File

@ -25,5 +25,5 @@ export class FooterComponent implements OnInit {
/**
* empty onInit
*/
public ngOnInit() {}
public ngOnInit(): void {}
}

View File

@ -86,20 +86,20 @@ export class HeadBarComponent implements OnInit {
/**
* empty onInit
*/
public ngOnInit() {}
public ngOnInit(): void {}
/**
* Emits a signal to the parent if an item in the menu was clicked.
* @param item
*/
public clickMenu(item: any) {
public clickMenu(item: any): void {
this.ellipsisMenuItem.emit(item);
}
/**
* Emits a signal to the parent if
*/
public clickPlusButton() {
public clickPlusButton(): void {
this.plusButtonClicked.emit(true);
}
}

View File

@ -51,7 +51,7 @@ export class PermsDirective extends OpenSlidesComponent {
* The value defines the requires permissions as an array or a single permission.
*/
@Input()
public set osPerms(value) {
public set osPerms(value: string | string[]) {
if (!value) {
value = [];
} else if (typeof value === 'string') {

View File

@ -15,7 +15,7 @@ export abstract class BaseModel extends OpenSlidesComponent implements Deseriali
* @param collectionString
* @param type
*/
public static registerCollectionElement(collectionString: string, type: any) {
public static registerCollectionElement(collectionString: string, type: any): void {
CollectionStringModelMapperService.registerCollectionElement(collectionString, type);
}

View File

@ -67,14 +67,14 @@ export class Motion extends BaseModel {
/**
* update the values of the motion with new values
*/
public patchValues(update: object) {
public patchValues(update: object): void {
Object.assign(this, update);
}
/**
* sets the and the workflow from either dataStore or WebSocket
*/
public initDataStoreValues() {
public initDataStoreValues(): void {
// check the containing Workflows in DataStore
const allWorkflows = this.DS.getAll(Workflow);
allWorkflows.forEach(localWorkflow => {
@ -97,7 +97,7 @@ export class Motion extends BaseModel {
* add a new motionSubmitter from user-object
* @param user the user
*/
public addSubmitter(user: User) {
public addSubmitter(user: User): void {
const newSubmitter = new MotionSubmitter();
newSubmitter.user_id = user.id;
this.submitters.push(newSubmitter);
@ -107,7 +107,7 @@ export class Motion extends BaseModel {
/**
* return the submitters as uses objects
*/
public get submitterAsUser() {
public get submitterAsUser(): User[] {
const submitterIds: number[] = this.submitters
.sort((a: MotionSubmitter, b: MotionSubmitter) => {
return a.weight - b.weight;
@ -133,11 +133,11 @@ export class Motion extends BaseModel {
/**
* return the workflow state
*/
public get state(): any {
public get state(): WorkflowState {
if (this.workflow) {
return this.workflow.state_by_id(this.state_id);
} else {
return '';
return null;
}
}
@ -157,29 +157,29 @@ export class Motion extends BaseModel {
*
* TODO: Motion workflow needs to be specific on the server
*/
public get recommendation(): any {
public get recommendation(): WorkflowState {
if (this.recommendation_id && this.workflow && this.workflow.id) {
const state = this.workflow.state_by_id(this.recommendation_id);
return state;
} else {
return '';
return null;
}
}
/**
* returns the value of 'config.motions_recommendations_by'
*/
public get recomBy() {
public get recomBy(): string {
const motionsRecommendationsByConfig = this.DS.filter<Config>(
Config,
config => config.key === 'motions_recommendations_by'
)[0] as Config;
if (motionsRecommendationsByConfig) {
const recomByString = motionsRecommendationsByConfig.value;
const recomByString: string = motionsRecommendationsByConfig.value as string;
return recomByString;
} else {
return null;
return '';
}
}

View File

@ -19,7 +19,7 @@ export class Group extends BaseModel {
}
}
public get users() {
public get users(): User[] {
// We have to use the string version to avoid circular dependencies.
return this.DS.filter<User>('users/user', user => {
return user.groups_id.includes(this.id);

View File

@ -29,7 +29,7 @@ export class AgendaListComponent extends BaseComponent implements OnInit {
* Init function.
* Sets the title
*/
public ngOnInit() {
public ngOnInit(): void {
super.setTitle('Agenda');
// tslint:disable-next-line
const i: Item = new Item(); // Needed, that the Item.ts is loaded. Can be removed, if something else creates/uses items.
@ -41,7 +41,7 @@ export class AgendaListComponent extends BaseComponent implements OnInit {
* Handler for the plus button.
* Comes from the HeadBar Component
*/
public onPlusButton() {
public onPlusButton(): void {
console.log('create new motion');
}
}

View File

@ -39,14 +39,14 @@ export class AssignmentListComponent extends BaseComponent implements OnInit {
/**
* Click on the plus button delegated from head-bar
*/
public onPlusButton() {
public onPlusButton(): void {
console.log('create new assignments');
}
/**
* Init function. Sets the title.
*/
public ngOnInit() {
public ngOnInit(): void {
super.setTitle('Assignments');
// tslint:disable-next-line
@ -66,7 +66,7 @@ export class AssignmentListComponent extends BaseComponent implements OnInit {
*
* @param event clicked entry from ellipsis menu
*/
public onEllipsisItem(event: any) {
public onEllipsisItem(event: any): void {
if (event.action) {
this[event.action]();
}

View File

@ -12,7 +12,7 @@ export class LegalNoticeComponent implements OnInit {
public constructor(private configService: ConfigService, private translate: TranslateService) {}
public ngOnInit() {
public ngOnInit(): void {
this.configService.get('general_event_legal_notice').subscribe(value => {
if (value) {
this.legalNotice = this.translate.instant(value);

View File

@ -42,14 +42,14 @@ export class MediafileListComponent extends BaseComponent implements OnInit {
* Init.
* Set the title
*/
public ngOnInit() {
public ngOnInit(): void {
super.setTitle('Files');
}
/**
* Click on the plus button delegated from head-bar
*/
public onPlusButton() {
public onPlusButton(): void {
console.log('clicked plus (mediafile)');
}
@ -59,7 +59,7 @@ export class MediafileListComponent extends BaseComponent implements OnInit {
*
* TODO: Not yet implemented, might not even be required
*/
public deleteAllFiles() {
public deleteAllFiles(): void {
console.log('do download');
}
@ -68,7 +68,7 @@ export class MediafileListComponent extends BaseComponent implements OnInit {
*
* @param event clicked entry from ellipsis menu
*/
public onEllipsisItem(event: any) {
public onEllipsisItem(event: any): void {
if (event.action) {
this[event.action]();
}

View File

@ -51,7 +51,7 @@ export class CategoryListComponent extends BaseComponent implements OnInit {
*
* Sets the title and gets/observes categories from DataStore
*/
public ngOnInit() {
public ngOnInit(): void {
super.setTitle('Category');
this.categoryArray = this.DS.getAll(Category);
this.dataSource = new MatTableDataSource(this.categoryArray);
@ -72,7 +72,7 @@ export class CategoryListComponent extends BaseComponent implements OnInit {
*
* TODO: Not yet implemented
*/
public onPlusButton() {
public onPlusButton(): void {
console.log('Add New Category');
}
}

View File

@ -105,7 +105,7 @@ export class MotionDetailComponent extends BaseComponent implements OnInit {
/**
* Async load the values of the motion in the Form.
*/
public patchForm(formMotion: Motion) {
public patchForm(formMotion: Motion): void {
this.metaInfoForm.patchValue({
category_id: formMotion.category_id,
state_id: formMotion.state_id,
@ -125,7 +125,7 @@ export class MotionDetailComponent extends BaseComponent implements OnInit {
*
* TODO: Build a custom form validator
*/
public createForm() {
public createForm(): void {
this.metaInfoForm = this.formBuilder.group({
identifier: [''],
category_id: [''],
@ -149,7 +149,7 @@ export class MotionDetailComponent extends BaseComponent implements OnInit {
*
* TODO: state is not yet saved. Need a special "put" command
*/
public saveMotion() {
public saveMotion(): void {
const newMotionValues = { ...this.metaInfoForm.value, ...this.contentForm.value };
this.motionCopy.patchValues(newMotionValues);
@ -171,7 +171,7 @@ export class MotionDetailComponent extends BaseComponent implements OnInit {
/**
* Click on the edit button (pen-symbol)
*/
public editMotionButton() {
public editMotionButton(): void {
this.editMotion ? (this.editMotion = false) : (this.editMotion = true);
if (this.editMotion) {
// copy the motion
@ -191,7 +191,7 @@ export class MotionDetailComponent extends BaseComponent implements OnInit {
/**
* Trigger to delete the motion
*/
public deleteMotionButton() {
public deleteMotionButton(): void {
this.dataSend.delete(this.motion).subscribe(answer => {
this.router.navigate(['./motions/']);
});
@ -200,5 +200,5 @@ export class MotionDetailComponent extends BaseComponent implements OnInit {
/**
* Init. Does nothing here.
*/
public ngOnInit() {}
public ngOnInit(): void {}
}

View File

@ -6,6 +6,7 @@ import { TranslateService } from '@ngx-translate/core';
import { Motion } from '../../../shared/models/motions/motion';
import { MatTable, MatPaginator, MatSort, MatTableDataSource } from '@angular/material';
import { Workflow } from '../../../shared/models/motions/workflow';
import { WorkflowState } from '../../../shared/models/motions/workflow-state';
/**
* Component that displays all the motions in a Table using DataSource.
@ -91,7 +92,7 @@ export class MotionListComponent extends BaseComponent implements OnInit {
/**
* Init function
*/
public ngOnInit() {
public ngOnInit(): void {
super.setTitle('Motions');
this.workflowArray = this.DS.getAll(Workflow);
this.motionArray = this.DS.getAll(Motion);
@ -114,7 +115,7 @@ export class MotionListComponent extends BaseComponent implements OnInit {
*
* @param motion The row the user clicked at
*/
public selectMotion(motion) {
public selectMotion(motion: Motion): void {
this.router.navigate(['./' + motion.id], { relativeTo: this.route });
}
@ -123,7 +124,7 @@ export class MotionListComponent extends BaseComponent implements OnInit {
* TODO Needs to be more accessible (Motion workflow needs adjustment on the server)
* @param state the name of the state
*/
public getStateIcon(state) {
public getStateIcon(state: WorkflowState): string {
const stateName = state.name;
if (stateName === 'accepted') {
return 'thumbs-up';
@ -140,21 +141,21 @@ export class MotionListComponent extends BaseComponent implements OnInit {
* Determines if an icon should be shown in the list view
* @param state
*/
public isDisplayIcon(state): boolean {
public isDisplayIcon(state: WorkflowState): boolean {
return state.name === 'accepted' || state.name === 'rejected' || state.name === 'not decided';
}
/**
* Handler for the plus button
*/
public onPlusButton() {
public onPlusButton(): void {
this.router.navigate(['./new'], { relativeTo: this.route });
}
/**
* navigate to 'motion/category'
*/
public toCategories() {
public toCategories(): void {
this.router.navigate(['./category'], { relativeTo: this.route });
}
@ -163,7 +164,7 @@ export class MotionListComponent extends BaseComponent implements OnInit {
*
* TODO: Currently does nothing
*/
public downloadMotions() {
public downloadMotions(): void {
console.log('Download Motions Button');
}
@ -172,7 +173,7 @@ export class MotionListComponent extends BaseComponent implements OnInit {
*
* @param event clicked entry from ellipsis menu
*/
public onEllipsisItem(event: any) {
public onEllipsisItem(event: any): void {
if (event.action) {
this[event.action]();
}

View File

@ -8,5 +8,5 @@ import { Component, OnInit } from '@angular/core';
export class PrivacyPolicyComponent implements OnInit {
public constructor() {}
public ngOnInit() {}
public ngOnInit(): void {}
}

View File

@ -26,7 +26,7 @@ export class SettingsListComponent extends BaseComponent implements OnInit {
/**
* Init function. Sets the title
*/
public ngOnInit() {
public ngOnInit(): void {
super.setTitle('Settings');
}
}

View File

@ -64,7 +64,7 @@ export class SiteComponent extends BaseComponent implements OnInit {
/**
* Initialize the site component
*/
public ngOnInit() {
public ngOnInit(): void {
this.vp.checkForChange();
// get a translation via code: use the translation service
@ -81,7 +81,7 @@ export class SiteComponent extends BaseComponent implements OnInit {
/**
* Closes the sidenav in mobile view
*/
public toggleSideNav() {
public toggleSideNav(): void {
if (this.vp.isMobile) {
this.sideNav.toggle();
}
@ -109,15 +109,15 @@ export class SiteComponent extends BaseComponent implements OnInit {
}
// TODO: Implement this
public editProfile() {}
public editProfile(): void {}
// TODO: Implement this
public changePassword() {}
public changePassword(): void {}
/**
* Function to log out the current user
*/
public logout() {
public logout(): void {
this.authService.logout();
}
}

View File

@ -37,7 +37,7 @@ export class StartComponent extends BaseComponent implements OnInit {
* And observes DataStore for changes
* Set title and observe DataStore for changes.
*/
public ngOnInit() {
public ngOnInit(): void {
// required dummy translation, cause translations for config values were never set
// tslint:disable-next-line
const welcomeTitleTranslateDummy = this.translate.instant('Welcome to OpenSlides');
@ -77,7 +77,7 @@ export class StartComponent extends BaseComponent implements OnInit {
/**
* test data store
*/
public DataStoreTest() {
public DataStoreTest(): void {
console.log('add a user to dataStore');
this.DS.add(new User({ id: 100 }));
console.log('add three users to dataStore');
@ -107,14 +107,14 @@ export class StartComponent extends BaseComponent implements OnInit {
/**
* function to print datastore
*/
public giveDataStore() {
public giveDataStore(): void {
this.DS.printWhole();
}
/**
* test translations in component
*/
public TranslateTest() {
public TranslateTest(): void {
console.log('lets translate the word "motion" in the current in the current lang');
console.log('Motions in ' + this.translate.currentLang + ' is ' + this.translate.instant('Motions'));
}

View File

@ -26,7 +26,7 @@ export class UserListComponent extends BaseComponent implements OnInit {
/**
* Init function, sets the title
*/
public ngOnInit() {
public ngOnInit(): void {
super.setTitle('Users');
}
}

View File

@ -15,6 +15,14 @@
"order": ["static-field", "static-method", "instance-field", "constructor", "instance-method"]
}
],
"no-unused-variable": true
"no-unused-variable": true,
"typedef": [
true,
"call-signature",
"property-declaration",
"parameter",
"object-destructuring",
"array-destructuring"
]
}
}