Skip to content

Commit 910cf95

Browse files
authored
perf(chore): sonar fixes (#847)
gh-845
1 parent 9b1e221 commit 910cf95

102 files changed

Lines changed: 306 additions & 293 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

packages/core/src/components/bearer-verifier/component.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {Binding, Component, inject, ProviderMap} from '@loopback/core';
22
import {Class, Model, Repository} from '@loopback/repository';
33
import {Strategies} from 'loopback4-authentication';
4+
import {ILogger, LOGGER} from '../logger-extension';
45

56
import {
67
BearerVerifierBindings,
@@ -16,6 +17,7 @@ export class BearerVerifierComponent implements Component {
1617
constructor(
1718
@inject(BearerVerifierBindings.Config)
1819
private readonly config: BearerVerifierConfig,
20+
@inject(LOGGER.LOGGER_INJECT) public logger: ILogger,
1921
) {
2022
this.providers = {};
2123
this.repositories = [RevokedTokenRepository];
@@ -29,7 +31,7 @@ export class BearerVerifierComponent implements Component {
2931
this.providers[Strategies.Passport.BEARER_TOKEN_VERIFIER.key] =
3032
FacadesBearerTokenVerifyProvider;
3133
} else {
32-
console.error('Invalid BearerVerifierType specified !');
34+
this.logger.error('Invalid BearerVerifierType specified !');
3335
}
3436
}
3537
providers?: ProviderMap;

packages/core/src/components/logger-extension/component.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import {LOGGER} from './keys';
33
import {LoggerProvider} from './providers/logger.provider';
44

55
export class LoggerExtensionComponent implements Component {
6-
constructor() {}
7-
8-
providers?: ProviderMap = {[LOGGER.BINDINGS.LOG_ACTION.key]: LoggerProvider};
6+
providers: ProviderMap = {};
7+
constructor() {
8+
this.providers = {[LOGGER.BINDINGS.LOG_ACTION.key]: LoggerProvider};
9+
}
910
}

packages/core/src/components/logger-extension/winston/logger-base.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import {LogMessage} from '../types';
44
import {LOGGER} from '../keys';
55

66
export class WinstonLoggerBase implements ILogger {
7-
constructor() {}
8-
97
logger: WinstonLogger;
108

119
log(info: LogMessage): void {

packages/core/src/components/swagger-authentication/middlewares/authenticate-swagger.middleware.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
import {MiddlewareContext, Middleware} from '@loopback/express';
1515
import {SwaggerAuthenticationBindings} from '../keys';
1616
import {HttpAuthenticationVerifier} from '../types';
17+
import {STATUS_CODE} from '../../../enums';
1718

1819
@globalInterceptor('auth', {tags: {name: 'AuthenticateSwaggerMiddleware'}})
1920
export class AuthenticateSwaggerMiddlewareInterceptor
@@ -43,7 +44,7 @@ export class AuthenticateSwaggerMiddlewareInterceptor
4344
const verified = this.verifier(username, password);
4445
if (!verified) {
4546
response
46-
.status(401)
47+
.status(STATUS_CODE.UNAUTHORISED)
4748
.setHeader('WWW-Authenticate', 'Basic realm="Node"');
4849
response.end('Unauthorized');
4950
return null;

packages/core/src/models/success-response.dto.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export class SuccessResponse extends Model {
99

1010
// Indexer property to allow additional data
1111
// eslint-disable-next-line @typescript-eslint/no-explicit-any
12-
[prop: string]: any;
12+
[prop: string]: any; //NOSONAR
1313

1414
constructor(data?: Partial<SuccessResponse>) {
1515
super(data);

packages/core/src/models/upsert-response.dto.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export class UpsertResponse extends Model {
1919

2020
// Indexer property to allow additional data
2121
// eslint-disable-next-line @typescript-eslint/no-explicit-any
22-
[prop: string]: any;
22+
[prop: string]: any; //NOSONAR
2323

2424
constructor(data?: Partial<UpsertResponse>) {
2525
super(data);

packages/search/projects/search-lib/karma.conf.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Karma configuration file, see link for more information
22
// https://karma-runner.github.io/1.0/config/configuration-file.html
33

4+
// sonarignore:start
45
module.exports = function (config) {
56
config.set({
67
basePath: '',
@@ -39,3 +40,4 @@ module.exports = function (config) {
3940
restartOnFileChange: true,
4041
});
4142
};
43+
// sonarignore:end

sandbox/audit-ms-example/src/models/to-do.model.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,4 @@ export class ToDo extends Entity {
3232
}
3333
}
3434

35-
export interface ToDoRelations {
36-
// describe navigational properties here
37-
}
38-
39-
export type ToDoWithRelations = ToDo & ToDoRelations;
35+
export type ToDoWithRelations = ToDo;

sandbox/auth-multitenant-example/src/__tests__/acceptance/todo.controller.acceptance.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ describe('PingController', () => {
1212
sarah: null,
1313
};
1414

15-
const client_id = 'temp_client';
16-
const client_secret = 'temp_secret';
15+
const clientId = 'temp_client';
16+
const clientSecret = 'temp_secret';
1717
const todo = {
1818
title: 'Testing',
1919
description: 'Test description',
@@ -26,14 +26,14 @@ describe('PingController', () => {
2626

2727
before('get auth tokens', async () => {
2828
const johnAuthRes = await client.post('/auth/login-token').send({
29-
client_id,
30-
client_secret,
29+
client_id: clientId,
30+
client_secret: clientSecret,
3131
username: 'john.doe@example.com',
3232
password: 'test123!@#',
3333
});
3434
const sarahAuthRes = await client.post('/auth/login-token').send({
35-
client_id,
36-
client_secret,
35+
client_id: clientId,
36+
client_secret: clientSecret,
3737
username: 'sarah.rafferty@example.com',
3838
password: 'test123!@#',
3939
});

sandbox/auth-multitenant-example/src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import {
55

66
export * from './application';
77

8+
const port = 3000;
9+
810
export async function main(
911
options: ApplicationConfig = {},
1012
): Promise<AuthMultitenantExampleApplication> {
@@ -23,7 +25,7 @@ if (require.main === module) {
2325
// Run the application
2426
const config = {
2527
rest: {
26-
port: +(process.env.PORT ?? 3000),
28+
port: +(process.env.PORT ?? port),
2729
host: process.env.HOST,
2830
// The `gracePeriodForClose` provides a graceful close for http/https
2931
// servers with keep-alive clients. The default value is `Infinity`

0 commit comments

Comments
 (0)