Skip to content

Commit

Permalink
fix: sonar cloud smells (#155)
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". -->

```
[x] Bugfix
[ ] Feature
[ ] 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?

The Sonar cloud on the main branch reports six smells on the code.

The smells are about

- replacing || operator with ??
- returning this as the type of fluent API functions

## What is the new behavior?

- Logical Or operator (||) is replaced for coalescence operator (??)
- We set this as the return type of fluent functions

## Does this PR introduce a breaking change?

```
[ ] Yes
[x] No
```

## Other information


https://sonarcloud.io/project/issues?resolved=false&id=ngworker_lumberjack
  • Loading branch information
NachoVazquez committed May 25, 2023
1 parent cd72a1b commit 158d1fc
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 @@ import { NoopConsole } from './noop-console.service';
deps: [[new Optional(), new SkipSelf(), NoopConsole]],
provide: lumberjackConsoleToken,
useFactory: (maybeExistingInstance: NoopConsole | null): NoopConsole =>
maybeExistingInstance || new NoopConsole(),
maybeExistingInstance ?? new NoopConsole(),
},
],
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { SpyConsole } from './spy-console.service';
{
deps: [[new Optional(), new SkipSelf(), SpyConsole]],
provide: lumberjackConsoleToken,
useFactory: (maybeExistingInstance: SpyConsole | null): SpyConsole => maybeExistingInstance || new SpyConsole(),
useFactory: (maybeExistingInstance: SpyConsole | null): SpyConsole => maybeExistingInstance ?? new SpyConsole(),
},
],
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ import { ObjectPayload } from './object.payload';
@Injectable({ providedIn: 'root' })
export class ObjectService {
log(object?: ObjectPayload): boolean {
return object?.isWorking || false;
return object?.isWorking ?? false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class LumberjackLogBuilder<TPayload extends LumberjackLogPayload | void =
message: this.message,
scope: this.scope,
createdAt: this.time.getUnixEpochTicks(),
payload: (payloadArg[0] || this.payload) as Exclude<TPayload, InternalWithStaticPayload>,
payload: (payloadArg[0] ?? this.payload) as Exclude<TPayload, InternalWithStaticPayload>,
};
}

Expand Down

0 comments on commit 158d1fc

Please sign in to comment.