Skip to content

Commit

Permalink
Add new ESLint rules to cover fixed SonarCloud issues
Browse files Browse the repository at this point in the history
  • Loading branch information
MichalKinas committed Oct 30, 2023
1 parent b66eae8 commit b73a3f6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
12 changes: 9 additions & 3 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@
"@angular-eslint/component-class-suffix": "error",
"@angular-eslint/directive-class-suffix": "error",
"@angular-eslint/no-conflicting-lifecycle": "error",
"@typescript-eslint/no-floating-promises": "off",
"@typescript-eslint/no-floating-promises": "warn",
"@typescript-eslint/no-misused-promises": "warn",
"@typescript-eslint/default-param-last": "warn",
"@angular-eslint/no-input-rename": "error",
"@angular-eslint/no-output-native": "error",
"@angular-eslint/no-output-on-prefix": "error",
Expand All @@ -122,7 +124,7 @@
"@angular-eslint/no-outputs-metadata-property": "error",
"@angular-eslint/use-lifecycle-interface": "error",
"@angular-eslint/use-pipe-transform-interface": "error",
"@typescript-eslint/prefer-optional-chain": "warn",
"@typescript-eslint/prefer-optional-chain": "error",
"@typescript-eslint/no-misused-new": "error",
"@typescript-eslint/no-non-null-assertion": "error",
"@typescript-eslint/prefer-function-type": "error",
Expand Down Expand Up @@ -204,6 +206,7 @@
"newline-per-chained-call": "off",
"prefer-rest-params": "error",
"prefer-spread": "error",
"prefer-promise-reject-errors": "error",
"import/order": "off",
"max-len": [
"error",
Expand All @@ -226,6 +229,8 @@
"no-caller": "error",
"no-global-assign": "error",
"no-cond-assign": "error",
"no-constant-binary-expression": "error",
"no-useless-rename": "error",
"no-console": [
"error",
{
Expand Down Expand Up @@ -324,7 +329,8 @@
{
"files": ["*.spec.ts", "*.test.ts"],
"rules": {
"@typescript-eslint/no-floating-promises": "off",
"@typescript-eslint/no-floating-promises": "warn",
"@typescript-eslint/no-misused-promises": "warn",
"max-lines": "off"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1503,7 +1503,7 @@ describe('ContentManagementService', () => {
}));

it('should raise error when unlock node fails', fakeAsync(() => {
spyOn(contentApi, 'unlockNode').and.callFake(() => new Promise((_resolve, reject) => reject('error')));
spyOn(contentApi, 'unlockNode').and.callFake(() => new Promise((_resolve, reject) => reject(new Error('error'))));
spyOn(store, 'dispatch').and.callThrough();
store.dispatch(new UnlockWriteAction({ entry: { id: 'node-id', name: 'some-file' } }));
tick();
Expand Down
24 changes: 12 additions & 12 deletions projects/aca-content/src/lib/services/content-management.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export class ContentManagementService {
}

manageVersions(node: any, focusedElementOnCloseSelector?: string) {
if (node && node.entry) {
if (node?.entry) {
// shared and favorite
const id = node.entry.nodeId || (node as any).entry.guid;

Expand All @@ -137,7 +137,7 @@ export class ContentManagementService {
}

manageAspects(node: any, focusedElementOnCloseSelector?: string) {
if (node && node.entry) {
if (node?.entry) {
// shared and favorite
const id = node.entry.nodeId || (node as any).entry.guid;

Expand Down Expand Up @@ -174,7 +174,7 @@ export class ContentManagementService {
}

shareNode(node: any, focusedElementOnCloseSelector?: string): void {
if (node && node.entry) {
if (node?.entry) {
// shared and favorite
const id = node.entry.nodeId || (node as any).entry.guid;

Expand Down Expand Up @@ -276,7 +276,7 @@ export class ContentManagementService {
this.focusAfterClose(this.createMenuButtonSelector);
}),
map((node: SiteEntry) => {
if (node && node.entry && node.entry.guid) {
if (node?.entry?.guid) {
return node.entry.guid;
}
return null;
Expand Down Expand Up @@ -557,7 +557,7 @@ export class ContentManagementService {
errorJson = JSON.parse(error.message);
} catch {}

if (errorJson && errorJson.error && errorJson.error.statusCode === 403) {
if (errorJson?.error?.statusCode === 403) {
i18nMessageString = 'APP.MESSAGES.ERRORS.PERMISSION';
}

Expand Down Expand Up @@ -609,8 +609,8 @@ export class ContentManagementService {
}

private undoMoveNodes(moveResponse, selectionParentId: string) {
const movedNodes = moveResponse && moveResponse['succeeded'] ? moveResponse['succeeded'] : [];
const partiallyMovedNodes = moveResponse && moveResponse['partiallySucceeded'] ? moveResponse['partiallySucceeded'] : [];
const movedNodes = moveResponse?.['succeeded'] ?? [];
const partiallyMovedNodes = moveResponse?.['partiallySucceeded'] ?? [];

const restoreDeletedNodesBatch = this.nodeActionsService.moveDeletedEntries.map((folderEntry) =>
this.contentApi.restoreNode(folderEntry.nodeId || folderEntry.id).pipe(map((node) => node.entry))
Expand All @@ -623,7 +623,7 @@ export class ContentManagementService {

const revertMoveBatch = this.nodeActionsService
.flatten(nodesToBeMovedBack)
.filter((node) => node.entry || (node.itemMoved && node.itemMoved.entry))
.filter((node) => node.entry || node.itemMoved?.entry)
.map((node) => {
if (node.itemMoved) {
return this.nodeActionsService.moveNodeAction(node.itemMoved.entry, node.initialParentId);
Expand All @@ -647,7 +647,7 @@ export class ContentManagementService {
errorJson = JSON.parse(error.message);
} catch {}

if (errorJson && errorJson.error && errorJson.error.statusCode === 403) {
if (errorJson?.error?.statusCode === 403) {
message = 'APP.MESSAGES.ERRORS.PERMISSION';
}

Expand Down Expand Up @@ -1009,9 +1009,9 @@ export class ContentManagementService {
}

private showMoveMessage(nodes: Array<NodeEntry>, info: any, moveResponse?: any) {
const succeeded = moveResponse && moveResponse['succeeded'] ? moveResponse['succeeded'].length : 0;
const partiallySucceeded = moveResponse && moveResponse['partiallySucceeded'] ? moveResponse['partiallySucceeded'].length : 0;
const failures = moveResponse && moveResponse['failed'] ? moveResponse['failed'].length : 0;
const succeeded = moveResponse?.['succeeded'].length ?? 0;
const partiallySucceeded = moveResponse?.['partiallySucceeded'].length ?? 0;
const failures = moveResponse?.['failed'].length ?? 0;

let successMessage = '';
let partialSuccessMessage = '';
Expand Down

0 comments on commit b73a3f6

Please sign in to comment.