Skip to content

Commit

Permalink
turn no-non-null-assertion off and bring back all usages of
Browse files Browse the repository at this point in the history
  • Loading branch information
nevio18324 committed Dec 23, 2024
1 parent d919fca commit 8153e04
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 24 deletions.
3 changes: 2 additions & 1 deletion frontend/eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ export default tsEslint.config(
],
'@typescript-eslint/no-empty-function': ['error', { allow: ['arrowFunctions', 'constructors'] }],
'@typescript-eslint/no-non-null-asserted-optional-chain': 'error',
'@typescript-eslint/no-non-null-assertion': 'error',
//Turn off to allow ! in the code
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-confusing-non-null-assertion': 'error',

//Stylistic eslint rules
Expand Down
18 changes: 9 additions & 9 deletions frontend/src/app/components/action-plan/action-plan.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class ActionPlanComponent {
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 +42,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, newIndex);
currentActionPlan.forEach((action: Action, index: number) => action.priority = index);
Expand All @@ -56,7 +56,7 @@ export class ActionPlanComponent {
}

increaseActiveItemWithTab() {
if (this.activeItem <= (this.control.value ?? []).length - 2) {
if (this.activeItem <= this.control.getValue()!.length - 2) {
this.activeItem++;
}
}
Expand All @@ -69,7 +69,7 @@ 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],
Expand All @@ -78,26 +78,26 @@ export class ActionPlanComponent {
this.control.next(actions);
}
if (event.previousContainer === event.container) {
moveItemInArray(event.container.data ?? [], event.previousIndex, event.currentIndex);
moveItemInArray(event.container.data!, event.previousIndex, event.currentIndex);
} else {
transferArrayItem(
event.previousContainer.data ?? [], event.container.data ?? [], event.previousIndex, event.currentIndex
event.previousContainer.data!, event.container.data!, event.previousIndex, event.currentIndex
);
}
this.adjustPriorities();
this.activeItem = event.currentIndex;
}

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 @@ -124,7 +124,7 @@ export class ActionPlanComponent {
}

addNewAction() {
const actions: Action[] = this.control.getValue() ?? [];
const actions: Action[] = this.control.getValue()!;
actions.push({
action: '',
priority: actions.length,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,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 @@ -120,9 +120,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 @@ -135,11 +135,11 @@ export class CheckInFormComponent implements OnInit {
}

getActions(): Action[] {
return this.dialogForm.controls['actionList'].value || [];
return this.dialogForm.controls['actionList'].value!;
}

changeIsChecked(event: any, index: number) {
const actions = this.dialogForm.value.actionList ?? [];
const actions = this.dialogForm.value.actionList!;
actions[index] = {
...actions[index],
isChecked: event.checked
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ export class KeyresultDialogComponent {
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.version = this.data.keyResult?.version!;

Check failure on line 65 in frontend/src/app/components/keyresult-dialog/keyresult-dialog.component.ts

View workflow job for this annotation

GitHub Actions / frontend

Optional chain expressions can return undefined by design - using a non-null assertion is unsafe and wrong
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 @@ -50,7 +50,7 @@ export class CustomizationService {
return;
}

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

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

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

const styles = (this.document.querySelector('html') as HTMLHtmlElement).style;
const styles = (this.document.querySelector('html') as HTMLHtmlElement)!.style;
if (!styles) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/app/shared/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export function isLastCheckInNegative(baseline: number, stretchGoal: number, val
}

export function calculateCurrentPercentage(keyResultMetric: KeyResultMetricMin): number {
const value: number = +(keyResultMetric.lastCheckIn?.value ?? 0);
const value: number = +keyResultMetric.lastCheckIn?.value!;

Check failure on line 49 in frontend/src/app/shared/common.ts

View workflow job for this annotation

GitHub Actions / frontend

Optional chain expressions can return undefined by design - using a non-null assertion is unsafe and wrong
const baseline: number = +keyResultMetric.baseline;
const stretchGoal: number = +keyResultMetric.stretchGoal;
if (isLastCheckInNegative(baseline, stretchGoal, value)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ describe('ScoringComponent', () => {
component.failPercent = 0;

// Set zone
(component.keyResult.lastCheckIn as CheckInOrdinalMin).zone = object.zoneValue;
(component.keyResult.lastCheckIn as CheckInOrdinalMin)!.zone! = object.zoneValue;

Check failure on line 166 in frontend/src/app/shared/custom/scoring/scoring.component.spec.ts

View workflow job for this annotation

GitHub Actions / frontend

Confusing combination of non-null assertion and assignment like `a! = b`, which looks very similar to `a != b`
component.calculatePercentageOrdinal();

// Verify if percentage was set correctly
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ export class AddEditTeamDialogComponent implements OnInit {
if (this.data) {
const updatedTeam: Team = {
...this.teamForm.value,
id: this.data.team.id,
version: this.data.team.version
id: this.data!.team.id,
version: this.data!.team.version
} as Team;
this.teamService.updateTeam(updatedTeam)
.subscribe((result) => {
Expand Down

0 comments on commit 8153e04

Please sign in to comment.