Skip to content

Commit

Permalink
fix undefined metric description (#2883)
Browse files Browse the repository at this point in the history
* add new metric description for 'statements'
#2575

* add logic to omit a metric description if it does not exist
#2575

* update CHANGELOG.md
#2575

* refactor getNameAndDescriptionOfMetric
#2575

* add a test to make sure that metrics without a description do not cause a 'undefined' description#2575

Co-authored-by: Charlotte Kehm <charlotte.kehm@outlook.de>
  • Loading branch information
MW-Friedrich and charlotteKehm committed Jul 6, 2022
1 parent e9f6b1c commit fc0061f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Expand Up @@ -11,11 +11,16 @@ and this project adheres to [Semantic Versioning](http://semver.org/)

- Select matching metric combination based on available metrics [#2862](https://github.com/MaibornWolff/codecharta/pull/2862)

### Added 🚀

- Add a description for the statements metric [#2883](https://github.com/MaibornWolff/codecharta/pull/2883)

### Fixed 🐞

- Fix resetting of color range within color settings panel [#2877](https://github.com/MaibornWolff/codecharta/pull/2877)
- Fix resetting of colors in delta mode within color settings panel [#2873](https://github.com/MaibornWolff/codecharta/pull/2873)
- Restore global settings on page load again [#2878](https://github.com/MaibornWolff/codecharta/pull/2878)
- Fix 'undefinded' being displayed as a metric description when no description was available [#2883](https://github.com/MaibornWolff/codecharta/pull/2883)

### Chore 👨‍💻 👩‍💻

Expand Down
Expand Up @@ -126,6 +126,19 @@ describe("suspiciousMetricsHelper", () => {
})
})

it("should get description of metric or else should write nothing", () => {
const metricValuesByLanguage: MetricValuesByLanguage = {}
metricValuesByLanguage["java"] = { rloc: [1, 1, 1, 1], cognitive_complexity: [3, 5, 1, 1] }

const actualAssessmentResults: MetricAssessmentResults = findGoodAndBadMetrics(metricValuesByLanguage, "java")

expect(actualAssessmentResults).toEqual({
suspiciousMetrics: new Map<string, ColorRange>(),
unsuspiciousMetrics: ["rloc (real lines of code)", "cognitive_complexity"],
outliersThresholds: new Map<string, number>()
})
})

it("should calculate suspicious metrics", () => {
const colorRange: ColorRange = {
from: 1,
Expand Down
Expand Up @@ -62,6 +62,14 @@ function compareSuspiciousMetricSuggestionLinks(a: MetricSuggestionParameters, b
return 0
}

function getNameAndDescriptionOfMetric(metricName: string): string {
const metricDescription = metricDescriptions.get(metricName)
if (metricDescription) {
return `${metricName} (${metricDescription})`
}
return `${metricName}`
}

export function findGoodAndBadMetrics(
metricValuesByLanguages: MetricValuesByLanguage,
mainProgrammingLanguage: string
Expand All @@ -84,7 +92,7 @@ export function findGoodAndBadMetrics(
const maxMetricValue = Math.max(...valuesOfMetric)

if (maxMetricValue <= thresholdConfig.percentile70) {
metricAssessmentResults.unsuspiciousMetrics.push(`${metricName} (${metricDescriptions.get(metricName)})`)
metricAssessmentResults.unsuspiciousMetrics.push(getNameAndDescriptionOfMetric(metricName))
} else if (maxMetricValue > thresholdConfig.percentile70) {
metricAssessmentResults.suspiciousMetrics.set(metricName, {
from: thresholdConfig.percentile70,
Expand Down
Expand Up @@ -14,5 +14,6 @@ export const metricDescriptions: Map<string, string> = new Map([
["line_coverage", "number of code lines covered by tests"],
["sonar_code_smells", "number of smells Sonar has identified"],
["avg_code_churn", "average number of lines added or removed from this file"],
["number_of_authors", "number of authors that have edited this file"]
["number_of_authors", "number of authors that have edited this file"],
["statements", "number of statements"]
])

0 comments on commit fc0061f

Please sign in to comment.