Skip to content

Commit f2102cb

Browse files
fix(all-services): sonar issues (#2253)
* fix(all-services): sonar issues GH-2252 * fix(all-services): refactor code GH-2252 * fix(all-services): sonar issues GH-2252 * fix(all-services): sonar issues GH-2252 * fix(all-services): sonar issues GH-2252 * fix(all-services): sonar issues GH-2252 * fix(all-services): sonar issues GH-2252 * fix(all-services): sonar issue GH-2252 * fix(all-services): fix formatting and linting issues GH-2252 * refactor(cli): readme update GH-2252
1 parent 8288e78 commit f2102cb

File tree

46 files changed

+1737
-984
lines changed

Some content is hidden

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

46 files changed

+1737
-984
lines changed

export-typedocs.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { execSync } from 'child_process';
2-
import { existsSync, readFileSync, writeFileSync } from 'fs';
1+
import {execSync} from 'child_process';
2+
import {existsSync, readFileSync, writeFileSync} from 'fs';
33
import * as path from 'path';
4-
import { PackageJson } from 'type-fest';
4+
import {PackageJson} from 'type-fest';
55
import * as TypeDoc from 'typedoc';
66

77
/**

packages/cli/.eslintrc.js

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
module.exports = {
2-
extends: '@loopback/eslint-config',
3-
rules: {
4-
'no-extra-boolean-cast': 'off',
5-
'@typescript-eslint/interface-name-prefix': 'off',
6-
'no-prototype-builtins': 'off',
7-
'@typescript-eslint/no-misused-promises': [
8-
'error',
9-
{
10-
checksVoidReturn: false,
11-
},
12-
],
13-
},
14-
};
15-
2+
extends: '@loopback/eslint-config',
3+
rules: {
4+
'no-extra-boolean-cast': 'off',
5+
'@typescript-eslint/interface-name-prefix': 'off',
6+
'no-prototype-builtins': 'off',
7+
'@typescript-eslint/no-misused-promises': [
8+
'error',
9+
{
10+
checksVoidReturn: false,
11+
},
12+
],
13+
},
14+
};

packages/cli/src/generators/backstage-integration/index.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22
//
33
// This software is released under the MIT License.
44
// https://opensource.org/licenses/MIT
5-
import { BaseGenerator } from '../../base-generator';
6-
import { BackstageIntegrationOptions } from '../../types';
5+
import {BaseGenerator} from '../../base-generator';
6+
import {BackstageIntegrationOptions} from '../../types';
77
export default class BackstageIntegrationGenerator extends BaseGenerator<BackstageIntegrationOptions> {
88
cwd?: string;
9-
constructor(public args: string[], public opts: BackstageIntegrationOptions) {
9+
constructor(
10+
public args: string[],
11+
public opts: BackstageIntegrationOptions,
12+
) {
1013
super(args, opts);
1114
}
1215

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

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import fetch from 'node-fetch';
2-
import { existsSync, mkdirSync } from 'node:fs';
2+
import {existsSync, mkdirSync} from 'node:fs';
33
import {
44
appendFile,
55
readFile,
@@ -15,9 +15,9 @@ import {
1515
Project,
1616
PropertyAssignmentStructure,
1717
} from 'ts-morph';
18-
import { BaseGenerator } from '../../base-generator';
19-
import { IacList } from '../../enum';
20-
import { CdkOptions } from '../../types';
18+
import {BaseGenerator} from '../../base-generator';
19+
import {IacList} from '../../enum';
20+
import {CdkOptions} from '../../types';
2121
const chalk = require('chalk'); //NOSONAR
2222

2323
/**
@@ -101,12 +101,8 @@ export default class CdkGenerator extends BaseGenerator<CdkOptions> {
101101
);
102102
}
103103

104-
if (!this.options.dir) {
105-
this.options.dir = 'cdk';
106-
}
107-
if (!this.options.packageJsonName) {
108-
this.options.packageJsonName = `arc-cdktf`;
109-
}
104+
this.options.dir ??= 'cdk';
105+
this.options.packageJsonName ??= `arc-cdktf`;
110106
if (!this.options.iac) {
111107
throw new Error(
112108
'Error: The "iac" option is missing. Please provide an iac name.',
@@ -131,7 +127,7 @@ export default class CdkGenerator extends BaseGenerator<CdkOptions> {
131127
return filesToKeep.some(reqPath => filePath.startsWith(reqPath));
132128
};
133129

134-
const { owner, repo, tag, templateDir: dir } = this.remoteConfig;
130+
const {owner, repo, tag, templateDir: dir} = this.remoteConfig;
135131
/**
136132
* When the tar file is downloaded and extracted it creates a dir structure like
137133
* ${repo}-${tag}
@@ -146,7 +142,7 @@ export default class CdkGenerator extends BaseGenerator<CdkOptions> {
146142

147143
try {
148144
if (!existsSync(outputDir)) {
149-
mkdirSync(outputDir, { recursive: true });
145+
mkdirSync(outputDir, {recursive: true});
150146
}
151147

152148
const response = await fetch(url);
@@ -215,7 +211,8 @@ export default class CdkGenerator extends BaseGenerator<CdkOptions> {
215211

216212
await this._updateFile(
217213
this.destinationPath(
218-
`${this.options.dir}/${(this[this.options.iac!] as LambdaConfig).handlerFile
214+
`${this.options.dir}/${
215+
(this[this.options.iac!] as LambdaConfig).handlerFile
219216
}`,
220217
),
221218
'{{app_class_name_placeholder}}',
@@ -224,18 +221,19 @@ export default class CdkGenerator extends BaseGenerator<CdkOptions> {
224221

225222
await this._updateFile(
226223
this.destinationPath(
227-
`${this.options.dir}/${(this[this.options.iac!] as LambdaConfig).handlerFile
224+
`${this.options.dir}/${
225+
(this[this.options.iac!] as LambdaConfig).handlerFile
228226
}`,
229227
),
230228
'{{app_import_placeholder}}',
231229
appImport,
232230
);
233231
} else {
234232
// Handle the case where applicationClassName or relativePathToApp is undefined
235-
this.log.error("Application class name or relative path to app is undefined.");
233+
this.log.error(
234+
'Application class name or relative path to app is undefined.',
235+
);
236236
}
237-
238-
239237
}
240238

241239
async updatePackageJsonName() {
@@ -247,9 +245,8 @@ export default class CdkGenerator extends BaseGenerator<CdkOptions> {
247245
);
248246
} else {
249247
// Handle the case where applicationClassName or relativePathToApp is undefined
250-
this.log.error("packageJsonName is undefined.");
248+
this.log.error('packageJsonName is undefined.');
251249
}
252-
253250
}
254251

255252
async configureEnvs() {
@@ -258,17 +255,19 @@ export default class CdkGenerator extends BaseGenerator<CdkOptions> {
258255
const keysToCreate = await this._getEnvKeys(envFile);
259256
await this._appendEmptyKeysToEnv(
260257
this.destinationPath(
261-
`${this.options.dir}/${(this[this.options.iac!] as IacConfig).envSchemaFile
258+
`${this.options.dir}/${
259+
(this[this.options.iac!] as IacConfig).envSchemaFile
262260
}`,
263261
),
264262
keysToCreate,
265263
);
266264

267265
// Create entries for env variables in stack
268266
try {
269-
const { project, sourcefile } = this._parseTsFile(
267+
const {project, sourcefile} = this._parseTsFile(
270268
this.destinationPath(
271-
`${this.options.dir!}/${(this[this.options.iac!] as IacConfig).mainStackFile
269+
`${this.options.dir!}/${
270+
(this[this.options.iac!] as IacConfig).mainStackFile
272271
}`,
273272
),
274273
);
@@ -300,7 +299,8 @@ export default class CdkGenerator extends BaseGenerator<CdkOptions> {
300299
this.log.ok('Your files are ready for action! 🎉');
301300
} catch (error) {
302301
this.log.error(
303-
`Failed to update env vars of lambda stack in ${this.options.dir}/${(this[this.options.iac!] as IacConfig).mainStackFile
302+
`Failed to update env vars of lambda stack in ${this.options.dir}/${
303+
(this[this.options.iac!] as IacConfig).mainStackFile
304304
}.`,
305305
error,
306306
);
@@ -374,19 +374,18 @@ export default class CdkGenerator extends BaseGenerator<CdkOptions> {
374374
});
375375
} else {
376376
// Handle the case where applicationClassName or relativePathToApp is undefined
377-
this.log.error("dir is undefined.");
377+
this.log.error('dir is undefined.');
378378
}
379-
380379
}
381380

382381
async end() {
383-
const { owner, repo, templateDir: dir } = this.remoteConfig;
382+
const {owner, repo, templateDir: dir} = this.remoteConfig;
384383
this.log(`
385384
${chalk.green("🚀 Hooray! You're all set to launch your app.")}
386385
Next steps:
387386
1. Fill up the environment variables in your ${chalk.yellow(
388-
this.options.dir,
389-
)} directory.
387+
this.options.dir,
388+
)} directory.
390389
2. Build your app.
391390
3. Run ${chalk.blue(`cdktf deploy ${this.options.iac}`)} to deploy the iac.
392391
@@ -499,7 +498,7 @@ ${chalk.blue(`https://github.com/${owner}/${repo}/blob/main/${dir}/README.md`)}
499498
_parseTsFile(filePath: string) {
500499
const project = new Project();
501500
const sourcefile = project.addSourceFileAtPathIfExists(filePath);
502-
return { project, sourcefile };
501+
return {project, sourcefile};
503502
}
504503

505504
/**
@@ -539,9 +538,9 @@ ${chalk.blue(`https://github.com/${owner}/${repo}/blob/main/${dir}/README.md`)}
539538
encoding: BufferEncoding = 'utf-8',
540539
) {
541540
try {
542-
let data = await readFile(filePath, { encoding });
541+
let data = await readFile(filePath, {encoding});
543542
data = data.replace(new RegExp(placeholder, 'g'), replaceWith);
544-
await writeFile(filePath, data, { encoding });
543+
await writeFile(filePath, data, {encoding});
545544
} catch (error) {
546545
if (error instanceof Error) {
547546
this.log.error(error.message);
@@ -595,6 +594,7 @@ ${chalk.blue(`https://github.com/${owner}/${repo}/blob/main/${dir}/README.md`)}
595594
JSON_INDENTATION,
596595
)}`,
597596
);
597+
throw error;
598598
}
599599
}
600600

@@ -631,7 +631,7 @@ ${chalk.blue(`https://github.com/${owner}/${repo}/blob/main/${dir}/README.md`)}
631631
return pattern.test(fileContent);
632632
} catch (error) {
633633
this.log.error(`Error reading ${filePath}`);
634-
return false;
634+
throw error;
635635
}
636636
}
637637

@@ -648,6 +648,7 @@ ${chalk.blue(`https://github.com/${owner}/${repo}/blob/main/${dir}/README.md`)}
648648
this.log.error(
649649
`Error moving file from ${sourcePath} to ${destinationPath}`,
650650
);
651+
throw error;
651652
}
652653
}
653654
}

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// This software is released under the MIT License.
44
// https://opensource.org/licenses/MIT
55
import fs from 'fs';
6-
import { join } from 'path';
6+
import {join} from 'path';
77
// eslint-disable-next-line @typescript-eslint/naming-convention
88
import AppGenerator from '../../app-generator';
99
import {
@@ -17,14 +17,14 @@ import {
1717
SEQUELIZESERVICES,
1818
SERVICES,
1919
} from '../../enum';
20-
import { AnyObject, MicroserviceOptions } from '../../types';
20+
import {AnyObject, MicroserviceOptions} from '../../types';
2121
import {
2222
JSON_SPACING,
2323
appendDependencies,
2424
getDependencyVersion,
2525
} from '../../utils';
2626
const chalk = require('chalk'); //NOSONAR
27-
const { promisify } = require('util');
27+
const {promisify} = require('util');
2828

2929
const DATASOURCE_TEMPLATE = join(
3030
'..',
@@ -79,7 +79,7 @@ const DEFAULT_NAME = 'microservice';
7979
const dbconfig = 'database.json';
8080

8181
const ENV_EXAMPLE = '.env.example';
82-
const ENV_DEFAULT = '.env.defaults'
82+
const ENV_DEFAULT = '.env.defaults';
8383

8484
export default class MicroserviceGenerator extends AppGenerator<MicroserviceOptions> {
8585
initializing() {
@@ -138,7 +138,7 @@ export default class MicroserviceGenerator extends AppGenerator<MicroserviceOpti
138138
);
139139
this.projectInfo.datasourceConnector =
140140
DATASOURCE_CONNECTORS[
141-
this.options.datasourceType ?? DATASOURCES.POSTGRES
141+
this.options.datasourceType ?? DATASOURCES.POSTGRES
142142
];
143143
this.projectInfo.datasourceConnectorName =
144144
this.projectInfo.datasourceConnector;
@@ -332,7 +332,7 @@ export default class MicroserviceGenerator extends AppGenerator<MicroserviceOpti
332332
async _appendDockerScript() {
333333
const packageJsonFile = join(this.destinationRoot(), './package.json');
334334
const packageJson = this.fs.readJSON(packageJsonFile) as AnyObject;
335-
const scripts = { ...packageJson.scripts };
335+
const scripts = {...packageJson.scripts};
336336
scripts[`docker:build:${this.options.baseService}`] =
337337
`docker build --build-arg SERVICE_NAME=${this.options.baseService} --build-arg FROM_FOLDER=services -t $REPOSITORY_URI:${this.options.baseService} -f ./services/${this.options.name}/Dockerfile .`;
338338
packageJson.scripts = scripts;
@@ -539,7 +539,7 @@ export default class MicroserviceGenerator extends AppGenerator<MicroserviceOpti
539539
// Handle the error or perform actions when the file/directory doesn't exist
540540
this.log(
541541
chalk.cyan(
542-
`Since migrations do not exist in the base service, generating without migrations`,
542+
`Since migrations do not exist in the base service, generating without migrations ${error}`,
543543
),
544544
);
545545
return;
@@ -579,7 +579,7 @@ export default class MicroserviceGenerator extends AppGenerator<MicroserviceOpti
579579
// File exists
580580
return true;
581581
} catch (error) {
582-
// File does not exist
582+
this.log(chalk.cyan(`No migrations found ${error}`));
583583
return false;
584584
}
585585
}

0 commit comments

Comments
 (0)