Skip to content

Commit

Permalink
fix: SonarCloud issues (#11165)
Browse files Browse the repository at this point in the history
Fix a handful of issues reported by SonarCloud, or add a workaround for
the issue.
  • Loading branch information
hangy authored Dec 22, 2024
1 parent ac175ce commit b84d545
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 52 deletions.
2 changes: 1 addition & 1 deletion .sonarcloud.properties
Original file line number Diff line number Diff line change
@@ -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
sonar.exclusions=scripts/obsolete/**/*,html/css/normalize.css,tests/integration/expected_test_results/**/*
5 changes: 3 additions & 2 deletions html/js/display-list-of-tags.js
Original file line number Diff line number Diff line change
@@ -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
//
Expand Down Expand Up @@ -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: {
Expand Down
17 changes: 7 additions & 10 deletions html/js/product-multilingual.js
Original file line number Diff line number Diff line change
@@ -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
//
Expand Down Expand Up @@ -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;
}
}
Expand Down
50 changes: 25 additions & 25 deletions html/js/search.js
Original file line number Diff line number Diff line change
@@ -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
//
Expand All @@ -18,22 +18,22 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

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("");
Expand All @@ -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);
4 changes: 0 additions & 4 deletions scss/_footer.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 2 additions & 3 deletions scss/_off.scss
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ ul.products {
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 3;
line-clamp: 3;
height: 50px;
overflow: hidden;
}
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -1318,7 +1318,6 @@ $border-pink: #ff6e78;
&__aside{
display: flex;
flex-direction: column;
//align-items: center;
}
&__main-title{
color: $border-pink;
Expand Down
5 changes: 1 addition & 4 deletions scss/_product-list.scss
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ $productsGutter:12;
.list_product_img_div {
height: 144px;
margin: 12px;
// margin-top: 6px;
}

.list_product_img {
Expand All @@ -131,6 +130,7 @@ $productsGutter:12;
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 4;
line-clamp: 4;
height: 82px;
overflow: hidden;
}
Expand Down Expand Up @@ -184,9 +184,6 @@ $productsGutter:12;

#preferences_selected {
display: flex;
// flex-direction: column;
// align-items: center;
// justify-content: center;
}
#show_selection_form {
height: auto;
Expand Down
3 changes: 0 additions & 3 deletions scss/_topbar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,6 @@
.button {
height: auto;
position: relative;
//not sure why top: auto; is added, breaks buttons in the top bar
//top: auto;
}
}
}
Expand Down Expand Up @@ -227,7 +225,6 @@
height: 2.35rem;
&[type="text"] {
width: 100%;
//border-color:$white;
box-shadow: none;
@media #{$topbar-media-query} {
width: 180px;
Expand Down

0 comments on commit b84d545

Please sign in to comment.