Skip to content

Commit

Permalink
Lint files (#1204)
Browse files Browse the repository at this point in the history
* chore: install isml linter

* chore: fix some js files

* fix: adyen configs file

* fix: whitespace
  • Loading branch information
amihajlovski authored Nov 1, 2024
1 parent a7012aa commit 1f4f3a2
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 32 deletions.
4 changes: 0 additions & 4 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -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

3 changes: 1 addition & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ module.exports = {
],
},
],
"import/extensions": ["error", { "js": "never" }],
"import/no-extraneous-dependencies": "off",
"operator-linebreak": "off",
"object-curly-newline": ["error", {
Expand All @@ -96,6 +95,6 @@ module.exports = {
"import/extensions": "off",
"camelcase": "off",
"no-bitwise": "off",
"no-underscore-dangle": "off"
"no-underscore-dangle": "off"
},
};
47 changes: 47 additions & 0 deletions ismllinter.config.js
Original file line number Diff line number Diff line change
@@ -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;
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) => {
Expand All @@ -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 = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const dwsystem = require('dw/system');

const adyenCurrentSite = dwsystem.Site.getCurrent();

function getCustomPreference(field) {
Expand Down Expand Up @@ -61,7 +62,7 @@ const adyenConfigsObj = {
return getCustomPreference('Adyen_klarnaWidget');
},

getAdyenInstallmentsEnabled(){
getAdyenInstallmentsEnabled() {
return getCustomPreference('AdyenInstallments_enabled');
},

Expand Down Expand Up @@ -105,25 +106,28 @@ const adyenConfigsObj = {
return getCustomPreference('Adyen_Frontend_Region').value;
},

getAdyenTokenisationEnabled: function () {
getAdyenTokenisationEnabled() {
return getCustomPreference('AdyenTokenisationEnabled');
},

getAdyenBasketFieldsEnabled() {
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(',')
: [];
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},
};
Expand Down

0 comments on commit 1f4f3a2

Please sign in to comment.