Skip to content

Commit 314d351

Browse files
vaibhavbhalla2505Vaibhav  Bhallaa-ganguly
authored
refactor(chore): fix sonarqube issues (#2306)
* refactor(chore): fix sonarqube issues GH-2302 * refactor(chore): fix sonarqube issues GH-2302 * refactor(chore): fix sonarqube issues GH-2302 * refactor(chore): fix sonarqube issues GH-2302 --------- Co-authored-by: Vaibhav Bhalla <vaibhav.bhalla@SFSupports-MacBook-Air.local> Co-authored-by: a-ganguly <abir.ganguly@sourcefuse.com>
1 parent e169b24 commit 314d351

File tree

24 files changed

+304
-180
lines changed

24 files changed

+304
-180
lines changed

.czferc.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ module.exports = {
100100
message:
101101
'List any ISSUES CLOSED by this change (optional). E.g.: #31, #34:\n',
102102
filter: (input, answers) => {
103-
return input.replace(/^\#/g, 'gh-');
103+
return input.replace(/^#/g, 'gh-');
104104
},
105105
},
106106
{
@@ -164,7 +164,7 @@ function getMigrationChanges(staged) {
164164
.filter(f => f && f.length > 0);
165165
let timestamps = {};
166166
for (let item of migrationPaths) {
167-
let match = item.match(/[0-9]{14}/g);
167+
let match = item.match(/\d{14}/g);
168168
if (match && match[0]) {
169169
timestamps[match[0]] = [...(timestamps[match[0]] || []), item];
170170
}

packages/cli/src/commands/mcp.ts

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,7 @@ export class Mcp extends Base<{}> {
9191
command.name,
9292
command.mcpDescription,
9393
params,
94-
async args => {
95-
return command.mcpRun(args as Record<string, AnyObject[string]>);
96-
},
94+
async args => command.mcpRun(args as Record<string, AnyObject[string]>),
9795
);
9896
});
9997
}
@@ -116,10 +114,13 @@ export class Mcp extends Base<{}> {
116114
timestamp: new Date().toISOString(),
117115
})
118116
.catch(err => {
117+
// sonarignore:start
119118
console.error('Error sending exit message:', err);
119+
// sonarignore:end
120120
});
121121
return undefined as never;
122122
};
123+
// sonarignore:start
123124
const original = console.error;
124125
console.error = (...args: AnyObject[]) => {
125126
// log errors to the MCP client
@@ -135,6 +136,7 @@ export class Mcp extends Base<{}> {
135136
original(...args);
136137
};
137138
console.log = (...args: AnyObject[]) => {
139+
// sonarignore:end
138140
// log messages to the MCP client
139141
this.server.server
140142
.sendLoggingMessage({
@@ -143,7 +145,9 @@ export class Mcp extends Base<{}> {
143145
timestamp: new Date().toISOString(),
144146
})
145147
.catch(err => {
148+
// sonarignores:start
146149
console.error('Error sending logging message:', err);
150+
// sonarignore:end
147151
});
148152
};
149153
}
@@ -156,27 +160,35 @@ export class Mcp extends Base<{}> {
156160
private flagToZod<T>(flag: IFlag<T>, checkRequired = false) {
157161
let option;
158162
let description = flag.description ?? '';
159-
switch (true) {
160-
case flag.type === 'boolean':
161-
option = z.boolean().optional();
162-
option = option.default((flag.default as boolean) ?? false);
163-
break;
164-
case this._isOptionFlag(flag) && flag.options !== undefined: {
165-
// typescript is not able to infer type
166-
const typedFlag = flag as IOptionFlag<T>;
167-
option = z.enum(typedFlag.options as [string, ...string[]]);
168-
description += ` (options: ${typedFlag.options?.join(', ')})`;
169-
break;
170-
}
171-
case this._isOptionFlag(flag) && flag.options === undefined:
172-
option = z.string().optional();
173-
break;
174-
default:
175-
throw new Error(
176-
`Unsupported flag type: ${flag.type}. Supported types are boolean, option, enum, and integer.`,
177-
);
163+
164+
if (flag.type === 'boolean') {
165+
option = z.boolean().optional();
166+
option = option.default((flag.default as boolean) ?? false);
167+
return this._describeOption(option, description, flag, checkRequired);
168+
}
169+
if (!this._isOptionFlag(flag)) {
170+
throw new Error(
171+
'Unsupported flag type. Supported types are boolean, option, enum, and integer.',
172+
);
178173
}
179174

175+
const optionFlag = flag as IOptionFlag<T>;
176+
if (optionFlag.options !== undefined) {
177+
option = z.enum(optionFlag.options as [string, ...string[]]);
178+
description += ` (options: ${optionFlag.options?.join(', ')})`;
179+
return this._describeOption(option, description, flag, checkRequired);
180+
} else {
181+
option = z.string().optional();
182+
return this._describeOption(option, description, flag, checkRequired);
183+
}
184+
}
185+
186+
private _describeOption<T>(
187+
option: z.ZodTypeAny,
188+
description: string,
189+
flag: IFlag<T>,
190+
checkRequired: boolean,
191+
) {
180192
if (flag.dependsOn) {
181193
description += ` (required if ${flag.dependsOn.join(', ')} ${flag.dependsOn.length > 1 ? 'are' : 'is'} provided)`;
182194
option = option.optional();

packages/cli/src/generators/scaffold/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export default class ScaffoldGenerator extends BaseGenerator<ScaffoldOptions> {
6262
},
6363
);
6464
} catch (error) {
65-
this.log(chalk.cyan(`Error while adding jenkinsfile{error.message}`));
65+
this.log(chalk.cyan(`Error while adding jenkinsfile ${error}`));
6666
}
6767
}
6868
async install() {

packages/cli/src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export type CommandTestCase = {
8585
export type ICommandWithMcpFlags = {
8686
mcpFlags?: Record<string, IFlag<AnyObject[string]>>;
8787
args?: IArg[];
88-
flags?: Record<string, IFlag<AnyObject[string]>> | undefined;
88+
flags?: Record<string, IFlag<AnyObject[string]>>;
8989
name: string;
9090
mcpDescription: string;
9191
mcpRun: (args: Record<string, AnyObject[string]>) => Promise<McpTextResponse>;

packages/core/src/casbin-secure-sequence.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ const SequenceActions = RestBindings.SequenceActions;
4242
const isJsonString = (str: string) => {
4343
try {
4444
JSON.parse(str);
45-
} catch (_) {
45+
} catch (error) {
46+
// sonarignore:start
47+
console.error('Invalid JSON string', error);
48+
// sonarignore:end
4649
return false;
4750
}
4851
return true;

packages/core/src/mixins/booter.mixin.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const KEY_LENGTH = 5;
2424
* @param basePath The base path to be used as `projectRoot`
2525
* @param defaultOptions Default options to merge with user config
2626
*/
27+
// sonarignore-next-line
2728
export function BooterBasePathMixin<T extends Constructor<Booter>>(
2829
booterClass: T,
2930
basePath: string,

packages/core/src/secure-sequence.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ const SequenceActions = RestBindings.SequenceActions;
4141
const isJsonString = (str: string) => {
4242
try {
4343
JSON.parse(str);
44-
} catch (_) {
44+
} catch (error) {
45+
// sonarignore:start
46+
console.error('Invalid JSON string', error);
47+
// sonarignore:ends
4548
return false;
4649
}
4750
return true;

packages/core/src/service-sequence.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ const SequenceActions = RestBindings.SequenceActions;
3636
const isJsonString = (str: string) => {
3737
try {
3838
JSON.parse(str);
39-
} catch (_) {
39+
} catch (error) {
40+
// sonarignore:start
41+
console.error('Invalid JSON string', error);
42+
// sonarignore:end
4043
return false;
4144
}
4245
return true;

sandbox/auth-multitenant-example/migration.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ try {
1010
isLocal = true;
1111
}
1212
} catch (err) {
13-
console.info('\n');
13+
console.error('Error while checking for .infolder:', err);
1414
}
1515
if (isLocal) {
1616
console.info(`Skipping migrations`);

sandbox/telemed-app/backend/authentication-service/cdk/.gen/modules/redis.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ To get more info see https://registry.terraform.io/providers/hashicorp/aws/lates
1313
1414
* @default
1515
*/
16+
// sonarignore-next-line
1617
readonly additionalSecurityGroupRules?: any[];
1718
/**
1819
* Additional key-value pairs to add to each map in `tags_as_list_of_maps`. Not added to `tags` or `id`.
@@ -136,6 +137,7 @@ except for attributes, tags, and additional_tag_map, which are merged.
136137
137138
* @default [object Object]
138139
*/
140+
// sonarignore-next-line
139141
readonly context?: any;
140142
/**
141143
* Set `true` to create and configure a new security group. If false, `associated_security_group_ids` must be provided.
@@ -172,6 +174,7 @@ Default is `{}` (`descriptors` output will be empty).
172174
173175
* @default [object Object]
174176
*/
177+
// sonarignore-next-line
175178
readonly descriptorFormats?: any;
176179
/**
177180
* The subdomain to use for the CNAME record. If not provided then the CNAME record will use var.name.
@@ -183,6 +186,7 @@ Historical description: Outbound traffic address.
183186
Historical default: ["0.0.0.0/0"]
184187
185188
*/
189+
// sonarignore-next-line
186190
readonly egressCidrBlocks?: any[];
187191
/**
188192
* Subnet group name for the ElastiCache instance
@@ -278,6 +282,7 @@ Set to `[]` to suppress all generated tags.
278282
* @default
279283
* The property type contains a map, they have special handling, please see {@link cdk.tf/module-map-inputs the docs}
280284
*/
285+
// sonarignore-next-line
281286
readonly logDeliveryConfiguration?: {[key: string]: any}[];
282287
/**
283288
* Maintenance window
@@ -312,6 +317,7 @@ The "name" tag is set to the full `id` string. There is no tag with the value of
312317
* A list of Redis parameters to apply. Note that parameters may differ from one Redis family to another
313318
* @default
314319
*/
320+
// sonarignore-next-line
315321
readonly parameter?: any;
316322
/**
317323
* Managed by Terraform
@@ -441,9 +447,11 @@ Can also be a plain string, but that use is DEPRECATED because of Terraform issu
441447
442448
* @default
443449
*/
450+
// sonarignore-next-line
444451
readonly zoneId?: any;
445452
}
446453
export class Redis extends TerraformModule {
454+
// sonarignore-next-line
447455
private readonly inputs: {[name: string]: any} = {};
448456
public constructor(scope: Construct, id: string, config: RedisConfig) {
449457
super(scope, id, {

0 commit comments

Comments
 (0)