Skip to content

Commit

Permalink
[No Ticket] Format the code and add linting rules (#104)
Browse files Browse the repository at this point in the history
* [No Ticket] Format the code and add linting rules

* readd comment
  • Loading branch information
mschuwalow authored Feb 2, 2023
1 parent 454a538 commit c70baf2
Show file tree
Hide file tree
Showing 43 changed files with 347 additions and 332 deletions.
25 changes: 0 additions & 25 deletions .eslintrc.js

This file was deleted.

59 changes: 59 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"root": true,
"env": {
"browser": true,
"commonjs": true,
"es6": true,
"node": true,
"mocha": true
},
"plugins": [
"wdio",
"@typescript-eslint",
"typescript-formatter"
],
"extends": [
"standard",
"plugin:wdio/recommended",
"plugin:@typescript-eslint/recommended"
],
"globals": {},
"rules": {
"semi": "off", // handled by typescript-formatter/format
"space-before-function-paren": "off", // handled by typescript-formatter/format
"indent": ["error", 2],
"@typescript-eslint/ban-ts-comment": "off",
"@typescript-eslint/no-explicit-any": "error",
"typescript-formatter/format": [
"error",
{
"baseIndentSize": 0,
"indentSize": 2,
"tabSize": 2,
"newLineCharacter": "\n",
"convertTabsToSpaces": true,
"indentStyle": 2,
"trimTrailingWhitespace": true,
"insertSpaceAfterCommaDelimiter": true,
"insertSpaceAfterSemicolonInForStatements": true,
"insertSpaceBeforeAndAfterBinaryOperators": true,
"insertSpaceAfterConstructor": true,
"insertSpaceAfterKeywordsInControlFlowStatements": true,
"insertSpaceAfterFunctionKeywordForAnonymousFunctions": true,
"insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis": false,
"insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets": false,
"insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces": true,
"insertSpaceAfterOpeningAndBeforeClosingEmptyBraces": false,
"insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces": false,
"insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces": false,
"insertSpaceAfterTypeAssertion": false,
"insertSpaceBeforeFunctionParenthesis": false,
"placeOpenBraceOnNewLineForFunctions": false,
"placeOpenBraceOnNewLineForControlBlocks": false,
"insertSpaceBeforeTypeAnnotation": false,
"indentMultiLineObjectLiteralBeginningOnBlankLine": false,
"semicolons": "remove"
}
]
}
}
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.1",
"eslint-plugin-typescript-formatter": "0.0.2",
"eslint-plugin-wdio": "^7.18.0",
"express": "^4.17.1",
"fs-extra": "^9.0.1",
Expand Down
2 changes: 1 addition & 1 deletion src/config-validators/remove-invalid-pairs.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { EventBus, LiveConnectConfig } from '../types'

export function removeInvalidPairs (config: LiveConnectConfig, eventBus: EventBus): LiveConnectConfig {
export function removeInvalidPairs(config: LiveConnectConfig, eventBus: EventBus): LiveConnectConfig {
if (config && config.appId && config.distributorId) {
const distributorId = config.distributorId
delete config.distributorId
Expand Down
4 changes: 2 additions & 2 deletions src/enrichers/identifiers-nohash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { safeToString, isArray, trim } from '../utils/types'
import { EventBus, RetrievedIdentifier, State } from '../types'
import { MinimalStorageHandler } from '../handlers/storage-handler'

export function enrich (state: State, storageHandler: MinimalStorageHandler, eventBus: EventBus): State {
export function enrich(state: State, storageHandler: MinimalStorageHandler, eventBus: EventBus): State {
try {
return _parseIdentifiersToResolve(state, storageHandler)
} catch (e) {
Expand All @@ -12,7 +12,7 @@ export function enrich (state: State, storageHandler: MinimalStorageHandler, eve
}
}

function _parseIdentifiersToResolve (state: State, storageHandler: MinimalStorageHandler): State {
function _parseIdentifiersToResolve(state: State, storageHandler: MinimalStorageHandler): State {
state.identifiersToResolve = state.identifiersToResolve || []
const cookieNames = isArray(state.identifiersToResolve) ? state.identifiersToResolve : safeToString(state.identifiersToResolve).split(',')
const identifiers: RetrievedIdentifier[] = []
Expand Down
8 changes: 4 additions & 4 deletions src/enrichers/identifiers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { safeToString, isString, isArray } from '../utils/types'
import { EventBus, HashedEmail, State, RetrievedIdentifier } from '../types'
import { MinimalStorageHandler } from '../handlers/storage-handler'

export function enrich (state: State, storageHandler: MinimalStorageHandler, eventBus: EventBus): State {
export function enrich(state: State, storageHandler: MinimalStorageHandler, eventBus: EventBus): State {
try {
return _getIdentifiers(_parseIdentifiersToResolve(state), storageHandler)
} catch (e) {
Expand All @@ -14,7 +14,7 @@ export function enrich (state: State, storageHandler: MinimalStorageHandler, eve
}
}

function _parseIdentifiersToResolve (state: State): string[] {
function _parseIdentifiersToResolve(state: State): string[] {
let cookieNames: string[] = []
if (state.identifiersToResolve) {
if (isArray(state.identifiersToResolve)) {
Expand All @@ -29,7 +29,7 @@ function _parseIdentifiersToResolve (state: State): string[] {
return cookieNames
}

function _getIdentifiers (cookieNames: string[], storageHandler: MinimalStorageHandler): State {
function _getIdentifiers(cookieNames: string[], storageHandler: MinimalStorageHandler): State {
const identifiers: RetrievedIdentifier[] = []
let hashes: HashedEmail[] = []
for (let i = 0; i < cookieNames.length; i++) {
Expand All @@ -50,7 +50,7 @@ function _getIdentifiers (cookieNames: string[], storageHandler: MinimalStorageH
}
}

function _deduplicateHashes (hashes: HashedEmail[]): HashedEmail[] {
function _deduplicateHashes(hashes: HashedEmail[]): HashedEmail[] {
const seen = new Set<string>()
const result: HashedEmail[] = []
for (let i = 0; i < hashes.length; i++) {
Expand Down
5 changes: 1 addition & 4 deletions src/enrichers/page.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import { State } from '../types'
import { getPage, getReferrer, getContextElements } from '../utils/page'

/**
* @private
*/
let _currentPage: State | null = null

export function enrich (state: State): State {
export function enrich(state: State): State {
if (_currentPage) {
return _currentPage
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/enrichers/people-verified.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { PEOPLE_VERIFIED_LS_ENTRY } from '../utils/consts'
import { EventBus, State } from '../types'
import { MinimalStorageHandler } from '../handlers/storage-handler'

export function enrich (state: State, storageHandler: MinimalStorageHandler, eventBus: EventBus): State {
export function enrich(state: State, storageHandler: MinimalStorageHandler, eventBus: EventBus): State {
try {
return { peopleVerifiedId: state.peopleVerifiedId || storageHandler.getDataFromLocalStorage(PEOPLE_VERIFIED_LS_ENTRY) || undefined }
} catch (e) {
Expand Down
2 changes: 1 addition & 1 deletion src/enrichers/privacy-config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { State } from '../types'
import { isNonEmpty } from '../utils/types'

export function enrich (state: State): State {
export function enrich(state: State): State {
if (isNonEmpty(state) && isNonEmpty(state.gdprApplies)) {
const privacyMode = !!state.gdprApplies
return {
Expand Down
8 changes: 4 additions & 4 deletions src/events/error-pixel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const _defaultReturn: State = {
}
}

function _asInt (field: unknown): number | undefined {
function _asInt(field: unknown): number | undefined {
try {
const intValue = (field as number) * 1
return isNaN(intValue) ? undefined : intValue
Expand All @@ -24,7 +24,7 @@ function _asInt (field: unknown): number | undefined {
}
}

function _truncate (value: unknown): string | undefined {
function _truncate(value: unknown): string | undefined {
try {
if (isString(value) && value.length && value.length > MAX_ERROR_FIELD_LENGTH) {
return `${value.substr(0, MAX_ERROR_FIELD_LENGTH)}...`
Expand All @@ -35,7 +35,7 @@ function _truncate (value: unknown): string | undefined {
}
}

export function asErrorDetails (e: unknown): State {
export function asErrorDetails(e: unknown): State {
if (isRecord(e)) {
return {
errorDetails: {
Expand All @@ -52,7 +52,7 @@ export function asErrorDetails (e: unknown): State {
}
}

export function register (state: State, callHandler: CallHandler, eventBus: EventBus): void {
export function register(state: State, callHandler: CallHandler, eventBus: EventBus): void {
try {
const pixelSender = new PixelSender(state, callHandler, eventBus)

Expand Down
10 changes: 5 additions & 5 deletions src/events/event-bus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import * as C from '../utils/consts'
import { isFunction } from '../utils/types'
import { EventBus } from '../types'

function initBus (size?: number): EventBus {
function initBus(size?: number): EventBus {
if (typeof size === 'number' && size >= 0) {
return new ReplayEmitter(size)
} else {
return new ReplayEmitter(5)
}
}

function extendBusIfNeeded (bus: EventBus) {
function extendBusIfNeeded(bus: EventBus) {
if (isFunction(bus.emitErrorWithMessage) && isFunction(bus.emitError)) {
return
}
Expand All @@ -27,11 +27,11 @@ function extendBusIfNeeded (bus: EventBus) {
}
}

export function LocalEventBus (size = 5) {
export function LocalEventBus(size = 5) {
return initBus(size)
}

export function GlobalEventBus (name: string, size: number, errorCallback: (error: unknown) => void): EventBus {
export function GlobalEventBus(name: string, size: number, errorCallback: (error: unknown) => void): EventBus {
try {
if (!window) {
errorCallback(new Error('Bus can only be attached to the window, which is not present'))
Expand All @@ -47,7 +47,7 @@ export function GlobalEventBus (name: string, size: number, errorCallback: (erro
}
}

export function getAvailableBus (name: string): EventBus {
export function getAvailableBus(name: string): EventBus {
const eventBus = window[name].eventBus || window[C.EVENT_BUS_NAMESPACE]
extendBusIfNeeded(eventBus)
return eventBus
Expand Down
24 changes: 12 additions & 12 deletions src/events/replayemitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import { ErrorDetails, EventBus } from '../types'
import { isObject } from '../utils/types'

interface EventHandler {
callback: (data: unknown) => void;
unbound: (data: unknown) => void;
callback: (data: unknown) => void
unbound: (data: unknown) => void
}

export class ReplayEmitter implements EventBus {
private h: Record<string, EventHandler[]>;
private q: Record<string, unknown[]>;
size: number;
private h: Record<string, EventHandler[]>
private q: Record<string, unknown[]>
size: number

constructor (replaySize: number | string) {
this.size = 5
Expand All @@ -25,7 +25,7 @@ export class ReplayEmitter implements EventBus {
this.q = {}
}

on <F extends ((event: unknown) => void)> (name: string, callback: F, ctx?: ThisParameterType<F>): this {
on<F extends ((event: unknown) => void)>(name: string, callback: F, ctx?: ThisParameterType<F>): this {
const handler: EventHandler = {
callback: callback.bind(ctx),
unbound: callback
Expand All @@ -41,7 +41,7 @@ export class ReplayEmitter implements EventBus {
return this
}

once <F extends ((event: unknown) => void)> (name: string, callback: F, ctx?: ThisParameterType<F>): this {
once<F extends ((event: unknown) => void)>(name: string, callback: F, ctx?: ThisParameterType<F>): this {
const eventQueue = this.q[name] || []
if (eventQueue.length > 0) {
callback.call(ctx, eventQueue[0])
Expand All @@ -57,7 +57,7 @@ export class ReplayEmitter implements EventBus {
}
}

emit (name: string, event: unknown): this {
emit(name: string, event: unknown): this {
const evtArr = (this.h[name] || []).slice()
let i = 0
const len = evtArr.length
Expand All @@ -75,7 +75,7 @@ export class ReplayEmitter implements EventBus {
return this
}

off (name: string, callback: (event: unknown) => void): this {
off(name: string, callback: (event: unknown) => void): this {
const handlers = this.h[name]
const liveEvents = []

Expand All @@ -94,18 +94,18 @@ export class ReplayEmitter implements EventBus {
return this
}

emitErrorWithMessage (name: string, message: string, exception: unknown): this {
emitErrorWithMessage(name: string, message: string, exception: unknown): this {
const wrappedError = wrapError(name, message, exception)
return this.emit(C.ERRORS_PREFIX, wrappedError)
}

emitError (name: string, exception: unknown): this {
emitError(name: string, exception: unknown): this {
const wrappedError = wrapError(name, undefined, exception)
return this.emit(C.ERRORS_PREFIX, wrappedError)
}
}

export function wrapError (name: string, message?: string, e?: unknown): ErrorDetails {
export function wrapError(name: string, message?: string, e?: unknown): ErrorDetails {
if (isObject(e)) {
let error: ErrorDetails
if ('message' in e && typeof e.message === 'string') {
Expand Down
12 changes: 6 additions & 6 deletions src/handlers/call-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ interface WrappedExternalCallHandler {
onSuccess: (responseText: string, response: unknown) => void,
onError?: (error: unknown) => void,
timeout?: number
) => void;
) => void
pixelGet: (
url: string,
onLoad?: () => void
) => void;
url: string,
onLoad?: () => void
) => void
}

export class CallHandler {
Expand All @@ -28,7 +28,7 @@ export class CallHandler {
wrapper.reportErrors()
}

ajaxGet (
ajaxGet(
url: string,
onSuccess: (responseText: string, response: unknown) => void,
onError?: (error: unknown) => void,
Expand All @@ -37,7 +37,7 @@ export class CallHandler {
this.functions.ajaxGet(url, onSuccess, onError, timeout)
}

pixelGet (
pixelGet(
url: string,
onLoad?: () => void
): void {
Expand Down
Loading

0 comments on commit c70baf2

Please sign in to comment.