Skip to content

Commit 2bf567b

Browse files
lucas-paulger-sonarsourcesonartech
authored andcommitted
SONARCH-1471: Detect the language by ncloc (#3646)
GitOrigin-RevId: b48b3f56ff34d5c6566fd89156677300d47ebdab
1 parent 2fd34ce commit 2bf567b

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

libs/shared/src/helpers/measures.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
import { RatingBadgeRating } from '@sonarsource/echoes-react';
2222
import { IntlShape } from 'react-intl';
2323
import { getCurrentLocale } from '~adapters/helpers/l10n';
24+
import { isDefined } from '../helpers/types';
25+
import { Measure } from '../types/measures';
2426
import {
2527
RISK_SEVERITY_LABELS,
2628
SCA_RISK_SEVERITY_METRIC_THRESHOLD_KEYS,
@@ -32,6 +34,20 @@ type FormatMessageFunction = IntlShape['formatMessage'];
3234

3335
const HOURS_IN_DAY = 8;
3436

37+
function getLanguagesSortedByNCLOC(measures: Measure[]) {
38+
return (
39+
measures
40+
.flatMap((measure) =>
41+
measure.value?.split(';').map((pair) => {
42+
const [language, count] = pair.split('=');
43+
return { language, count: Number.parseInt(count, 10) };
44+
}),
45+
)
46+
.filter(isDefined)
47+
.sort((a, b) => b.count - a.count) || []
48+
);
49+
}
50+
3551
function noFormatter(value: string | number): string | number {
3652
return value;
3753
}
@@ -326,6 +342,7 @@ function addSpaceIfNeeded(value: string): string {
326342
export {
327343
durationFormatter,
328344
floatFormatter,
345+
getLanguagesSortedByNCLOC,
329346
intFormatter,
330347
levelFormatter,
331348
millisecondsFormatter,

libs/sq-server-commons/src/l10n/default.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2070,6 +2070,7 @@ export const defaultMessages = {
20702070
'architecture.user.promotion.message':
20712071
'You now have Design & Architecture enabled in Early Access, you can start to visualize your codebase, define and verify your architecture. <link>Take me there!</link>',
20722072
'architecture.no_graph_file.message': 'No graph file found for this project.',
2073+
'architecture.unsupported_language.message': 'No supported languages found for this project.',
20732074
'architecture.issues.no_data': 'No issues found',
20742075
'architecture.error.message': "Sorry, Currently a project of this size isn't supported.",
20752076
'architecture.nodes.orphans.label': 'Orphans ({orphansCount})',

libs/sq-server-commons/src/sq-server-adapters/queries/measures.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
import { queryOptions, useQueryClient } from '@tanstack/react-query';
2222
import { getBranchLikeQuery } from '~shared/helpers/branch-like';
23-
import { createQueryHook } from '~shared/queries/common';
23+
import { createQueryHook, StaleTime } from '~shared/queries/common';
2424
import { Measure } from '~shared/types/measures';
2525
import { getMeasuresWithPeriodAndMetrics } from '../../api/measures';
2626
import { BranchLike } from '../../types/branch-like';
@@ -64,6 +64,7 @@ export const useMeasuresComponentQuery = createQueryHook(
6464

6565
return data;
6666
},
67+
staleTime: StaleTime.LONG,
6768
});
6869
},
6970
);

0 commit comments

Comments
 (0)