Sonarcloud issues fixes (#3499)

* Sonarcloud issues fixes

* Code smell fixes

* Refactoring to remove new code duplications

* Sonarcloud code smell fixes part I

* Sonarcloud code smell fixes part II

* Missing code smell fix

* Add new ESLint rules to cover fixed SonarCloud issues

* Add missing command

* Add missing is existing check
This commit is contained in:
MichalKinas
2023-11-03 11:43:06 +01:00
committed by GitHub
parent 968febffb0
commit 69c00fc403
72 changed files with 327 additions and 530 deletions

View File

@@ -130,7 +130,7 @@ export abstract class PageComponent implements OnInit, OnDestroy, OnChanges {
}
ngOnChanges(changes: SimpleChanges) {
if (changes.nodeResult && changes.nodeResult.currentValue) {
if (changes.nodeResult?.currentValue) {
this.nodeResult = changes.nodeResult.currentValue;
}
}
@@ -145,7 +145,7 @@ export abstract class PageComponent implements OnInit, OnDestroy, OnChanges {
}
showPreview(node: NodeEntry, extras?: ViewNodeExtras) {
if (node && node.entry) {
if (node?.entry) {
if (this.fileAutoDownloadService?.shouldFileAutoDownload(node.entry?.content?.sizeInBytes)) {
this.fileAutoDownloadService.autoDownloadFile(node);
} else {

View File

@@ -91,10 +91,6 @@ class DocumentBasePageServiceMock extends DocumentBasePageService {
class TestComponent extends PageComponent {
node: any;
constructor() {
super();
}
addSubscription(entry: Subscription) {
this.subscriptions.push(entry);
}

View File

@@ -74,6 +74,6 @@ export class ToolbarButtonComponent {
}
private hasClickAction(actionRef: ContentActionRef): boolean {
return !!(actionRef && actionRef.actions && actionRef.actions.click);
return !!actionRef?.actions?.click;
}
}

View File

@@ -71,7 +71,7 @@ export class ToolbarMenuItemComponent {
}
private hasClickAction(actionRef: ContentActionRef): boolean {
return !!(actionRef && actionRef.actions && actionRef.actions.click);
return !!actionRef?.actions?.click;
}
trackByActionId(_: number, obj: ContentActionRef): string {

View File

@@ -98,11 +98,9 @@ export class ContextActionsDirective implements OnInit, OnDestroy {
}
private findAncestor(el: Element, className: string): Element {
if (el.classList.contains(className)) {
return el;
while (el && !el.classList.contains(className)) {
el = el.parentElement;
}
// eslint-disable-next-line curly
while ((el = el.parentElement) && !el.classList.contains(className));
return el;
}
}

View File

@@ -180,7 +180,7 @@ export class AppExtensionService implements RuleContext {
this.withCredentials = this.appConfig.get<boolean>('auth.withCredentials', false);
if (config.features && config.features.viewer) {
if (config.features?.viewer) {
this.viewerRules = (config.features.viewer['rules'] as ViewerRules) || {};
}
@@ -340,7 +340,7 @@ export class AppExtensionService implements RuleContext {
private setActionDisabledFromRule(action: ContentActionRef) {
let disabled = false;
if (action && action.rules && action.rules.enabled) {
if (action?.rules?.enabled) {
disabled = !this.extensions.evaluateRule(action.rules.enabled, this);
}
@@ -483,7 +483,7 @@ export class AppExtensionService implements RuleContext {
}
filterVisible(action: ContentActionRef | SettingsGroupRef | SidebarTabRef | DocumentListPresetRef): boolean {
if (action && action.rules && action.rules.visible) {
if (action?.rules?.visible) {
return this.extensions.evaluateRule(action.rules.visible, this);
}
return true;
@@ -495,7 +495,7 @@ export class AppExtensionService implements RuleContext {
return true;
}
if (extension.rules && extension.rules.disabled) {
if (extension.rules?.disabled) {
return this.extensions.evaluateRule(extension.rules.disabled, this);
}
}