Skip to content

Commit

Permalink
Fix/sonar smells (#157)
Browse files Browse the repository at this point in the history
## PR Checklist

Please check if your PR fulfills the following requirements:

- [x] The commit message follows our guidelines: CONTRIBUTING.md#commit
- [ ] Tests for the changes have been added (for bug fixes / features)
- [ ] Docs have been added / updated (for bug fixes / features)

## PR Type

What kind of change does this PR introduce?

<!-- Please check the one that applies to this PR using "x". -->

```
[ ] Bugfix
[ ] Feature
[x] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Documentation content changes
[ ] Other... Please describe:
```

## What is the current behavior?

Some files still contain remaining logical OR operators (||) instead of
the safetier null coalescence operator (??).

## What is the new behavior?

All remaining instances of the || operator where replaced with the ??
operator.

## Does this PR introduce a breaking change?

```
[ ] Yes
[x] No
```
  • Loading branch information
NachoVazquez committed Jun 1, 2023
1 parent 158d1fc commit 0f87630
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export function formatLogDriverError<TPayload extends LumberjackLogPayload | voi
log,
logDriver,
}: LumberjackLogDriverError<TPayload>): string {
const thrownErrorMessage = (error as Error).message || String(error);
const thrownErrorMessage = (error as Error).message ?? String(error);
const payloadMessage = log.payload ? ` with payload "${JSON.stringify(log.payload)}"` : '';

return `Could not log message "${formattedLog}"${payloadMessage} to ${logDriver.config.identifier}.\n Error: "${thrownErrorMessage}"`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function parseFormattedLog(formattedLog: string) {
const formattedLogPattern = /^([a-z]+) ([0-9.:\-TZ]+) (\[(.+)\] )?(.*)$/;

const [, level, timestamp, taggedScopeWithEndingSpace = '', scope = '', message] =
formattedLogPattern.exec(formattedLog) || [];
formattedLogPattern.exec(formattedLog) ?? [];
const taggedScope = taggedScopeWithEndingSpace ? taggedScopeWithEndingSpace.slice(0, -1) : '';

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class LumberjackLogFormatter<TPayload extends LumberjackLogPayload | void
}

private createFormattingErrorLog(formatError: unknown, log: LumberjackLog<TPayload>): LumberjackLog<TPayload> {
const formattingErrorMessage = (formatError as Error).message || String(formatError);
const formattingErrorMessage = (formatError as Error).message ?? String(formatError);

return {
scope: 'LumberjackLogFormattingError',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class LumberjackLoggerBuilder<TPayload extends LumberjackLogPayload | voi
message: this.message,
scope: this.scope,
createdAt: this.time.getUnixEpochTicks(),
payload: (payloadArg[0] as TPayload) || this.payload,
payload: (payloadArg[0] as TPayload) ?? this.payload,
});
};
}
Expand Down

0 comments on commit 0f87630

Please sign in to comment.