aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src/main/js/helpers
diff options
context:
space:
mode:
authorDavid Cho-Lerat <david.cho-lerat@sonarsource.com>2023-03-13 12:35:13 +0100
committersonartech <sonartech@sonarsource.com>2023-03-14 20:03:27 +0000
commitc4e2a351504a92709154992ab1c2963201538d4c (patch)
treec88f89688a387b6d24cdd13230429a821d64033f /server/sonar-web/src/main/js/helpers
parentdd791e68ca7a5b0375e7cba70a2f8f27d4c75c26 (diff)
downloadsonarqube-c4e2a351504a92709154992ab1c2963201538d4c.tar.gz
sonarqube-c4e2a351504a92709154992ab1c2963201538d4c.zip
Fix some code smells in MMF-3035
Diffstat (limited to 'server/sonar-web/src/main/js/helpers')
-rw-r--r--server/sonar-web/src/main/js/helpers/__tests__/colors-test.ts50
-rw-r--r--server/sonar-web/src/main/js/helpers/colors.ts50
2 files changed, 0 insertions, 100 deletions
diff --git a/server/sonar-web/src/main/js/helpers/__tests__/colors-test.ts b/server/sonar-web/src/main/js/helpers/__tests__/colors-test.ts
deleted file mode 100644
index 84667c740d3..00000000000
--- a/server/sonar-web/src/main/js/helpers/__tests__/colors-test.ts
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2023 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-import * as colors from '../colors';
-
-describe('#stringToColor', () => {
- it('should return a color for a text', () => {
- expect(colors.stringToColor('skywalker')).toBe('#97f047');
- });
-});
-
-describe('#isDarkColor', () => {
- it('should be dark', () => {
- expect(colors.isDarkColor('#000000')).toBe(true);
- expect(colors.isDarkColor('#222222')).toBe(true);
- expect(colors.isDarkColor('#000')).toBe(true);
- });
- it('should be light', () => {
- expect(colors.isDarkColor('#FFFFFF')).toBe(false);
- expect(colors.isDarkColor('#CDCDCD')).toBe(false);
- expect(colors.isDarkColor('#FFF')).toBe(false);
- });
-});
-
-describe('#getTextColor', () => {
- it('should return dark color', () => {
- expect(colors.getTextColor('#FFF', 'dark', 'light')).toBe('dark');
- expect(colors.getTextColor('#FFF')).toBe('#222');
- });
- it('should return light color', () => {
- expect(colors.getTextColor('#000', 'dark', 'light')).toBe('light');
- expect(colors.getTextColor('#000')).toBe('#fff');
- });
-});
diff --git a/server/sonar-web/src/main/js/helpers/colors.ts b/server/sonar-web/src/main/js/helpers/colors.ts
deleted file mode 100644
index 932b9c994ba..00000000000
--- a/server/sonar-web/src/main/js/helpers/colors.ts
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2023 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-/* eslint-disable no-bitwise, no-mixed-operators */
-export function stringToColor(str: string) {
- let hash = 0;
- for (let i = 0; i < str.length; i++) {
- hash = str.charCodeAt(i) + ((hash << 5) - hash);
- }
- let color = '#';
- for (let i = 0; i < 3; i++) {
- const value = (hash >> (i * 8)) & 0xff;
- color += ('00' + value.toString(16)).substr(-2);
- }
- return color;
-}
-
-export function isDarkColor(color: string) {
- color = color.substr(1);
- if (color.length === 3) {
- // shortcut notation: #f90
- color = color[0] + color[0] + color[1] + color[1] + color[2] + color[2];
- }
- const rgb = parseInt(color.substr(1), 16);
- const r = (rgb >> 16) & 0xff;
- const g = (rgb >> 8) & 0xff;
- const b = (rgb >> 0) & 0xff;
- const luma = 0.2126 * r + 0.7152 * g + 0.0722 * b;
- return luma < 140;
-}
-
-export function getTextColor(background: string, dark = '#222', light = '#fff') {
- return isDarkColor(background) ? light : dark;
-}