Skip to content

Commit a372dd1

Browse files
authored
Sonar recommendations (#32059)
1 parent 4013d1b commit a372dd1

File tree

7 files changed

+20
-23
lines changed

7 files changed

+20
-23
lines changed

generators/base-application/entity.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,13 +192,13 @@ export const mutateRelationship = {
192192
collection: ({ relationshipType }) => relationshipType === 'one-to-many' || relationshipType === 'many-to-many',
193193

194194
relationshipFieldName: ({ relationshipName }) => lowerFirst(relationshipName),
195-
relationshipFieldNamePlural: ({ relationshipFieldName }) => pluralize(relationshipFieldName!),
195+
relationshipFieldNamePlural: ({ relationshipFieldName }) => pluralize(relationshipFieldName),
196196
relationshipNamePlural: ({ relationshipName }) => pluralize(relationshipName),
197197
relationshipNameCapitalized: ({ relationshipName }) => upperFirst(relationshipName),
198198
relationshipNameHumanized: ({ relationshipName }) => startCase(relationshipName),
199199

200200
propertyName: ({ collection, relationshipFieldName, relationshipFieldNamePlural }) =>
201-
collection ? relationshipFieldNamePlural! : relationshipFieldName!,
201+
collection ? relationshipFieldNamePlural : relationshipFieldName,
202202

203203
...mutateProperty,
204204
} as const satisfies MutateDataPropertiesWithRequiredProperties<MutateDataParam<Relationship>, BaseApplicationAddedRelationshipProperties>;

generators/base-application/internal/utils.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ export function createAuthorityEntity(
259259
...customAuthorityData,
260260
};
261261

262-
loadRequiredConfigIntoEntity(authorityEntity, application as BaseApplicationApplication<BaseApplicationEntity>);
262+
loadRequiredConfigIntoEntity(authorityEntity, application);
263263
// Fallback to defaults for test cases.
264264
loadRequiredConfigIntoEntity(authorityEntity, this.jhipsterConfigWithDefaults as BaseApplicationApplication<BaseApplicationEntity>);
265265

@@ -281,15 +281,15 @@ function addOrExtendFields<const F extends BaseApplicationField>(fields: F[], fi
281281
for (const fieldToAdd of fieldsToAdd) {
282282
const { fieldName: newFieldName, id } = fieldToAdd;
283283
let field = fields.find(field => field.fieldName === newFieldName);
284-
if (!field) {
284+
if (field) {
285+
defaults(field, fieldToAdd);
286+
} else {
285287
field = { ...fieldToAdd };
286288
if (id) {
287289
fields.unshift(field);
288290
} else {
289291
fields.push(field);
290292
}
291-
} else {
292-
defaults(field, fieldToAdd);
293293
}
294294
}
295295
}
@@ -298,11 +298,11 @@ function addOrExtendRelationships<const R extends BaseApplicationRelationship>(r
298298
for (const relationshipToAdd of relationshipsToAdd) {
299299
const { relationshipName: newrelationshipName } = relationshipToAdd;
300300
let relationship = relationships.find(relationship => relationship.relationshipName === newrelationshipName);
301-
if (!relationship) {
301+
if (relationship) {
302+
defaults(relationship, relationshipToAdd);
303+
} else {
302304
relationship = { ...relationshipToAdd };
303305
relationships.push(relationship);
304-
} else {
305-
defaults(relationship, relationshipToAdd);
306306
}
307307
}
308308
}

generators/base-application/support/prepare-entity.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -498,8 +498,7 @@ function preparePostEntityCommonDerivedPropertiesNotTyped(entity: EntityAll) {
498498

499499
const types = entity.relationships
500500
.filter(rel => rel.otherEntity.primaryKey)
501-
.map(rel => rel.otherEntity.primaryKey!.fields.map(f => f.fieldType))
502-
.flat();
501+
.flatMap(rel => rel.otherEntity.primaryKey!.fields.map(f => f.fieldType));
503502
entity.otherEntityPrimaryKeyTypes = Array.from(new Set(types));
504503
entity.otherEntityPrimaryKeyTypesIncludesUUID = types.includes(UUID);
505504

generators/base-application/support/relationship.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ export const addOtherRelationship = <const R extends BaseApplicationRelationship
133133
const otherRelationship = {
134134
otherEntityName: lowerFirst(entity.name),
135135
otherEntityRelationshipName: relationship.relationshipName,
136-
relationshipName: relationship.otherEntityRelationshipName as string,
136+
relationshipName: relationship.otherEntityRelationshipName,
137137
relationshipType: otherRelationshipType(relationship.relationshipType),
138138
otherEntity: entity,
139139
ownerSide: !relationship.ownerSide,

generators/base-core/internal/write-files.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,11 @@ export const convertWriteFileSectionsToBlocks = <DataType, Generator>(
3131
})
3232
.filter(({ sectionName }) => !sectionName.startsWith('_'));
3333

34-
return parsedSections
35-
.map(({ sectionName, sectionBlocks }) => {
36-
return sectionBlocks.map((block, blockIdx) => {
37-
const blockSpecPath = `${sectionName}[${blockIdx}]`;
38-
assert(typeof block === 'object', `Block must be an object for ${blockSpecPath}`);
39-
return { blockSpecPath, ...block };
40-
});
41-
})
42-
.flat();
34+
return parsedSections.flatMap(({ sectionName, sectionBlocks }) => {
35+
return sectionBlocks.map((block, blockIdx) => {
36+
const blockSpecPath = `${sectionName}[${blockIdx}]`;
37+
assert(typeof block === 'object', `Block must be an object for ${blockSpecPath}`);
38+
return { blockSpecPath, ...block };
39+
});
40+
});
4341
};

generators/base-core/support/needles.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ export const insertContentBeforeNeedle = ({ content, contentToAdd, needle, autoI
216216
}
217217
contentToAdd = Array.isArray(contentToAdd) ? contentToAdd : [contentToAdd];
218218
if (autoIndent) {
219-
contentToAdd = contentToAdd.map(eachContentToAdd => eachContentToAdd.split('\n')).flat();
219+
contentToAdd = contentToAdd.flatMap(eachContentToAdd => eachContentToAdd.split('\n'));
220220
}
221221

222222
// Normalize needle indent with contentToAdd.

generators/base-core/support/properties-file.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export const editPropertiesFileCallback = (
7676
const existingLine = lines.find(line => Array.isArray(line) && line[0] === key) as string[] | undefined;
7777
if (existingLine) {
7878
if (typeof value === 'function' || valueSep) {
79-
existingLine[1] = getNewValue(value, existingLine[1] as string, valueSep);
79+
existingLine[1] = getNewValue(value, existingLine[1], valueSep);
8080
} else {
8181
existingLine[1] = value;
8282
}

0 commit comments

Comments
 (0)