Skip to content

Commit

Permalink
chore: lint and format fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
saikumarrs committed Sep 2, 2024
1 parent 2100e88 commit a7c9795
Show file tree
Hide file tree
Showing 22 changed files with 42 additions and 62 deletions.
3 changes: 1 addition & 2 deletions packages/analytics-js-common/src/utilities/detect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* Determines if the SDK is running inside a chrome extension
* @returns boolean
*/
const isSDKRunningInChromeExtension = (): boolean =>
!!((window as any).chrome && (window as any).chrome.runtime && (window as any).chrome.runtime.id);
const isSDKRunningInChromeExtension = (): boolean => !!(window as any).chrome?.runtime?.id;

export { isSDKRunningInChromeExtension };
2 changes: 1 addition & 1 deletion packages/analytics-js-common/src/utilities/timezone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
const getTimezone = (): string => {
const timezone = new Date().toString().match(/([A-Z]+[+-]\d+)/);
return timezone && timezone[1] ? timezone[1] : 'NA';
return timezone?.[1] ? timezone[1] : 'NA';
};

export { getTimezone };
3 changes: 1 addition & 2 deletions packages/analytics-js-common/src/v1.1/utils/notifyError.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import { ERROR_REPORTING_SERVICE_GLOBAL_KEY_NAME } from './constants';
* @param {Error} error Error instance from handled error
*/
const notifyError = error => {
const errorReportingClient =
window.RudderStackGlobals && window.RudderStackGlobals[ERROR_REPORTING_SERVICE_GLOBAL_KEY_NAME];
const errorReportingClient = window.RudderStackGlobals?.[ERROR_REPORTING_SERVICE_GLOBAL_KEY_NAME];
if (errorReportingClient && error instanceof Error) {
errorReportingClient.notify(error);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class AdobeAnalytics {
// The referrer variable overrides the automatically collected referrer in reports.
let referrer;
let url;
if (rudderElement.message.context && rudderElement.message.context.page) {
if (rudderElement.message.context?.page) {
referrer = rudderElement.message.context.page.referrer;
url = rudderElement.message.context.page.url;
} else if (rudderElement.message.properties) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ const updateWindowSKeys = (value, key) => {
const updateCommonWindowSKeys = (rudderElement, pageName) => {
const { properties, type, context } = rudderElement.message;
let campaign;
if (context && context.campaign) {
if (context?.campaign) {
campaign = context.campaign.name;
} else {
campaign = properties.campaign;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class Amplitude {
}

isLoaded() {
return Boolean(window.amplitude && window.amplitude.getDeviceId());
return Boolean(window.amplitude?.getDeviceId());
}

isReady() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class FacebookPixel {
}

isLoaded() {
return !!(window.fbq && window.fbq.callMethod);
return !!window.fbq?.callMethod;
}

isReady() {
Expand Down Expand Up @@ -266,7 +266,7 @@ class FacebookPixel {
} else if (event === 'Checkout Started') {
let contentCategory = category;
const { contents, contentIds } = getProductsContentsAndContentIds(products, quantity, price);
if (Array.isArray(products) && !contentCategory && products[0] && products[0].category) {
if (Array.isArray(products) && !contentCategory && products[0]?.category) {
contentCategory = products[0].category;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ function getConversionData(eventTypeConversions, eventName, defaultPageConversio

function newCustomerAcquisitionReporting(properties) {
const updatedProperties = { ...properties }; // create a copy of properties object
if (updatedProperties && updatedProperties.newCustomer) {
if (updatedProperties?.newCustomer) {
updatedProperties.new_customer = updatedProperties.newCustomer;
delete updatedProperties.newCustomer;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Heap {
}

isLoaded() {
return !!(window.heap && window.heap.appid);
return !!window.heap?.appid;
}

isReady() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class Klaviyo {

identify(rudderElement) {
const { message } = rudderElement;
if (!(message.context && message.context.traits)) {
if (!message.context?.traits) {
logger.error('user traits not present');
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class Optimizely {
if (!state) {
return undefined;
}
const referrer = state.getRedirectInfo() && state.getRedirectInfo().referrer;
const referrer = state.getRedirectInfo()?.referrer;
if (!referrer) {
return undefined;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Qualtrics {
}

isLoaded() {
return !!(window._qsie && window.QSI && window.QSI.API);
return !!(window._qsie && window.QSI?.API);
}

isReady() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class VWO {
logger.error('[VWO] track:: event name is required');
return;
}
const properties = (rudderElement.message && rudderElement.message.properties) || {};
const properties = rudderElement.message?.properties || {};
window.VWO = window.VWO || [];
if (eventName === 'Order Completed') {
const total = rudderElement.message.properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ function getEventMappingFromConfig(event, eventsHashmap) {
function getDestinationExternalID(message, type) {
let externalIdArray = null;
let destinationExternalId = null;
if (message.context && message.context.externalId) {
if (message.context?.externalId) {
externalIdArray = message.context.externalId;
}
if (externalIdArray && Array.isArray(externalIdArray)) {
Expand Down
4 changes: 2 additions & 2 deletions packages/analytics-js-integrations/src/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { logger } from '@rudderstack/analytics-js-common/v1.1/utils/logUtil';
* @param {*} inURL
*/
function removeTrailingSlashes(inURL) {
return inURL && inURL.endsWith('/') ? inURL.replace(/\/+$/, '') : inURL;
return inURL?.endsWith('/') ? inURL.replace(/\/+$/, '') : inURL;
}

/**
Expand Down Expand Up @@ -51,7 +51,7 @@ function getRevenue(properties, eventName) {
const orderCompletedRegExp = /^[ _]?completed[ _]?order[ _]?|^[ _]?order[ _]?completed[ _]?$/i;

// it's always revenue, unless it's called during an order completion.
if (!revenue && eventName && eventName.match(orderCompletedRegExp)) {
if (!revenue && eventName?.match(orderCompletedRegExp)) {
revenue = total;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/analytics-js-plugins/.size-limit.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ export default [
name: 'Plugins - Modern - CDN',
path: 'dist/cdn/modern/plugins/rsa-plugins-*.min.js',
limit: '7.5 KiB',
}
},
];
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ const isDestinationSDKMounted = (
logger?: ILogger,
): boolean =>
Boolean(
(globalThis as any)[destSDKIdentifier] &&
(globalThis as any)[destSDKIdentifier][sdkTypeName] &&
(globalThis as any)[destSDKIdentifier][sdkTypeName].prototype &&
(globalThis as any)[destSDKIdentifier]?.[sdkTypeName]?.prototype &&
typeof (globalThis as any)[destSDKIdentifier][sdkTypeName].prototype.constructor !==
'undefined',
);
Expand Down
38 changes: 15 additions & 23 deletions packages/analytics-v1.1/src/core/analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,7 @@ class Analytics {
*/
integrationSDKLoaded(pluginName, modName) {
return (
window[pluginName] &&
window[pluginName][modName] &&
window[pluginName][modName].prototype &&
window[pluginName]?.[modName]?.prototype &&
typeof window[pluginName][modName].prototype.constructor !== 'undefined'
);
}
Expand Down Expand Up @@ -275,7 +273,7 @@ class Analytics {
try {
const cookieConsent = CookieConsentFactory.initialize(this.cookieConsentOptions);
// Fetch denied consent group Ids and pass it to cloud mode
this.deniedConsentIds = cookieConsent && cookieConsent.getDeniedList();
this.deniedConsentIds = cookieConsent?.getDeniedList();
// If cookie consent object is return we filter according to consents given by user
// else we do not consider any filtering for cookie consent.
this.clientIntegrations = this.clientIntegrations.filter(
Expand Down Expand Up @@ -1094,7 +1092,7 @@ class Analytics {

getPageProperties(properties, options) {
const defaultPageProperties = getDefaultPageProperties();
const optionPageProperties = (options && options.page) || {};
const optionPageProperties = options?.page || {};
for (const key in defaultPageProperties) {
if (properties[key] === undefined) {
properties[key] = optionPageProperties[key] || defaultPageProperties[key];
Expand All @@ -1108,8 +1106,7 @@ class Analytics {
const defaultPageProperties = getDefaultPageProperties();
const contextPageProperties = {};
for (const key in defaultPageProperties) {
contextPageProperties[key] =
properties && properties[key] ? properties[key] : defaultPageProperties[key];
contextPageProperties[key] = properties?.[key] ? properties[key] : defaultPageProperties[key];
}
return contextPageProperties;
}
Expand Down Expand Up @@ -1209,7 +1206,7 @@ class Analytics {
options = serverUrl;
serverUrl = null;
}
if (options && options.logLevel) {
if (options?.logLevel) {
this.logLevel = options.logLevel;
logger.setLogLevel(options.logLevel);
}
Expand All @@ -1219,16 +1216,15 @@ class Analytics {
if (!this.storage || Object.keys(this.storage).length === 0) {
throw Error('Cannot proceed as no storage is available');
}
if (options && options.cookieConsentManager)
this.cookieConsentOptions = options.cookieConsentManager;
if (options?.cookieConsentManager) this.cookieConsentOptions = options.cookieConsentManager;

this.writeKey = writeKey;
this.serverUrl = serverUrl;
this.options = options;

let storageOptions = {};

if (options && options.setCookieDomain) {
if (options?.setCookieDomain) {
storageOptions = { ...storageOptions, domain: options.setCookieDomain };
}

Expand Down Expand Up @@ -1260,28 +1256,24 @@ class Analytics {
}, this.uaChTrackLevel);
}

if (options && options.integrations) {
if (options?.integrations) {
Object.assign(this.loadOnlyIntegrations, options.integrations);
transformToRudderNames(this.loadOnlyIntegrations);
}

this.useGlobalIntegrationsConfigInEvents =
options && options.useGlobalIntegrationsConfigInEvents === true;

if (options && options.sendAdblockPage) {
if (options?.sendAdblockPage) {
this.sendAdblockPage = true;
}
if (
options &&
options.sendAdblockPageOptions &&
typeof options.sendAdblockPageOptions === 'object'
) {
if (options?.sendAdblockPageOptions && typeof options.sendAdblockPageOptions === 'object') {
this.sendAdblockPageOptions = options.sendAdblockPageOptions;
}
// Session initialization
this.uSession.initialize(options);

if (options && options.clientSuppliedCallbacks) {
if (options?.clientSuppliedCallbacks) {
// convert to rudder recognized method names
const transformedCallbackMapping = {};
Object.keys(this.methodToCallbackMapping).forEach(methodName => {
Expand All @@ -1297,7 +1289,7 @@ class Analytics {
this.registerCallbacks(true);
}

if (options && options.loadIntegration != undefined) {
if (options?.loadIntegration != undefined) {
this.loadIntegration = !!options.loadIntegration;
}

Expand All @@ -1322,10 +1314,10 @@ class Analytics {
this.destSDKBaseURL = getIntegrationsCDNPath(
this.version,
this.lockIntegrationsVersion,
options && options.destSDKBaseURL,
options?.destSDKBaseURL,
);

if (options && options.getSourceConfig) {
if (options?.getSourceConfig) {
if (typeof options.getSourceConfig !== 'function') {
handleError(new Error('option "getSourceConfig" must be a function'));
} else {
Expand All @@ -1341,7 +1333,7 @@ class Analytics {
}

let configUrl = getConfigUrl(writeKey, this.lockIntegrationsVersion);
if (options && options.configUrl) {
if (options?.configUrl) {
configUrl = getUserProvidedConfigUrl(options.configUrl, configUrl);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class Ketch {
Object.entries(consentObj).forEach(e => {
const purposeCode = e[0];
const purposeValue = e[1];
if (purposeValue && purposeValue.status) {
if (purposeValue?.status) {
consent[purposeCode] = purposeValue.status === 'granted';
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,7 @@ const getReleaseStage = () => {

const isValidVersion = globalLibInstance => {
// For version 7
let version =
globalLibInstance &&
globalLibInstance._client &&
globalLibInstance._client._notifier &&
globalLibInstance._client._notifier.version;
let version = globalLibInstance?._client?._notifier?.version;

// For versions older than 7
if (!version) {
Expand All @@ -55,7 +51,7 @@ const isValidVersion = globalLibInstance => {
return false;
},
});
version = tempInstance.notifier && tempInstance.notifier.version;
version = tempInstance.notifier?.version;
tempInstance = undefined;
}

Expand Down Expand Up @@ -123,10 +119,7 @@ class BugsnagProvider {
*/
init() {
// Return if RS Bugsnag instance is already initialized or should not init
if (
window.RudderStackGlobals &&
window.RudderStackGlobals[ERROR_REPORTING_SERVICE_GLOBAL_KEY_NAME]
) {
if (window.RudderStackGlobals?.[ERROR_REPORTING_SERVICE_GLOBAL_KEY_NAME]) {
return;
}

Expand Down
7 changes: 3 additions & 4 deletions packages/analytics-v1.1/src/utils/EventRepository.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class EventRepository {
initialize(writeKey, url, options) {
let queueOptions = {};
let targetUrl = removeTrailingSlashes(url);
if (options && options.useBeacon && navigator.sendBeacon) {
if (options?.useBeacon && navigator.sendBeacon) {
if (
options.beaconQueueOptions &&
options.beaconQueueOptions != null &&
Expand All @@ -37,14 +37,13 @@ class EventRepository {
targetUrl = `${targetUrl}/beacon/v1/batch`;
this.queue = new BeaconQueue();
} else {
if (options && options.useBeacon) {
if (options?.useBeacon) {
logger.info(
'[EventRepository] sendBeacon feature not available in this browser :: fallback to XHR',
);
}
if (
options &&
options.queueOptions &&
options?.queueOptions &&
options.queueOptions != null &&
typeof options.queueOptions === 'object'
) {
Expand Down
2 changes: 1 addition & 1 deletion packages/analytics-v1.1/src/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
* @param {*} inURL
*/
function removeTrailingSlashes(inURL) {
return inURL && inURL.endsWith('/') ? inURL.replace(/\/+$/, '') : inURL;
return inURL?.endsWith('/') ? inURL.replace(/\/+$/, '') : inURL;
}

/**
Expand Down

0 comments on commit a7c9795

Please sign in to comment.