Skip to content

Commit 3eec6f8

Browse files
committed
feat(query-generation): sonar fixes
1 parent bff3346 commit 3eec6f8

2 files changed

Lines changed: 34 additions & 26 deletions

File tree

src/components/db-query/db-query.graph.ts

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -170,34 +170,38 @@ export class DbQueryGraph extends BaseGraph<DbQueryState> {
170170
}
171171

172172
private _mergeValidationResults(state: DbQueryState) {
173-
const hasSyntacticFailure =
174-
state.syntacticStatus && state.syntacticStatus !== EvaluationResult.Pass;
175-
const hasSemanticFailure =
176-
state.semanticStatus && state.semanticStatus !== EvaluationResult.Pass;
173+
const hasSyntacticFailure = this._isValidationFailure(
174+
state.syntacticStatus,
175+
);
176+
const hasSemanticFailure = this._isValidationFailure(state.semanticStatus);
177177

178178
if (!hasSyntacticFailure && !hasSemanticFailure) {
179179
return this._buildPassedResult(state);
180180
}
181181

182+
return this._buildFailedResult(state, hasSyntacticFailure);
183+
}
184+
185+
private _isValidationFailure(status: DbQueryState['syntacticStatus']) {
186+
return !!status && status !== EvaluationResult.Pass;
187+
}
188+
189+
private _buildFailedResult(
190+
state: DbQueryState,
191+
hasSyntacticFailure: boolean,
192+
) {
182193
const clearedState = this._buildClearedState(state);
183194
const baseFeedbacks = state.feedbacks ?? [];
184195
const semanticFb = this._toArray(state.semanticFeedback);
185-
186-
if (hasSyntacticFailure) {
187-
return {
188-
status: state.syntacticStatus,
189-
feedbacks: [
190-
...baseFeedbacks,
191-
...this._toArray(state.syntacticFeedback),
192-
...semanticFb,
193-
],
194-
...clearedState,
195-
};
196-
}
196+
const syntacticFb = hasSyntacticFailure
197+
? this._toArray(state.syntacticFeedback)
198+
: [];
197199

198200
return {
199-
status: state.semanticStatus,
200-
feedbacks: [...baseFeedbacks, ...semanticFb],
201+
status: hasSyntacticFailure
202+
? state.syntacticStatus
203+
: state.semanticStatus,
204+
feedbacks: [...baseFeedbacks, ...syntacticFb, ...semanticFb],
201205
...clearedState,
202206
};
203207
}

src/components/db-query/services/template-helper.service.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -286,14 +286,18 @@ Do not return any other text or explanation, just the XML tags.
286286
}
287287

288288
private _formatValue(type: string, value: string | null): string {
289-
const formatters: Record<string, (v: string | null) => string> = {
290-
string: v => `'${(v ?? '').replace(/'/g, "''")}'`,
291-
number: v => `${Number(v) || 0}`,
292-
boolean: v => (this._isTruthy(v) ? 'TRUE' : 'FALSE'),
293-
// eslint-disable-next-line @typescript-eslint/naming-convention
294-
sql_expression: v => v ?? '1=1',
295-
};
296-
return (formatters[type] ?? (v => v ?? ''))(value);
289+
switch (type) {
290+
case 'string':
291+
return `'${(value ?? '').replace(/'/g, "''")}'`;
292+
case 'number':
293+
return `${Number(value) || 0}`;
294+
case 'boolean':
295+
return this._isTruthy(value) ? 'TRUE' : 'FALSE';
296+
case 'sql_expression':
297+
return value ?? '1=1';
298+
default:
299+
return value ?? '';
300+
}
297301
}
298302

299303
private _isTruthy(value: string | null): boolean {

0 commit comments

Comments
 (0)