From 9b8f77caee38f23c44723c6f9ca4d1494e73c116 Mon Sep 17 00:00:00 2001 From: Samuel Degueldre Date: Thu, 10 Feb 2022 09:55:44 +0000 Subject: [PATCH] [IMP] test_lint, web, point_of_sale: enable no-unsafe-negation rule This commit also enables the valid-typeof rule which didn't find any issues Part-of: odoo/odoo#84530 --- addons/point_of_sale/static/src/js/db.js | 2 +- addons/web/static/src/legacy/js/core/utils.js | 2 +- odoo/addons/test_lint/tests/eslintrc | 4 +++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/addons/point_of_sale/static/src/js/db.js b/addons/point_of_sale/static/src/js/db.js index cfaff00e5ab..8330b038540 100644 --- a/addons/point_of_sale/static/src/js/db.js +++ b/addons/point_of_sale/static/src/js/db.js @@ -185,7 +185,7 @@ var PosDB = core.Class.extend({ add_products: function(products){ var stored_categories = this.product_by_category_id; - if(!products instanceof Array){ + if(!(products instanceof Array)){ products = [products]; } for(var i = 0, len = products.length; i < len; i++){ diff --git a/addons/web/static/src/legacy/js/core/utils.js b/addons/web/static/src/legacy/js/core/utils.js index 45fe3e48c1f..1de9b50426e 100644 --- a/addons/web/static/src/legacy/js/core/utils.js +++ b/addons/web/static/src/legacy/js/core/utils.js @@ -633,7 +633,7 @@ var utils = Object.assign({ if (typeof(node) === 'string') { return sindent + node.replace(/&/g, '&').replace(//g, '>').replace(/"/g, '"'); - } else if (typeof(node.tag) !== 'string' || !node.children instanceof Array || !node.attrs instanceof Object) { + } else if (typeof(node.tag) !== 'string' || node.children && !(node.children instanceof Array) || node.attrs && !(node.attrs instanceof Object)) { throw new Error( _.str.sprintf(_t("Node [%s] is not a JSONified XML node"), JSON.stringify(node))); diff --git a/odoo/addons/test_lint/tests/eslintrc b/odoo/addons/test_lint/tests/eslintrc index 66c7c6a5687..c0a1e623670 100644 --- a/odoo/addons/test_lint/tests/eslintrc +++ b/odoo/addons/test_lint/tests/eslintrc @@ -13,7 +13,9 @@ "no-restricted-globals": ["error", "event", "self"], "no-const-assign": ["error"], "no-debugger": ["error"], - "no-dupe-class-members": ["error"] + "no-dupe-class-members": ["error"], + "no-unsafe-negation": ["error"], + "valid-typeof": ["error"] }, "globals": { "owl": "readonly",