Skip to content

Commit

Permalink
refactor(chore): fix sonar code smells (#1402)
Browse files Browse the repository at this point in the history
mostly of function interfaces
  • Loading branch information
shubhamp-sf authored May 3, 2023
1 parent 085faef commit 9244178
Show file tree
Hide file tree
Showing 13 changed files with 186 additions and 224 deletions.
2 changes: 1 addition & 1 deletion packages/cli/src/base-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export abstract class BaseGenerator<
}

exit(reason?: string) {
if (!!reason) return;
if (reason) return;
this.exitGeneration = reason;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/generators/extension/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export default class ExtensionGenerator extends BaseExtensionGenerator<Extension
const offset = 2;
const firstPart = czConfig.slice(0, lastScopeIndex + offset);
const secPart = czConfig.slice(lastScopeIndex + offset);
const stringToAdd = `{name: \'${this.options.name}\'}, \n`;
const stringToAdd = `{name: '${this.options.name}'}, \n`;

czConfig = firstPart + stringToAdd + secPart;
fs.writeFile(
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/generators/microservice/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ export default class MicroserviceGenerator extends AppGenerator<MicroserviceOpti
const suffix = this.options.facade ? 'facade' : 'service';

const stringToAdd =
`{name: \'${this.options.name}` + '-' + `${suffix}\'}, \n`;
`{name: '${this.options.name}` + '-' + `${suffix}'}, \n`;

czConfig = firstPart + stringToAdd + secPart;
fs.writeFile(
Expand Down
16 changes: 6 additions & 10 deletions packages/core/src/components/logger-extension/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,12 @@ import {Request, OperationArgs} from '@loopback/rest';
/**
* A function to perform REST req/res logging action
*/
export interface LogFn {
(
req: Request,
args: OperationArgs,
// sonarignore:start
/* eslint-disable @typescript-eslint/no-explicit-any */
result: any,
): // sonarignore:end
Promise<void>;
}
export type LogFn = (
req: Request,
args: OperationArgs,
/* eslint-disable @typescript-eslint/no-explicit-any */
result: any, // NOSONAR
) => Promise<void>;

export interface LogMessage {
key?: string;
Expand Down
8 changes: 2 additions & 6 deletions packages/feature-toggle/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,9 @@ export interface FeatureFlagMetadata {
options?: Object;
}

export interface FeatureInterface {
(): Promise<boolean>;
}
export type FeatureInterface = () => Promise<boolean>;

export interface FeatureFlagFn {
(): Promise<boolean>;
}
export type FeatureFlagFn = () => Promise<boolean>;

export interface IAuthUserWithDisabledFeat extends IAuthUserWithPermissions {
disabledFeatures: string[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ export class FakeBackendHttpInterceptor implements HttpInterceptor {
}
if (url.includes('heroes/?name=') && method === 'GET') {
const name = url.split('=')[1];
const res = HEROES.filter(hero => hero.name.match(name));
let regexp = new RegExp(name);
const res = HEROES.filter(hero => regexp.exec(hero.name));
return of(new HttpResponse({body: res, status: 200}));
}
if (url.match(/\/heroes\/.*/) && method === 'GET') {
Expand Down
2 changes: 1 addition & 1 deletion services/authentication-service/src/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export class AuthenticationServiceComponent implements Component {
// Mount core component
this.application.component(CoreComponent);

if (!!+(process.env.AZURE_AUTH_ENABLED ?? 0)) {
if (+(process.env.AZURE_AUTH_ENABLED ?? 0)) {
const expressMiddlewares =
this.application.getSync(SFCoreBindings.EXPRESS_MIDDLEWARES) ?? [];
expressMiddlewares.push(cookieParser());
Expand Down
Loading

0 comments on commit 9244178

Please sign in to comment.