Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: SonarCloud issues #11165

Merged
merged 6 commits into from
Dec 22, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Loading