diff --git a/.eslintignore b/.eslintignore index 74f2c2445..e89905a2c 100644 --- a/.eslintignore +++ b/.eslintignore @@ -14,12 +14,8 @@ src/cartridges/app_adyen_SFRA/cartridge/client/default/js/checkout/checkoutSFRA6 src/cartridges/int_adyen_SFRA/cartridge/controllers/middlewares/checkout_services/placeOrder.js src/cartridges/int_adyen_SFRA/cartridge/adyen/webhooks src/cartridges/int_adyen_SFRA/cartridge/adyen/utils/adyenHelper.js -src/cartridges/int_adyen_SFRA/cartridge/adyen/utils/adyenConfigs.js -src/cartridges/int_adyen_SFRA/cartridge/adyen/utils/lineItemHelper.js -src/cartridges/int_adyen_SFRA/cartridge/adyen/scripts/payments/adyenGetOpenInvoiceData.js src/cartridges/int_adyen_SFRA/cartridge/adyen/scripts/payments/adyenTerminalApi.js # Test files -src/cartridges/int_adyen_SFRA/test *.test.js diff --git a/.eslintrc.js b/.eslintrc.js index 62693117b..53718735d 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -83,7 +83,6 @@ module.exports = { ], }, ], - "import/extensions": ["error", { "js": "never" }], "import/no-extraneous-dependencies": "off", "operator-linebreak": "off", "object-curly-newline": ["error", { @@ -96,6 +95,6 @@ module.exports = { "import/extensions": "off", "camelcase": "off", "no-bitwise": "off", - "no-underscore-dangle": "off" + "no-underscore-dangle": "off" }, }; diff --git a/ismllinter.config.js b/ismllinter.config.js new file mode 100644 index 000000000..797e0d83e --- /dev/null +++ b/ismllinter.config.js @@ -0,0 +1,47 @@ +// Please check all available configurations and rules +// at https://www.npmjs.com/package/isml-linter. + +const config = { + rules: { + // Line by line rules; + // 'enforce-isprint' : {}, // Known issue, will be fixed on v6.0.0; + 'enforce-require': {}, + 'no-br': {}, + 'no-git-conflict': {}, + 'no-import-package': {}, + 'no-inline-style': {}, + 'no-isscript': {}, + 'no-space-only-lines': {}, + 'no-tabs': {}, + 'no-trailing-spaces': {}, + 'max-lines': {}, + + // Tree rules; + indent: {}, + 'no-redundant-context': {}, + 'leading-iscontent': {}, + 'max-depth': {}, + 'no-embedded-isml': {}, + 'no-hardcode': {}, + 'no-require-in-loop': {}, + 'one-element-per-line': {}, + 'leading-iscache': {}, + 'no-deprecated-attrs': {}, + 'contextual-attrs': {}, + 'custom-tags': {}, + 'eslint-to-isscript': {}, + 'no-iselse-slash': {}, + 'empty-eof': {}, + 'align-isset': {}, + 'disallow-tags': { + values: ['isscript', 'br', 'style', 'iframe'], + }, + 'enforce-security': {}, + 'strict-void-elements': {}, + + // Other + 'lowercase-filename': {}, + }, +}; + +module.exports = config; diff --git a/package.json b/package.json index f647a5d0c..087263723 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,11 @@ "check-build:sfra": "chmod 755 ./check-build.sh && sh ./check-build.sh SFRA", "check-branch-name": "chmod 755 ./branching.sh && sh ./branching.sh", "prepare": "husky install", - "preinstall": "npx npm-force-resolutions" + "preinstall": "npx npm-force-resolutions", + "init:isml": "./node_modules/.bin/isml-linter --init", + "lint:isml": "./node_modules/.bin/isml-linter", + "build:isml": "./node_modules/.bin/isml-linter --build", + "fix:isml": "./node_modules/.bin/isml-linter --autofix" }, "engines": { "node": ">=14.0" @@ -57,6 +61,7 @@ "eslint-plugin-import": "^2.22.1", "eslint-plugin-prettier": "^5.1.3", "husky": "^8.0.3", + "isml-linter": "^5.43.9", "istanbul": "^0.4.4", "jest": "^29.2.2", "jest-environment-jsdom": "^29.3.1", diff --git a/src/cartridges/int_adyen_SFRA/cartridge/adyen/scripts/payments/adyenGetOpenInvoiceData.js b/src/cartridges/int_adyen_SFRA/cartridge/adyen/scripts/payments/adyenGetOpenInvoiceData.js index 9bc59d892..d8a804d32 100644 --- a/src/cartridges/int_adyen_SFRA/cartridge/adyen/scripts/payments/adyenGetOpenInvoiceData.js +++ b/src/cartridges/int_adyen_SFRA/cartridge/adyen/scripts/payments/adyenGetOpenInvoiceData.js @@ -15,7 +15,7 @@ * Copyright (c) 2021 Adyen B.V. * This file is open source and available under the MIT license. * See the LICENSE file for more info. - * * + * * */ // script include @@ -24,7 +24,9 @@ const LineItemHelper = require('*/cartridge/adyen/utils/lineItemHelper'); function getLineItems({ Order: order, Basket: basket, addTaxPercentage }) { if (!(order || basket)) return null; const orderOrBasket = order || basket; - const allLineItems = LineItemHelper.getAllLineItems(orderOrBasket.getAllLineItems()); + const allLineItems = LineItemHelper.getAllLineItems( + orderOrBasket.getAllLineItems(), + ); // Add all product and shipping line items to request return allLineItems.map((lineItem) => { @@ -38,15 +40,16 @@ function getLineItems({ Order: order, Basket: basket, addTaxPercentage }) { lineItemObject.amountExcludingTax = itemAmount.getValue().toFixed(); lineItemObject.taxAmount = vatAmount.getValue().toFixed(); - lineItemObject.amountIncludingTax = itemAmount.getValue() + vatAmount.getValue(); + lineItemObject.amountIncludingTax = + itemAmount.getValue() + vatAmount.getValue(); lineItemObject.description = description; lineItemObject.id = id; lineItemObject.quantity = quantity; - lineItemObject.taxPercentage = addTaxPercentage ? ( - new Number(vatPercentage) * 10000 - ).toFixed() : 0; + lineItemObject.taxPercentage = addTaxPercentage + ? (Number(vatPercentage) * 10000).toFixed() + : 0; return lineItemObject; - }) + }); } module.exports = { diff --git a/src/cartridges/int_adyen_SFRA/cartridge/adyen/utils/adyenConfigs.js b/src/cartridges/int_adyen_SFRA/cartridge/adyen/utils/adyenConfigs.js index e5dfe9597..f7120acae 100644 --- a/src/cartridges/int_adyen_SFRA/cartridge/adyen/utils/adyenConfigs.js +++ b/src/cartridges/int_adyen_SFRA/cartridge/adyen/utils/adyenConfigs.js @@ -1,4 +1,5 @@ const dwsystem = require('dw/system'); + const adyenCurrentSite = dwsystem.Site.getCurrent(); function getCustomPreference(field) { @@ -61,7 +62,7 @@ const adyenConfigsObj = { return getCustomPreference('Adyen_klarnaWidget'); }, - getAdyenInstallmentsEnabled(){ + getAdyenInstallmentsEnabled() { return getCustomPreference('AdyenInstallments_enabled'); }, @@ -105,7 +106,7 @@ const adyenConfigsObj = { return getCustomPreference('Adyen_Frontend_Region').value; }, - getAdyenTokenisationEnabled: function () { + getAdyenTokenisationEnabled() { return getCustomPreference('AdyenTokenisationEnabled'); }, @@ -113,17 +114,20 @@ const adyenConfigsObj = { return getCustomPreference('AdyenBasketFieldsEnabled'); }, - getAdyenLevel23DataEnabled: function () { + getAdyenLevel23DataEnabled() { return getCustomPreference('AdyenLevel23DataEnabled'); }, - getAdyenLevel23CommodityCode: function () { + getAdyenLevel23CommodityCode() { return getCustomPreference('AdyenLevel23_CommodityCode'); }, - getAdyenSalePaymentMethods: function () { - return getCustomPreference('AdyenSalePaymentMethods') - ? getCustomPreference('AdyenSalePaymentMethods').replace(/\s/g, '').toString().split(',') + getAdyenSalePaymentMethods() { + const adyenSalePaymentMethods = getCustomPreference( + 'AdyenSalePaymentMethods', + ); + return adyenSalePaymentMethods + ? adyenSalePaymentMethods.replace(/\s/g, '').toString().split(',') : []; }, diff --git a/src/cartridges/int_adyen_SFRA/cartridge/adyen/utils/lineItemHelper.js b/src/cartridges/int_adyen_SFRA/cartridge/adyen/utils/lineItemHelper.js index a4acd1d16..a01eaada7 100644 --- a/src/cartridges/int_adyen_SFRA/cartridge/adyen/utils/lineItemHelper.js +++ b/src/cartridges/int_adyen_SFRA/cartridge/adyen/utils/lineItemHelper.js @@ -99,21 +99,40 @@ const __LineItemHelper = { return new dw.value.Money(0, lineItem.getPrice().getCurrencyCode()); }, + isProductLineItem(lineItem) { + return lineItem instanceof dw.order.ProductLineItem; + }, + + isBonusProductLineItem(lineItem) { + return lineItem.bonusProductLineItem; + }, + + isShippingLineItem(lineItem) { + return lineItem instanceof dw.order.ShippingLineItem; + }, + + isPriceAdjustment(lineItem) { + return lineItem instanceof dw.order.PriceAdjustment; + }, + + isValidLineItem(lineItem) { + return ( + (this.isProductLineItem(lineItem) && + !this.isBonusProductLineItem(lineItem)) || + this.isShippingLineItem(lineItem) || + (this.isPriceAdjustment(lineItem) && + lineItem.promotion.promotionClass === + dw.campaign.Promotion.PROMOTION_CLASS_ORDER) + ); + }, + getAllLineItems(allLineItems) { const lineItems = []; - for (const item in allLineItems) { - const lineItem = allLineItems[item]; - if ( - (lineItem instanceof dw.order.ProductLineItem && - !lineItem.bonusProductLineItem) || - lineItem instanceof dw.order.ShippingLineItem || - (lineItem instanceof dw.order.PriceAdjustment && - lineItem.promotion.promotionClass === - dw.campaign.Promotion.PROMOTION_CLASS_ORDER) - ) { + allLineItems.forEach((lineItem) => { + if (this.isValidLineItem(lineItem)) { lineItems.push(lineItem); } - } + }); return lineItems; }, };