Skip to content

Commit

Permalink
fix(all-services): fix the pending sonar issues in all services (#2025)
Browse files Browse the repository at this point in the history
  • Loading branch information
arpit1503khanna authored Mar 6, 2024
1 parent 9356678 commit b2f6dc3
Show file tree
Hide file tree
Showing 24 changed files with 129 additions and 122 deletions.
2 changes: 1 addition & 1 deletion packages/cache/src/mixins/cache.mixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {

const SKIP_CACHE_VALUES = ['1', 'true', 1, true];
export class CacheManager {
static options: CachePluginComponentOptions = DEFAULT_CACHE_PLUGIN_OPTIONS;
static options: CachePluginComponentOptions = DEFAULT_CACHE_PLUGIN_OPTIONS; // NOSONAR

/* eslint-disable-next-line @typescript-eslint/naming-convention */
static CacheRepositoryMixin<
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ $ npm install -g @sourceloop/cli
$ sl COMMAND
running command...
$ sl (-v|--version|version)
@sourceloop/cli/7.2.1 darwin-arm64 node-v18.16.0
@sourceloop/cli/7.2.1 darwin-arm64 node-v18.17.0
$ sl --help [COMMAND]
USAGE
$ sl COMMAND
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/__tests__/commands/extension.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// sonarignore:start
import {Extension} from '../../commands/extension';
import {commandTest} from '../helper/command-test.helper';
import {extensionSuite} from '../suite/extension';

// sonarignore:start
describe('extension', () => {
extensionSuite.forEach(testCase => {
commandTest(testCase, Extension);
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/__tests__/commands/microservice.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// sonarignore:start
import {Microservice} from '../../commands/microservice';
import {commandTest} from '../helper/command-test.helper';
import {microserviceOptionsSuite} from '../suite/microservice-options';
import {microservicePromptsSuite} from '../suite/microservice-prompts';

// sonarignore:start
describe('microservice', () => {
describe('with options', () => {
microserviceOptionsSuite.forEach(testCase => {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/__tests__/commands/scaffold.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// sonarignore:start
import {Scaffold} from '../../commands/scaffold';
import {commandTest} from '../helper/command-test.helper';
import {scaffoldSuite} from '../suite/scaffold';

// sonarignore:start
describe('scaffold', () => {
scaffoldSuite.forEach(testCase => {
commandTest(testCase, Scaffold);
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/__tests__/commands/update.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// sonarignore:start
import {Update} from '../../commands/update';
import {commandTest} from '../helper/command-test.helper';
import {updateSuite} from '../suite/update';

// sonarignore:start
describe('update', () => {
updateSuite.forEach(testCase => {
commandTest(testCase, Update);
Expand Down
14 changes: 9 additions & 5 deletions packages/cli/src/generators/cdk/index.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import fetch from 'node-fetch';
import {existsSync, mkdirSync} from 'node:fs';
import zlib from 'node:zlib';
import {
readFile,
writeFile,
appendFile,
readFile,
readdir,
rename,
writeFile,
} from 'node:fs/promises';
import fetch from 'node-fetch';
import zlib from 'node:zlib';
import * as tar from 'tar';
import {
ObjectLiteralExpression,
OptionalKind,
Project,
PropertyAssignmentStructure,
} from 'ts-morph';
import {CdkOptions} from '../../types';
import {BaseGenerator} from '../../base-generator';
import {IacList} from '../../enum';
import {CdkOptions} from '../../types';
const chalk = require('chalk'); //NOSONAR

/**
Expand Down Expand Up @@ -264,7 +264,9 @@ export default class CdkGenerator extends BaseGenerator<CdkOptions> {
}`,
),
);
// sonarignore:start
const dec = sourcefile!.getVariableDeclaration(
// sonarignore:end
(this[this.options.iac!] as IacConfig).iacEnvObjectName,
);
if (dec) {
Expand Down Expand Up @@ -316,9 +318,11 @@ export default class CdkGenerator extends BaseGenerator<CdkOptions> {
async moveFiles() {
// We need to move lambda.ts alongside application.ts
// and Dockerfile.lambda to the root
// sonarignore:start
if (this.options.iac === IacList.LAMBDA) {
const dockerFileName = (this[this.options.iac] as LambdaConfig)
.dockerFile!;
// sonarignore:end
const lambdaFileName = (this[this.options.iac] as LambdaConfig)
.handlerFile;
const directory = this.options.dir;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="field_block" *ngFor="let field of data?.fieldData">

<label>{{field.label}}</label>
<label>{{field.label}}</label><!-- //NOSONAR -->
<div fxLayout="row" class="box" [class.active]="field?.isSelected" (click)="onEmitFieldData(field,true)">
<textarea [value]="field.value" #clause (blur)="getUpdatedValue(clause.value, field)" rows="5"
[disabled]="!field.supportedText">
Expand Down
162 changes: 79 additions & 83 deletions sandbox/cache-example/public/index.html
Original file line number Diff line number Diff line change
@@ -1,99 +1,95 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>cache example</title>

<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link
rel="shortcut icon"
type="image/x-icon"
href="https://loopback.io/favicon.ico"
/>

<style>
h3 {
margin-left: 25px;
text-align: center;

<head>
<title>cache example</title>

<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="shortcut icon" type="image/x-icon" href="https://loopback.io/favicon.ico" />

<style>
h3 {
margin-left: 25px;
text-align: center;
}

a,
a:visited {
color: #3f5dff;
}

h3 a {
margin-left: 10px;
}

a:hover,
a:focus,
a:active {
color: #001956;
}

.power {
position: absolute;
bottom: 25px;
left: 50%;
transform: translateX(-50%);
}

.info {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}

.info h1 {
text-align: center;
margin-bottom: 0;
}

.info p {
text-align: center;
margin-bottom: 3em;
margin-top: 1em;
}

@media (prefers-color-scheme: dark) {
body {
background-color: rgb(29, 30, 32);
color: white;
}

a,
a:visited {
color: #3f5dff;
}

h3 a {
margin-left: 10px;
color: #4990e2;
}

a:hover,
a:focus,
a:active {
color: #001956;
color: #2b78ff;
}
}
</style>
</head>

.power {
position: absolute;
bottom: 25px;
left: 50%;
transform: translateX(-50%);
}
<body>
<div class="info">
<h1>cache-example</h1>
<p>Version 1.0.0</p>

.info {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
<h3>OpenAPI spec: <a href="./openapi.json">/openapi.json</a></h3>
<h3>API Explorer: <a href="./explorer">/explorer</a></h3>
</div>

.info h1 {
text-align: center;
margin-bottom: 0;
}

.info p {
text-align: center;
margin-bottom: 3em;
margin-top: 1em;
}
<footer class="power">
<a href="https://loopback.io" target="_blank">
<img src="https://loopback.io/images/branding/powered-by-loopback/blue/powered-by-loopback-sm.png"
alt="loopback" />
</a>
</footer>
</body>

@media (prefers-color-scheme: dark) {
body {
background-color: rgb(29, 30, 32);
color: white;
}

a,
a:visited {
color: #4990e2;
}

a:hover,
a:focus,
a:active {
color: #2b78ff;
}
}
</style>
</head>

<body>
<div class="info">
<h1>cache-example</h1>
<p>Version 1.0.0</p>

<h3>OpenAPI spec: <a href="./openapi.json">/openapi.json</a></h3>
<h3>API Explorer: <a href="./explorer">/explorer</a></h3>
</div>

<footer class="power">
<a href="https://loopback.io" target="_blank">
<img
src="https://loopback.io/images/branding/powered-by-loopback/blue/powered-by-loopback-sm.png"
alt="loopback-image"
/>
</a>
</footer>
</body>
</html>
</html>
4 changes: 2 additions & 2 deletions sandbox/oauth-example/src/repositories/user.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export class UserRepository extends DefaultSoftCrudRepository<
const user = await super.findOne({where: {username}});
const creds = user && (await this.credentials(user.id).get());
// eslint-disable-next-line
if (!user || user.deleted || !creds || !creds.password) {
if (!user || user.deleted || !creds?.password) {
throw new HttpErrors.Unauthorized(AuthenticateErrorKeys.UserDoesNotExist);
} else if (creds.authProvider !== AuthProvider.INTERNAL) {
throw new HttpErrors.BadRequest(
Expand Down Expand Up @@ -191,7 +191,7 @@ export class UserRepository extends DefaultSoftCrudRepository<
);
}
// eslint-disable-next-line
if (!user || user.deleted || !creds || !creds.password) {
if (!user || user.deleted || !creds?.password) {
throw new HttpErrors.Unauthorized(AuthenticateErrorKeys.UserDoesNotExist);
} else if (await bcrypt.compare(newPassword, creds.password)) {
throw new HttpErrors.Unauthorized(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {Provider, injectable, BindingScope} from '@loopback/core';
import {BindingScope, Provider, injectable} from '@loopback/core';
import {repository} from '@loopback/repository';
import {
FindAccountProviderFn,
UserRepository,
User,
FindAccountResult,
User,
UserRepository,
} from '@sourceloop/oidc-service';

const defaultClaims = ['email'];
Expand Down Expand Up @@ -35,7 +35,7 @@ export class CustomFindAccountProvider
const userClaims: {[key: string]: User[keyof User] | undefined} = {};

claimsProfile.forEach(claim => {
if (newUser && newUser[claim as keyof User]) {
if (newUser?.[claim as keyof User]) {
userClaims[claim] = newUser[claim as keyof User];
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class AuthCacheDataSource
extends juggler.DataSource
implements LifeCycleObserver
{
static dataSourceName = 'AuthCache';
static readonly dataSourceName = 'AuthCache';
static readonly defaultConfig = config;

constructor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const config = {
};

export class AuthMockDataDataSource extends juggler.DataSource {
static dataSourceName = 'AuthDB';
static readonly dataSourceName = 'AuthDB';

constructor(
@inject('datasources.config.AuthDB', {optional: true})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class WorkflowDbDatasource
extends juggler.DataSource
implements LifeCycleObserver
{
static dataSourceName = WorkflowCacheSourceName;
static readonly dataSourceName = WorkflowCacheSourceName;

constructor(
@inject(`datasources.config.${WorkflowCacheSourceName}`, {optional: true})
Expand Down
2 changes: 1 addition & 1 deletion services/chat-service/src/datasources/pgdb.datasource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class PgdbDataSource
extends juggler.DataSource
implements LifeCycleObserver
{
static dataSourceName = 'chatDb';
static readonly dataSourceName = 'chatDb';

constructor(
@inject('datasources.config.Chat', {optional: true})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const config = {
};

export class FeatureToggleMockDataSource extends juggler.DataSource {
static dataSourceName = FeatureToggleDbName;
static readonly dataSourceName = FeatureToggleDbName;

constructor(
@inject('datasources.config.FeatureToggleDB', {optional: true})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class NotificationDbCacheDataSource
extends juggler.DataSource
implements LifeCycleObserver
{
static dataSourceName = 'NotifAccessCache';
static readonly dataSourceName = 'NotifAccessCache';

constructor(
@inject('datasources.config.NotifAccessCache', {optional: true})
Expand Down
Loading

0 comments on commit b2f6dc3

Please sign in to comment.