Skip to content

Commit

Permalink
turn on no non null assertion and fix errors caused by this
Browse files Browse the repository at this point in the history
  • Loading branch information
nevio18324 committed Dec 19, 2024
1 parent e1b6a5d commit 9a54b65
Show file tree
Hide file tree
Showing 12 changed files with 147 additions and 103 deletions.
12 changes: 8 additions & 4 deletions frontend/cypress/support/commands.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { validateScoring } from "./helper/scoringSupport";
import { keyCodeDefinitions } from "cypress-real-events/keyCodeDefinitions";
import { pressUntilContains, doUntilSelector } from "./helper/utils";
import { doUntilSelector, pressUntilContains } from "./helper/utils";
import Chainable = Cypress.Chainable;

Cypress.Commands.add("loginAsUser",
Expand Down Expand Up @@ -84,8 +84,12 @@ function loginWithCredentials (username: string, password: string) {
"**/users/current")
.as("getCurrentUser");
cy.origin(Cypress.env("login_url"),
{ args: { username,
password } },
{
args: {
username,
password
}
},
({ username, password }) => {
cy.get("input[name=\"username\"]")
.type(username);
Expand All @@ -99,7 +103,7 @@ function loginWithCredentials (username: string, password: string) {
cy.url()
.then((url) => {
const currentUrl = new URL(url);
const baseURL = new URL(Cypress.config().baseUrl!);
const baseURL = new URL(Cypress.config().baseUrl ?? "");
expect(currentUrl.pathname)
.equal(baseURL.pathname);
});
Expand Down
38 changes: 24 additions & 14 deletions frontend/cypress/support/helper/scoringSupport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,14 @@ function validateScoringWidth (zone: string, percent: number, isOverview: boolea
.invoke("width")
.then((parentWidth) => {
expect(parentWidth).not.to.equal(undefined);
cy.getZone(zone,
isOverview)
.invoke("width")
.should("be.within",
parentWidth! * (percent / 100) - 3,
parentWidth! * (percent / 100) + 3);
if (parentWidth) {
cy.getZone(zone,
isOverview)
.invoke("width")
.should("be.within",
parentWidth * (percent / 100) - 3,
parentWidth * (percent / 100) + 3);
}
});
}

Expand Down Expand Up @@ -121,22 +123,30 @@ function colorFromPercentage (percentage: number) {

function scoringValueFromPercentage (percentage: number): ScoringValue {
if (percentage >= 100) {
return { failPercent: 0,
return {
failPercent: 0,
commitPercent: 0,
targetPercent: 0 };
targetPercent: 0
};
} else if (percentage > 70) {
const targetPercent = (percentage - 70) * (100 / 30);
return { failPercent: 100,
return {
failPercent: 100,
commitPercent: 100,
targetPercent: targetPercent };
targetPercent: targetPercent
};
} else if (percentage > 30) {
const commitPercent = (percentage - 30) * (100 / 40);
return { failPercent: 100,
return {
failPercent: 100,
commitPercent: commitPercent,
targetPercent: -1 };
targetPercent: -1
};
}
const failPercent = percentage * (100 / 30);
return { failPercent: failPercent,
return {
failPercent: failPercent,
commitPercent: -1,
targetPercent: -1 };
targetPercent: -1
};
}
18 changes: 11 additions & 7 deletions frontend/eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,31 @@ export default tsEslint.config(
processor: angular.processInlineTemplates,
languageOptions: {
globals: {
//Cypress Undefined
//Cypress things not recognized by eslint
cy: 'readonly',
Cypress: 'readonly',
it: 'readonly',
describe: 'readonly',
expect: 'readonly',
beforeEach: 'readonly',
before: 'readonly',
//Dom undefined
//Dom things not recognized by eslint
localStorage: 'readonly',
console: 'readonly',
window: 'readonly',
document: 'readonly',
//Event undefined
//Event not recognized by eslint
MouseEvent: 'readonly',
KeyboardEvent: 'readonly',
Event: 'readonly',
//HTML Elements undefined
//HTML Elements not recognized by eslint
HTMLDivElement: 'readonly',
HTMLInputElement: 'readonly',
HTMLSpanElement: 'readonly',
HTMLElement: 'readonly',
//Other undefined
HTMLTitleElement: 'readonly',
HTMLHtmlElement: 'readonly',
//Others not recognized by eslint
ResizeObserver: 'readonly',
ResizeObserverEntry: 'readonly',
setTimeout: 'readonly',
Expand Down Expand Up @@ -76,11 +78,11 @@ export default tsEslint.config(
],
'prefer-rest-params': 'error',
'@typescript-eslint/no-empty-function': ['error', { allow: ['arrowFunctions', 'constructors'] }],
'@stylistic/lines-around-comment': ['error'],
'@stylistic/lines-around-comment': 'off',
'@angular-eslint/no-empty-lifecycle-method': 'error',
'@angular-eslint/component-class-suffix': 'error',
'@typescript-eslint/no-non-null-asserted-optional-chain': 'error',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-non-null-assertion': 'error',
'@stylistic/no-extra-parens': 'off',
'@typescript-eslint/no-confusing-non-null-assertion': 'off',
//Delete these rules after fixing all the issues and enabling the actual rules
Expand Down Expand Up @@ -124,10 +126,12 @@ export default tsEslint.config(
files: ['**/*.spec.ts'],
extends: [...tsEslint.configs.recommended],
rules: {
//Rules removed for Test files because they are unnecessary for tests
'@typescript-eslint/no-explicit-any': 'off',
'prefer-rest-params': 'off',
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
},
},

Expand Down
37 changes: 21 additions & 16 deletions frontend/src/app/components/action-plan/action-plan.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ export class ActionPlanComponent {
listItems!: QueryList<ElementRef>;

constructor (private actionService: ActionService,
public dialogService: DialogService) {}
public dialogService: DialogService) {
}

handleKeyDown (event: Event, currentIndex: number) {
let newIndex = currentIndex;
if ((event as KeyboardEvent).key === "ArrowDown") {
if (newIndex + 1 <= this.control.getValue()!.length - 1) {
if (newIndex + 1 <= (this.control.getValue() ?? []).length - 1) {
newIndex += 1;
}
} else if ((event as KeyboardEvent).key === "ArrowUp") {
Expand All @@ -42,7 +43,7 @@ export class ActionPlanComponent {

changeItemPosition (newIndex: number, currentIndex: number) {
this.activeItem = newIndex;
const currentActionPlan: Action[] = this.control.getValue()!;
const currentActionPlan: Action[] = this.control.getValue() ?? [];
this.updateActionTexts(currentActionPlan);
moveItemInArray(currentActionPlan,
currentIndex,
Expand All @@ -58,7 +59,7 @@ export class ActionPlanComponent {
}

increaseActiveItemWithTab () {
if (this.activeItem <= this.control.value!.length - 2) {
if (this.activeItem <= (this.control.value ?? []).length - 2) {
this.activeItem++;
}
}
Expand All @@ -71,20 +72,22 @@ export class ActionPlanComponent {

drop (event: CdkDragDrop<Action[] | null>) {
const value: string = (event.container.element.nativeElement.children[event.previousIndex].children[1] as HTMLInputElement).value;
const actions: Action[] = this.control.getValue()!;
const actions: Action[] = this.control.getValue() ?? [];
if (actions[event.previousIndex].action == "" && value != "") {
actions[event.previousIndex] = { ...actions[event.previousIndex],
action: value };
actions[event.previousIndex] = {
...actions[event.previousIndex],
action: value
};
this.control.next(actions);
}
if (event.previousContainer === event.container) {
moveItemInArray(event.container.data!,
moveItemInArray(event.container.data ?? [],
event.previousIndex,
event.currentIndex);
} else {
transferArrayItem(
event.previousContainer.data!,
event.container.data!,
event.previousContainer.data ?? [],
event.container.data ?? [],
event.previousIndex,
event.currentIndex
);
Expand All @@ -94,15 +97,15 @@ export class ActionPlanComponent {
}

adjustPriorities () {
const actions: Action[] = this.control.getValue()!;
const actions: Action[] = this.control.getValue() ?? [];
actions.forEach(function (action: Action, index: number) {
action.priority = index;
});
this.control.next(actions);
}

removeAction (index: number) {
const actions: Action[] = this.control.getValue()!;
const actions: Action[] = this.control.getValue() ?? [];
if (this.activeItem == index && this.activeItem > 0) {
this.activeItem--;
}
Expand All @@ -113,7 +116,7 @@ export class ActionPlanComponent {
.subscribe((result) => {
if (result) {
if (actions[index].id) {
this.actionService.deleteAction(actions[index].id!)
this.actionService.deleteAction(actions[index].id)
.subscribe();
}
actions.splice(index,
Expand All @@ -131,10 +134,12 @@ export class ActionPlanComponent {
}

addNewAction () {
const actions: Action[] = this.control.getValue()!;
actions.push({ action: "",
const actions: Action[] = this.control.getValue() ?? [];
actions.push({
action: "",
priority: actions.length,
keyResultId: this.keyResultId } as Action);
keyResultId: this.keyResultId
} as Action);
this.control.next(actions);
this.activeItem = actions.length - 1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export class CheckInFormComponent implements OnInit {

this.checkInService.saveCheckIn(checkIn)
.subscribe(() => {
this.actionService.updateActions(this.dialogForm.value.actionList!)
this.actionService.updateActions(this.dialogForm.value.actionList ?? [])
.subscribe(() => {
this.dialogRef.close();
});
Expand All @@ -124,9 +124,9 @@ export class CheckInFormComponent implements OnInit {

getCheckInValue (): string {
if ((this.checkIn as CheckInMetricMin).value != null) {
return (this.checkIn as CheckInMetricMin).value!.toString();
return (this.checkIn as CheckInMetricMin).value?.toString() ?? "";
} else {
return (this.checkIn as CheckInOrdinalMin).zone!;
return (this.checkIn as CheckInOrdinalMin).zone ?? "";
}
}

Expand All @@ -143,9 +143,11 @@ export class CheckInFormComponent implements OnInit {
}

changeIsChecked (event: any, index: number) {
const actions = this.dialogForm.value.actionList!;
actions[index] = { ...actions[index],
isChecked: event.checked };
const actions = this.dialogForm.value.actionList ?? [];
actions[index] = {
...actions[index],
isChecked: event.checked
};
this.dialogForm.patchValue({ actionList: actions });
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,15 @@ export class KeyresultDialogComponent {
});

constructor (
@Inject(MAT_DIALOG_DATA) public data: { objective: Objective;
keyResult: KeyResult; },
@Inject(MAT_DIALOG_DATA) public data: {
objective: Objective;
keyResult: KeyResult;
},
private keyResultService: KeyresultService,
public dialogService: DialogService,
public dialogRef: MatDialogRef<KeyresultDialogComponent>
) {}
) {
}

isMetricKeyResult () {
return this.keyResultForm.controls["keyResultType"].value === "metric";
Expand All @@ -52,14 +55,18 @@ export class KeyresultDialogComponent {
saveKeyResult (openNewDialog = false) {
const value = this.keyResultForm.value;
const keyResult = this.isMetricKeyResult()
? ({ ...value,
objective: this.data.objective } as KeyResultMetricDTO)
: ({ ...value,
? ({
...value,
objective: this.data.objective
} as KeyResultMetricDTO)
: ({
...value,
objective: this.data.objective,
id: this.data.keyResult?.id } as KeyResultOrdinalDTO);
id: this.data.keyResult?.id
} as KeyResultOrdinalDTO);
keyResult.id = this.data.keyResult?.id;
keyResult.version = this.data.keyResult?.version;
keyResult.actionList = keyResult.actionList!.filter((action: Action) => action.action !== "");
keyResult.actionList = (keyResult.actionList ?? []).filter((action: Action) => action.action !== "");
this.keyResultService.saveKeyResult(keyResult)
.subscribe((returnValue) => {
this.dialogRef.close({
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/app/services/customization.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class CustomizationService {
return;
}

this.document.querySelector("title")!.innerHTML = title;
(this.document.querySelector("title") as HTMLTitleElement).innerHTML = title;
}

private setStyleCustomizations (customStylesMap: CustomStyles) {
Expand All @@ -76,7 +76,7 @@ export class CustomizationService {
return;
}

const styles = this.document.querySelector("html")!.style;
const styles = (this.document.querySelector("html") as HTMLHtmlElement).style;
if (!styles) {
return;
}
Expand All @@ -94,7 +94,7 @@ export class CustomizationService {
return;
}

const styles = this.document.querySelector("html")!.style;
const styles = (this.document.querySelector("html") as HTMLHtmlElement).style;
if (!styles) {
return;
}
Expand Down
Loading

0 comments on commit 9a54b65

Please sign in to comment.