From b84d545c3592bee5603dbffa54dda230a62380da Mon Sep 17 00:00:00 2001 From: hangy Date: Sun, 22 Dec 2024 16:42:40 +0100 Subject: [PATCH] fix: SonarCloud issues (#11165) Fix a handful of issues reported by SonarCloud, or add a workaround for the issue. --- .sonarcloud.properties | 2 +- html/js/display-list-of-tags.js | 5 ++-- html/js/product-multilingual.js | 17 +++++------ html/js/search.js | 50 ++++++++++++++++----------------- scss/_footer.scss | 4 --- scss/_off.scss | 5 ++-- scss/_product-list.scss | 5 +--- scss/_topbar.scss | 3 -- 8 files changed, 39 insertions(+), 52 deletions(-) diff --git a/.sonarcloud.properties b/.sonarcloud.properties index b233365e90875..90fde573c6990 100644 --- a/.sonarcloud.properties +++ b/.sonarcloud.properties @@ -1,4 +1,4 @@ sonar.sources=cgi,docker,lib,scripts,templates,scss,html/css,html/js,docker-compose.yml,Dockerfile,Dockerfile.frontend,gulpfile.ts,Makefile sonar.tests=tests -sonar.exclusions=scripts/obsolete/**/*,html/css/normalize.css \ No newline at end of file +sonar.exclusions=scripts/obsolete/**/*,html/css/normalize.css,tests/integration/expected_test_results/**/* \ No newline at end of file diff --git a/html/js/display-list-of-tags.js b/html/js/display-list-of-tags.js index 3267a319c32b4..8f6e724721533 100644 --- a/html/js/display-list-of-tags.js +++ b/html/js/display-list-of-tags.js @@ -1,7 +1,7 @@ // This file is part of Product Opener. // // Product Opener -// Copyright (C) 2011-2023 Association Open Food Facts +// Copyright (C) 2011-2024 Association Open Food Facts // Contact: contact@openfoodfacts.org // Address: 21 rue des Iles, 94100 Saint-Maur des Fossés, France // @@ -32,7 +32,8 @@ function displayWorldMap(selector, countries) { const products = lang().products; const direction = getComputedStyle(document.querySelector(selector)).direction; - const map = new jsVectorMap({ + const JsVectorMap = jsVectorMap; // Workaround for SonarQube false positive + const map = new JsVectorMap({ selector: selector, map: "world_merc", visualizeData: { diff --git a/html/js/product-multilingual.js b/html/js/product-multilingual.js index fe1e20b3a332e..ecd00938b3b54 100644 --- a/html/js/product-multilingual.js +++ b/html/js/product-multilingual.js @@ -1,7 +1,7 @@ // This file is part of Product Opener. // // Product Opener -// Copyright (C) 2011-2023 Association Open Food Facts +// Copyright (C) 2011-2024 Association Open Food Facts // Contact: contact@openfoodfacts.org // Address: 21 rue des Iles, 94100 Saint-Maur des Fossés, France // @@ -146,22 +146,19 @@ function select_nutriment(event, ui) { unitElement.show(); percentElement.hide(); - for (let entryIndex = 0; entryIndex < units.length; ++entryIndex) { - const entry = units[entryIndex]; - for (let unitIndex = 0; unitIndex < entry.length; ++unitIndex) { - const unitEntry = entry[unitIndex].toLowerCase(); - if (unitEntry == unit) { + for (const entry of units) { + for (const unitEntry of entry) { + if (unitEntry.toLowerCase() == unit) { const domElement = unitElement[0]; domElement.options.length = 0; // Remove current entries. - for (let itemIndex = 0; itemIndex < entry.length; ++itemIndex) { - const unitValue = entry[itemIndex]; + for (const unitValue of entry) { domElement.options[domElement.options.length] = new Option(unitValue, unitValue, false, unitValue.toLowerCase() == unit); } - + if (ui.item.iu) { domElement.options[domElement.options.length] = new Option('IU', 'IU', false, 'iu' == unit); } - + return; } } diff --git a/html/js/search.js b/html/js/search.js index 8a317889b8111..9c1920bba70d8 100644 --- a/html/js/search.js +++ b/html/js/search.js @@ -1,7 +1,7 @@ // This file is part of Product Opener. // // Product Opener -// Copyright (C) 2011-2023 Association Open Food Facts +// Copyright (C) 2011-2024 Association Open Food Facts // Contact: contact@openfoodfacts.org // Address: 21 rue des Iles, 94100 Saint-Maur des Fossés, France // @@ -18,22 +18,22 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . -function modifySearchCriterion(element, criterion_number){ +function modifySearchCriterion(element, criterion_number) { //Type of criterion - var selects = element.find('select'); - var typeSelect = selects.eq(0); + const selects = element.find('select'); + const typeSelect = selects.eq(0); typeSelect.attr("name", "tagtype_" + criterion_number); typeSelect.attr("id", "tagtype_" + criterion_number); typeSelect.val(); //Contains/Does not contain select - var containsSelect = selects.eq(1); + const containsSelect = selects.eq(1); containsSelect.attr("name", "tag_contains_" + criterion_number); containsSelect.attr("id", "tag_contains_" + criterion_number); containsSelect.val(); //Criterion value - var tagContent = element.find('input'); + const tagContent = element.find('input'); tagContent.attr("name", "tag_" + criterion_number); tagContent.attr("id", "tag_" + criterion_number); tagContent.val(""); @@ -42,33 +42,33 @@ function modifySearchCriterion(element, criterion_number){ } function addSearchCriterion(target, criteria_number) { - var first = $(".criterion-row").first(); + const first = $(".criterion-row").first(); first.parent().append( - modifySearchCriterion(first.clone(), criteria_number) - ); + modifySearchCriterion(first.clone(), criteria_number) + ); // keep it responsive if (Foundation.utils.is_large_up()) { - first.parent().append( - modifySearchCriterion(first.clone(), criteria_number + 1) - ); - } + first.parent().append( + modifySearchCriterion(first.clone(), criteria_number + 1) + ); + } } -(function( $ ){ +(function ($) { //On criterion value change for the last criterion - $(document).on("change", ".criterion-row:last .tag-search-criterion > input", function(e){ - var criterionNumber = parseInt(e.target.name.substr(e.target.name.length - 1), 10); - addSearchCriterion(e.target, criterionNumber + 1); - e.preventDefault(); + $(document).on("change", ".criterion-row:last .tag-search-criterion > input", function (e) { + const criterionNumber = parseInt(e.target.name.substr(e.target.name.length - 1), 10); + addSearchCriterion(e.target, criterionNumber + 1); + e.preventDefault(); - // keep focus on rolling criterion - if (Foundation.utils.is_large_up()) { - $(".criterion-row:nth-last-of-type(2) select:first").focus(); - } else { - $(".criterion-row:last select:first").focus(); - } + // keep focus on rolling criterion + if (Foundation.utils.is_large_up()) { + $(".criterion-row:nth-last-of-type(2) select:first").focus(); + } else { + $(".criterion-row:last select:first").focus(); + } }); -})( jQuery ); +})(jQuery); diff --git a/scss/_footer.scss b/scss/_footer.scss index 967c17cf88092..3cb3422837fea 100644 --- a/scss/_footer.scss +++ b/scss/_footer.scss @@ -6,10 +6,6 @@ background: no-repeat bottom right url(/images/illustrations/footer-orange.svg) } -#footer_block_image_banner_inside { -// @media only screen and (max-width: 100rem) {margin-left:140px;} -} - .tags_links { a { margin-bottom: $inline-list-default-float-list-margin !important; diff --git a/scss/_off.scss b/scss/_off.scss index 92b947d62a8c0..239b31c8e6f31 100644 --- a/scss/_off.scss +++ b/scss/_off.scss @@ -320,6 +320,7 @@ ul.products { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; + line-clamp: 3; height: 50px; overflow: hidden; } @@ -1239,14 +1240,13 @@ $border-pink: #ff6e78; .off-days-banner { background-color: $section-cyan; - // background-image: url('/images/misc/banners/FR.png'); background-size: contain; background-repeat: no-repeat; background-position: center; height: 300px; @media #{$small-only} { background-size: contain; - height: 25vw; ; + height: 25vw; } &__FR { background-image: url('/images/misc/banners/FR.png'); @@ -1318,7 +1318,6 @@ $border-pink: #ff6e78; &__aside{ display: flex; flex-direction: column; - //align-items: center; } &__main-title{ color: $border-pink; diff --git a/scss/_product-list.scss b/scss/_product-list.scss index 9ac92a707b516..d8d053e919af9 100644 --- a/scss/_product-list.scss +++ b/scss/_product-list.scss @@ -110,7 +110,6 @@ $productsGutter:12; .list_product_img_div { height: 144px; margin: 12px; - // margin-top: 6px; } .list_product_img { @@ -131,6 +130,7 @@ $productsGutter:12; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 4; + line-clamp: 4; height: 82px; overflow: hidden; } @@ -184,9 +184,6 @@ $productsGutter:12; #preferences_selected { display: flex; -// flex-direction: column; -// align-items: center; -// justify-content: center; } #show_selection_form { height: auto; diff --git a/scss/_topbar.scss b/scss/_topbar.scss index 262dba39c95d3..f2ea03ecd1067 100644 --- a/scss/_topbar.scss +++ b/scss/_topbar.scss @@ -98,8 +98,6 @@ .button { height: auto; position: relative; - //not sure why top: auto; is added, breaks buttons in the top bar - //top: auto; } } } @@ -227,7 +225,6 @@ height: 2.35rem; &[type="text"] { width: 100%; - //border-color:$white; box-shadow: none; @media #{$topbar-media-query} { width: 180px;