Skip to content

Commit

Permalink
Update Linter and fix linting issues (#2737)
Browse files Browse the repository at this point in the history
  • Loading branch information
sayan-das-in authored Feb 13, 2025
1 parent 078cbaa commit 9c96f4c
Show file tree
Hide file tree
Showing 20 changed files with 210 additions and 153 deletions.
4 changes: 3 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ module.exports = {
'@typescript-eslint/require-await': 'off',
'@typescript-eslint/restrict-plus-operands': 'off',
'@typescript-eslint/restrict-template-expressions': 'off',
'@typescript-eslint/unbound-method': 'off'
'@typescript-eslint/unbound-method': 'off',
'@typescript-eslint/no-unsafe-argument': 'warn',
'@typescript-eslint/no-misused-promises': 'warn'
},
overrides: [
{
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
"@types/express": "^4.17.16",
"@types/jest": "^27.0.0",
"@types/ws": "^8.5.1",
"@typescript-eslint/eslint-plugin": "^4.14.0",
"@typescript-eslint/parser": "^4.14.0",
"@typescript-eslint/eslint-plugin": "^5.1.0",
"@typescript-eslint/parser": "^5.1.0",
"cors": "^2.8.5",
"eslint": "^7.25.0",
"eslint-config-prettier": "^6.15.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ export abstract class MessageSendPerformer<
* populate the logDetails object with the data that should be logged for every message
*/
beforePerform() {
super.beforePerform?.()
void super.beforePerform?.()

//adding common tags to the the tags that will be added to every single metric added via this.stats*
if (this.executeInput.statsContext)
Expand Down
2 changes: 1 addition & 1 deletion packages/actions-shared/src/friendbuy/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ type NotUndefined<T> = T extends undefined ? never : T
/**
* Returns true if the argument is undefined or an empty string, object, or array.
*/
export function isNonEmpty<T extends unknown>(o: T): o is NotUndefined<T> {
export function isNonEmpty<T extends string | object | unknown>(o: T): o is NotUndefined<T> {
if (o === undefined || o === '') {
return false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('Friendbuy.trackCustomEvent', () => {
enabled: true,
subscribe: 'type = "track" and event = "download"',
mapping: Object.fromEntries(
Object.entries(browserTrackCustomEventFields).map(([name, value]) => [name, value.default])
Object.entries(browserTrackCustomEventFields).map(([name, value]) => [name, value.default as any])
)
}
]
Expand Down Expand Up @@ -45,7 +45,7 @@ describe('Friendbuy.trackCustomEvent', () => {
properties: { type: 'application', fileId: 'MyApp', deduplicationId: '1234' }
})

trackCustomEvent.track?.(context1)
await trackCustomEvent.track?.(context1)

expect(window.friendbuyAPI?.push).not.toHaveBeenCalled()
}
Expand All @@ -58,7 +58,7 @@ describe('Friendbuy.trackCustomEvent', () => {
properties: { type: 'application', fileId: 'MyApp', deduplicationId: '1234' }
})

trackCustomEvent.track?.(context2)
await trackCustomEvent.track?.(context2)

expect(window.friendbuyAPI?.push).toHaveBeenNthCalledWith(1, [
'track',
Expand All @@ -82,7 +82,7 @@ describe('Friendbuy.trackCustomEvent', () => {
properties: { type: 'application', fileId: 'MyApp', email, firstName, lastName }
})

trackCustomEvent.track?.(context3)
await trackCustomEvent.track?.(context3)

expect(window.friendbuyAPI?.push).toHaveBeenNthCalledWith(2, [
'track',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ describe('Friendbuy.trackCustomer', () => {
})
// console.log('context1', JSON.stringify(context1, null, 2))

trackCustomer.identify?.(context1)
await trackCustomer.identify?.(context1)

// console.log('trackCustomer request', JSON.stringify(window.friendbuyAPI.push.mock.calls[0], null, 2))
expect(window.friendbuyAPI?.push).toHaveBeenNthCalledWith(1, [
Expand Down Expand Up @@ -126,7 +126,7 @@ describe('Friendbuy.trackCustomer', () => {
}
})

trackCustomer.identify?.(context2)
await trackCustomer.identify?.(context2)

expect(window.friendbuyAPI?.push).toHaveBeenNthCalledWith(2, [
'track',
Expand All @@ -152,7 +152,7 @@ describe('Friendbuy.trackCustomer', () => {
}
})

trackCustomer.identify?.(context3)
await trackCustomer.identify?.(context3)

expect(window.friendbuyAPI?.push).toHaveBeenNthCalledWith(3, [
'track',
Expand All @@ -170,15 +170,15 @@ describe('Friendbuy.trackCustomer', () => {
// enjoined fields are converted
const context4 = new Context({
type: 'identify',
userId: 12345,
userId: 12345 as any,
traits: {
email,
age: '44',
address: { postalCode: 90210 }
address: { postalCode: 90210 } as any
}
})

trackCustomer.identify?.(context4)
await trackCustomer.identify?.(context4)

expect(window.friendbuyAPI?.push).toHaveBeenNthCalledWith(4, [
'track',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('Friendbuy.trackPage', () => {
name: trackPageObject.title,
enabled: true,
subscribe: trackPageDefaultSubscription,
mapping: Object.fromEntries(Object.entries(trackPageFields).map(([name, value]) => [name, value.default]))
mapping: Object.fromEntries(Object.entries(trackPageFields).map(([name, value]) => [name, value.default as any]))
}
]

Expand Down Expand Up @@ -46,7 +46,7 @@ describe('Friendbuy.trackPage', () => {
})
// console.log('context', JSON.stringify(context, null, 2))

trackPage.page?.(context)
await trackPage.page?.(context)

// console.log('trackSignUp request', JSON.stringify(window.friendbuyAPI.push.mock.calls[0], null, 2))
expect(window.friendbuyAPI?.push).toHaveBeenCalledWith([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ beforeEach(async () => {
})

describe('Friendbuy.trackPurchase', () => {
const subscriptions = [
const subscriptions: JSONValue = [
{
partnerAction: 'trackPurchase',
name: trackPurchaseObject.title,
enabled: true,
subscribe: trackPurchaseDefaultSubscription,
mapping: Object.fromEntries(
Object.entries(browserTrackPurchaseFields).map(([name, value]) => [name, value.default])
Object.entries(browserTrackPurchaseFields).map(([name, value]) => [name, value.default as any])
)
}
]
Expand Down Expand Up @@ -62,15 +62,15 @@ describe('Friendbuy.trackPurchase', () => {
// console.log(window.friendbuyAPI)
jest.spyOn(window.friendbuyAPI as any, 'push')

const expectedProducts = products.map((p) => {
const expectedProducts = products.map((p: Record<string, unknown>) => {
p = { sku: 'unknown', name: 'unknown', quantity: 1, ...p }
if (p.image_url) {
p.imageUrl = p.image_url
delete p.image_url
}
return p
})
const amount = expectedProducts.reduce((acc, p) => acc + p.price * p.quantity, 0)
const amount = expectedProducts.reduce((acc, p) => acc + (p.price as number) * (p.quantity as number), 0)

{
// all fields
Expand All @@ -89,15 +89,15 @@ describe('Friendbuy.trackPurchase', () => {
attributionId,
referralCode,
giftCardCodes,
products: products as JSONValue,
products: products as unknown as JSONValue,
email,
name,
friendbuyAttributes
}
})
// console.log('context1', JSON.stringify(context1, null, 2))

trackPurchase.track?.(context1)
await trackPurchase.track?.(context1)

// console.log('trackPurchase request', JSON.stringify(window.friendbuyAPI.push.mock.calls[0], null, 2))
expect(window.friendbuyAPI?.push).toHaveBeenNthCalledWith(1, [
Expand All @@ -117,8 +117,8 @@ describe('Friendbuy.trackPurchase', () => {
},
true
])
expect(window.friendbuyAPI.push.mock.calls[0][0][2].products[1].quantity).toBe(1)
expect(window.friendbuyAPI.push.mock.calls[0][0][2].products[2].imageUrl).toBe(products[2].image_url)
expect((window.friendbuyAPI?.push as any).mock.calls[0][0][2].products[1].quantity).toBe(1)
expect((window.friendbuyAPI?.push as any).mock.calls[0][0][2].products[2].imageUrl).toBe(products[2].image_url)
}

{
Expand All @@ -133,7 +133,7 @@ describe('Friendbuy.trackPurchase', () => {
}
})

trackPurchase.track?.(context2)
await trackPurchase.track?.(context2)

expect(window.friendbuyAPI?.push).toHaveBeenNthCalledWith(2, [
'track',
Expand Down Expand Up @@ -163,7 +163,7 @@ describe('Friendbuy.trackPurchase', () => {
}
})

trackPurchase.track?.(context3)
await trackPurchase.track?.(context3)

expect(window.friendbuyAPI?.push).toHaveBeenNthCalledWith(3, [
'track',
Expand Down Expand Up @@ -192,7 +192,7 @@ describe('Friendbuy.trackPurchase', () => {
}
})

trackPurchase.track?.(context4)
await trackPurchase.track?.(context4)

expect(window.friendbuyAPI?.push).toHaveBeenNthCalledWith(4, [
'track',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('Friendbuy.trackSignUp', () => {
const [trackSignUp] = await friendbuyDestination({
merchantId,
subscriptions
})
} as any)
// console.log('trackSignUp', JSON.stringify(trackSignUp, null, 2), trackSignUp)
expect(trackSignUp).toBeDefined()

Expand Down Expand Up @@ -67,7 +67,7 @@ describe('Friendbuy.trackSignUp', () => {
})
// console.log('context', JSON.stringify(context, null, 2))

trackSignUp.track?.(context)
await trackSignUp.track?.(context)

// console.log('trackSignUp request', JSON.stringify(window.friendbuyAPI.push.mock.calls[0], null, 2))
expect(window.friendbuyAPI?.push).toHaveBeenCalledWith([
Expand Down
Loading

0 comments on commit 9c96f4c

Please sign in to comment.