Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
tyiuhc committed Apr 9, 2024
1 parent 537b928 commit 8c172f5
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 19 deletions.
2 changes: 1 addition & 1 deletion packages/experiment-tag/example/build_example.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const fs = require('fs');
const apiKey = 'API_KEY';
const apiKey = 'a6dd847b9d2f03c816d4f3f8458cdc1d';
const initialFlags = `[
{
"key": "test",
Expand Down
2 changes: 0 additions & 2 deletions packages/experiment-tag/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
"homepage": "https://github.com/amplitude/experiment-js-client",
"license": "MIT",
"main": "dist/experiment-tag.umd.js",
"module": "dist/experiment-tag.esm.js",
"es2015": "dist/experiment-tag.es2015.js",
"types": "dist/types/src/index.d.ts",
"publishConfig": {
"access": "public"
Expand Down
4 changes: 3 additions & 1 deletion packages/experiment-tag/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ const getCommonBrowserConfig = (target) => ({
json(),
commonjs(),
typescript({
...(target === 'es2015' ? { target: 'es2015', downlevelIteration: true } : { downlevelIteration: true }),
...(target === 'es2015'
? { target: 'es2015', downlevelIteration: true }
: { downlevelIteration: true }),
declaration: true,
declarationDir: 'dist/types',
include: tsConfig.include,
Expand Down
8 changes: 5 additions & 3 deletions packages/experiment-tag/src/experiment.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Experiment} from '@amplitude/experiment-js-client';
import { Experiment } from '@amplitude/experiment-js-client';

import {
getGlobalScope,
Expand All @@ -16,7 +16,9 @@ export const initializeExperiment = (apiKey: string, initialFlags: string) => {
if (isLocalStorageAvailable()) {
let user = undefined;
try {
user = JSON.parse(globalScope.localStorage.getItem(experimentStorageName) || '{}');
user = JSON.parse(
globalScope.localStorage.getItem(experimentStorageName) || '{}',
);
} catch (error) {
user = {};
}
Expand All @@ -32,7 +34,7 @@ export const initializeExperiment = (apiKey: string, initialFlags: string) => {
}

const urlParams = getUrlParams();
const parsedFlags = JSON.parse(initialFlags) as any[];
const parsedFlags = JSON.parse(initialFlags);

parsedFlags.forEach((flag) => {
if (flag.key in urlParams && urlParams[flag.key] in flag.variants) {
Expand Down
2 changes: 1 addition & 1 deletion packages/experiment-tag/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const urlWithoutParamsAndAnchor = (url: string): string => {
return url.split('?')[0].split('#')[0];
};

export const UUID = function (a?: any): string {
export const UUID = function (a?: number): string {
return a // if the placeholder was passed, return
? // a random number from 0 to 15
(
Expand Down
5 changes: 5 additions & 0 deletions packages/experiment-tag/test/experiment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ describe('initializeExperiment', () => {
document: { referrer: 'referrer' },
history: { pushState: jest.fn() },
};
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
mockGetGlobalScope.mockReturnValue(mockGlobal);
});
Expand Down Expand Up @@ -304,6 +305,7 @@ describe('initializeExperiment', () => {
},
document: { referrer: 'http://test.com' },
};
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
mockGetGlobalScope.mockReturnValue(mockGlobal);

Expand Down Expand Up @@ -382,6 +384,7 @@ describe('initializeExperiment', () => {
document: { referrer: 'referrer' },
history: { pushState: jest.fn() },
};
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
mockGetGlobalScope.mockReturnValue(mockGlobal);

Expand Down Expand Up @@ -465,6 +468,7 @@ describe('initializeExperiment', () => {
document: { referrer: 'referrer' },
history: { pushState: jest.fn() },
};
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
mockGetGlobalScope.mockReturnValue(mockGlobal);

Expand Down Expand Up @@ -545,6 +549,7 @@ describe('initializeExperiment', () => {
document: { referrer: 'referrer' },
history: { pushState: jest.fn() },
};
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
mockGetGlobalScope.mockReturnValue(mockGlobal);

Expand Down
28 changes: 18 additions & 10 deletions packages/experiment-tag/test/util.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import {
getUrlParams,
matchesUrl,
urlWithoutParamsAndAnchor,
} from 'src/util';

const util = require('src/util');
import { getUrlParams, matchesUrl, urlWithoutParamsAndAnchor } from 'src/util';
import * as util from 'src/util';

// Mock the getGlobalScope function
const spyGetGlobalScope = jest.spyOn(util, 'getGlobalScope');
Expand Down Expand Up @@ -34,21 +29,30 @@ describe('matchesUrl', () => {
});

it('should handle URLs with paths', () => {
const urlArray: string[] = ['http://example.com/page', 'http://example.org/'];
const urlArray: string[] = [
'http://example.com/page',
'http://example.org/',
];
const urlString = 'http://example.com/page';

expect(matchesUrl(urlArray, urlString)).toBe(true);
});

it('should handle URLs with query parameters', () => {
const urlArray: string[] = ['http://example.com?param=value', 'http://example.org/'];
const urlArray: string[] = [
'http://example.com?param=value',
'http://example.org/',
];
const urlString = 'http://example.com?param=value';

expect(matchesUrl(urlArray, urlString)).toBe(true);
});

it('should handle URLs with ports', () => {
const urlArray: string[] = ['http://example.com:8080', 'http://example.org/'];
const urlArray: string[] = [
'http://example.com:8080',
'http://example.org/',
];
const urlString = 'http://example.com:8080';

expect(matchesUrl(urlArray, urlString)).toBe(true);
Expand Down Expand Up @@ -87,6 +91,8 @@ describe('getUrlParams', () => {
};

// Mock the global scope and location
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
spyGetGlobalScope.mockReturnValue(mockGlobal);

expect(getUrlParams()).toEqual({
Expand All @@ -103,6 +109,8 @@ describe('getUrlParams', () => {
};

// Mock the global scope and location
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
spyGetGlobalScope.mockReturnValue(mockGlobal);

expect(getUrlParams()).toEqual({});
Expand Down
2 changes: 1 addition & 1 deletion packages/experiment-tag/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@
"includeVersion": true,
"out": "../../docs",
"readme": "none",
"theme": "default"
"theme": "default",
}
}

0 comments on commit 8c172f5

Please sign in to comment.