aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorGrégoire Aubert <gregoire.aubert@sonarsource.com>2017-05-12 15:05:28 +0200
committerGrégoire Aubert <gregoire.aubert@sonarsource.com>2017-05-12 16:14:43 +0200
commitc8bfae074f6ef3fd1b628981d8c1d9e7da3b29f4 (patch)
treeafe12e64b6cedd82e576f9ae8a64bbf67e968e2f /server
parent218182c4c4d7ebbbf41e9cbfd8d7688cd411a82f (diff)
downloadsonarqube-c8bfae074f6ef3fd1b628981d8c1d9e7da3b29f4.tar.gz
sonarqube-c8bfae074f6ef3fd1b628981d8c1d9e7da3b29f4.zip
Remove unused round option in measures helper
Diffstat (limited to 'server')
-rw-r--r--server/sonar-web/src/main/js/helpers/__tests__/measures-test.js16
-rw-r--r--server/sonar-web/src/main/js/helpers/measures.js43
2 files changed, 18 insertions, 41 deletions
diff --git a/server/sonar-web/src/main/js/helpers/__tests__/measures-test.js b/server/sonar-web/src/main/js/helpers/__tests__/measures-test.js
index 46d81f7f0a6..d36a63740eb 100644
--- a/server/sonar-web/src/main/js/helpers/__tests__/measures-test.js
+++ b/server/sonar-web/src/main/js/helpers/__tests__/measures-test.js
@@ -47,8 +47,6 @@ describe('#formatMeasure()', () => {
expect(formatMeasure(1529, 'INT')).toBe('1,529');
expect(formatMeasure(10000, 'INT')).toBe('10,000');
expect(formatMeasure(1234567890, 'INT')).toBe('1,234,567,890');
- expect(formatMeasure(1028.5, 'INT', { round: Math.floor })).toBe('1,028');
- expect(formatMeasure(1028.5, 'INT', { round: Math.ceil })).toBe('1,029');
});
it('should format SHORT_INT', () => {
@@ -60,8 +58,6 @@ describe('#formatMeasure()', () => {
expect(formatMeasure(10000, 'SHORT_INT')).toBe('10k');
expect(formatMeasure(10678, 'SHORT_INT')).toBe('11k');
expect(formatMeasure(1234567890, 'SHORT_INT')).toBe('1b');
- expect(formatMeasure(1529, 'SHORT_INT', { round: Math.ceil })).toBe('1.6k');
- expect(formatMeasure(1589, 'SHORT_INT', { round: Math.floor })).toBe('1.5k');
});
it('should format FLOAT', () => {
@@ -81,14 +77,6 @@ describe('#formatMeasure()', () => {
expect(formatMeasure(0.12, 'FLOAT')).toBe('0.12');
expect(formatMeasure(0.12345, 'FLOAT')).toBe('0.12345');
expect(formatMeasure(0.123456, 'FLOAT')).toBe('0.12346');
- expect(formatMeasure(0.123451, 'FLOAT', { round: Math.ceil })).toBe('0.12346');
- expect(formatMeasure(0.123458, 'FLOAT', { round: Math.floor })).toBe('0.12345');
- expect(formatMeasure(0.12345, 'FLOAT', { decimals: 1 })).toBe('0.1');
- expect(formatMeasure(0.16789, 'FLOAT', { decimals: 1 })).toBe('0.2');
- expect(formatMeasure(0.123456, 'FLOAT', { decimals: 5 })).toBe('0.12346');
- expect(formatMeasure(0.1234567, 'FLOAT', { decimals: 6 })).toBe('0.123457');
- expect(formatMeasure(0.12345, 'FLOAT', { decimals: 0 })).toBe('0.12345');
- expect(formatMeasure(0.16789, 'FLOAT', { decimals: 1, round: Math.floor })).toBe('0.1');
});
it('should format PERCENT', () => {
@@ -98,10 +86,8 @@ describe('#formatMeasure()', () => {
expect(formatMeasure(1.34, 'PERCENT')).toBe('1.3%');
expect(formatMeasure(50.89, 'PERCENT')).toBe('50.9%');
expect(formatMeasure(100.0, 'PERCENT')).toBe('100%');
- expect(formatMeasure(50.89, 'PERCENT', { round: Math.floor })).toBe('50.8%');
- expect(formatMeasure(50.83, 'PERCENT', { round: Math.ceil })).toBe('50.9%');
+ expect(formatMeasure(50.89, 'PERCENT', { decimals: 0 })).toBe('50.9%');
expect(formatMeasure(50.89, 'PERCENT', { decimals: 1 })).toBe('50.9%');
- expect(formatMeasure(50.89, 'PERCENT', { decimals: 1, round: Math.floor })).toBe('50.8%');
expect(formatMeasure(50.89, 'PERCENT', { decimals: 2 })).toBe('50.89%');
expect(formatMeasure(50.89, 'PERCENT', { decimals: 3 })).toBe('50.890%');
});
diff --git a/server/sonar-web/src/main/js/helpers/measures.js b/server/sonar-web/src/main/js/helpers/measures.js
index 01c3c43a3ee..b61bdd143e6 100644
--- a/server/sonar-web/src/main/js/helpers/measures.js
+++ b/server/sonar-web/src/main/js/helpers/measures.js
@@ -140,10 +140,7 @@ function getVariationFormatter(type) {
* Formatters
*/
-function genericFormatter(value, formatValue, options = {}) {
- if (options.round) {
- return numeral(value).format(formatValue, options.round);
- }
+function genericFormatter(value, formatValue) {
return numeral(value).format(formatValue);
}
@@ -155,15 +152,15 @@ function emptyFormatter() {
return null;
}
-function intFormatter(value, options) {
- return genericFormatter(value, '0,0', options);
+function intFormatter(value) {
+ return genericFormatter(value, '0,0');
}
-function intVariationFormatter(value, options) {
- return genericFormatter(value, '+0,0', options);
+function intVariationFormatter(value) {
+ return genericFormatter(value, '+0,0');
}
-function shortIntFormatter(value, options) {
+function shortIntFormatter(value) {
let format = '0,0';
if (value >= 1000) {
format = '0.[0]a';
@@ -171,42 +168,36 @@ function shortIntFormatter(value, options) {
if (value >= 10000) {
format = '0a';
}
- return genericFormatter(value, format, options);
+ return genericFormatter(value, format);
}
-function shortIntVariationFormatter(value, options) {
- const formatted = shortIntFormatter(Math.abs(value), options);
+function shortIntVariationFormatter(value) {
+ const formatted = shortIntFormatter(Math.abs(value));
return value < 0 ? `-${formatted}` : `+${formatted}`;
}
-function floatFormatter(value, options = {}) {
- if (options.decimals) {
- return genericFormatter(value, `0,0.${'0'.repeat(options.decimals)}`, options);
- }
- return genericFormatter(value, '0,0.0[0000]', options);
+function floatFormatter(value) {
+ return genericFormatter(value, '0,0.0[0000]');
}
-function floatVariationFormatter(value, options = {}) {
- if (options.decimals) {
- return genericFormatter(value, `+0,0.${'0'.repeat(options.decimals)}`, options);
- }
- return value === 0 ? '+0.0' : genericFormatter(value, '+0,0.0[0000]', options);
+function floatVariationFormatter(value) {
+ return value === 0 ? '+0.0' : genericFormatter(value, '+0,0.0[0000]');
}
function percentFormatter(value, options = {}) {
value = parseFloat(value);
if (options.decimals) {
- return genericFormatter(value / 100, `0,0.${'0'.repeat(options.decimals)}%`, options);
+ return genericFormatter(value / 100, `0,0.${'0'.repeat(options.decimals)}%`);
}
- return value === 100 ? '100%' : genericFormatter(value / 100, '0,0.0%', options);
+ return value === 100 ? '100%' : genericFormatter(value / 100, '0,0.0%');
}
function percentVariationFormatter(value, options = {}) {
value = parseFloat(value);
if (options.decimals) {
- return genericFormatter(value / 100, `+0,0.${'0'.repeat(options.decimals)}%`, options);
+ return genericFormatter(value / 100, `+0,0.${'0'.repeat(options.decimals)}%`);
}
- return value === 0 ? '+0.0%' : genericFormatter(value / 100, '+0,0.0%', options);
+ return value === 0 ? '+0.0%' : genericFormatter(value / 100, '+0,0.0%');
}
function ratingFormatter(value) {