Skip to content

Commit 2e690a0

Browse files
authored
Sonar recommendations (#32051)
1 parent d141cf1 commit 2e690a0

File tree

8 files changed

+25
-29
lines changed

8 files changed

+25
-29
lines changed

lib/jdl/converters/exporters/applications/jhipster-application-formatter.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@ function setUpApplicationStructure(application: JDLApplication): PostProcessedJD
5959
}
6060
applicationToExport[GENERATOR_NAME].entities = application.getEntityNames();
6161
if (application.hasConfigurationOption('creationTimestamp')) {
62-
applicationToExport[GENERATOR_NAME].creationTimestamp = parseInt(application.getConfigurationOptionValue('creationTimestamp'), 10);
62+
applicationToExport[GENERATOR_NAME].creationTimestamp = Number.parseInt(
63+
application.getConfigurationOptionValue('creationTimestamp'),
64+
10,
65+
);
6366
}
6467
const postProcessedApplicationToExport: PostProcessedJDLJSONApplication = cleanUpOptions(applicationToExport as JDLJSONApplication);
6568
return postProcessedApplicationToExport;

lib/jdl/core/built-in-options/tokens/application-tokens.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,7 @@ export const buildApplicationTokens = (tokenConfigs: JDLTokenConfig[]) => {
127127
tokenConfig.categories = [applicationConfigCategoryToken];
128128
// This is actually needed as the skipClient & skipServer options are both entity & app options...
129129
if (['SKIP_CLIENT', 'SKIP_SERVER'].includes(tokenConfig.name)) {
130-
tokenConfig.categories.push(KEYWORD);
131-
tokenConfig.categories.push(UNARY_OPTION);
130+
tokenConfig.categories.push(KEYWORD, UNARY_OPTION);
132131
}
133132
return createTokenFromConfig(tokenConfig);
134133
}),

lib/jdl/core/models/jdl-relationship.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ export default class JDLRelationship implements JDLRelationshipModel {
141141

142142
string += '\n}';
143143

144-
return string.replace(/ \n/g, '\n').replace(/[ ]{4}/g, ' ');
144+
return string.replace(/ \n/g, '\n').replace(/ {4}/g, ' ');
145145
}
146146

147147
private formatComment(comment: string | null | undefined): string {

lib/jdl/core/models/jdl-relationships.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ export default class JDLRelationships {
119119
}
120120

121121
function relationshipTypeToString(relationships: Map<string, JDLRelationship>, type: string) {
122-
const relationshipsLines = [...relationships.values()].map(relationship => relationship.toString().split('\n').slice(1, -1)).flat();
122+
const relationshipsLines = [...relationships.values()].flatMap(relationship => relationship.toString().split('\n').slice(1, -1));
123123
return `relationship ${type} {
124124
${relationshipsLines.join('\n')}
125125
}`;

lib/jdl/jdl-importer.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,7 @@ function importOnlyEntities(jdlObject: JDLObject, configuration: JDLApplicationC
177177
let { applicationName } = configuration;
178178

179179
let application = configuration.application;
180-
if (!application) {
181-
application = readCurrentPathYoRcFile();
182-
}
180+
application ??= readCurrentPathYoRcFile();
183181
if (application?.[GENERATOR_JHIPSTER]) {
184182
applicationName ??= application[GENERATOR_JHIPSTER].baseName;
185183
}

lib/jhipster/default-application-options.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,10 @@ function getConfigForAuthenticationType(options: ApplicationDefaults = {}): Appl
145145

146146
function getConfigForPackageName(options: ApplicationDefaults = {}): ApplicationDefaults {
147147
if (!options[PACKAGE_NAME]) {
148-
if (!options[PACKAGE_FOLDER]) {
149-
options[PACKAGE_NAME] = OptionValues[PACKAGE_NAME];
150-
} else {
148+
if (options[PACKAGE_FOLDER]) {
151149
options[PACKAGE_NAME] = options[PACKAGE_FOLDER].split('/').filter(Boolean).join('.');
150+
} else {
151+
options[PACKAGE_NAME] = OptionValues[PACKAGE_NAME];
152152
}
153153
}
154154
return options;

lib/testing/support/matrix-utils.ts

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,18 @@ export const fromMatrix = <T extends Record<string, any> = ConfigAll>(configMatr
4343
const samples = configEntries.reduce(
4444
(previousValue, currentValue) => {
4545
const [config, configValues] = currentValue;
46-
return previousValue
47-
.map(([previousName, previousConfig]) =>
48-
configValues.map((value: ValueType) => {
49-
return [
50-
// @ts-expect-error fix type
51-
appendTitle(previousName as string, config, value),
52-
{
53-
...(previousConfig as Record<string, ValueType>),
54-
[config]: value,
55-
},
56-
];
57-
}),
58-
)
59-
.flat();
46+
return previousValue.flatMap(([previousName, previousConfig]) =>
47+
configValues.map((value: ValueType) => {
48+
return [
49+
// @ts-expect-error fix type
50+
appendTitle(previousName as string, config, value),
51+
{
52+
...(previousConfig as Record<string, ValueType>),
53+
[config]: value,
54+
},
55+
];
56+
}),
57+
);
6058
},
6159
[['', {}]],
6260
);
@@ -73,9 +71,7 @@ const applyExtendedMatrix = <M extends Record<string, any> = ConfigAll, A extend
7371
const currentConfigObjects = configValues.map(configValue => ({
7472
[configName]: configValue,
7573
}));
76-
return currentArray
77-
.map(existingConfig => currentConfigObjects.map(currentObject => ({ ...existingConfig, ...currentObject })))
78-
.flat();
74+
return currentArray.flatMap(existingConfig => currentConfigObjects.map(currentObject => ({ ...existingConfig, ...currentObject })));
7975
},
8076
[{} as Record<keyof A, AdditionalValue<A, keyof A>>],
8177
);

lib/utils/yo-rc.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export const mergeYoRcContent = <
2727
merged[ns] = { ...oldConfig[ns], ...newConfig[ns] };
2828
}
2929
if ((oldConfig[YO_RC_CONFIG_KEY] as ConfigWithCreationTimestamp)?.creationTimestamp) {
30-
(merged[YO_RC_CONFIG_KEY] as ConfigWithCreationTimestamp)!.creationTimestamp = (
30+
(merged[YO_RC_CONFIG_KEY] as ConfigWithCreationTimestamp).creationTimestamp = (
3131
oldConfig[YO_RC_CONFIG_KEY] as ConfigWithCreationTimestamp
3232
).creationTimestamp;
3333
}

0 commit comments

Comments
 (0)