Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fix ~50 eslint errors #1008

Merged
merged 17 commits into from
May 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ module.exports = {
}
],
"no-plusplus": "off",
}
},
overrides: [
{
"files": ["packages/theme/tests/e2e/**/*"],
"rules": {
"jest/expect-expect": "off",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cypress uses similar test case syntax to jest so eslint gets confused and treats cypress like jest. this solution is not optimal but will do for now

"promise/catch-or-return": "off", // conflicts with Cypress.Chainable
"promise/always-return": "off",
}
}
]
}

2 changes: 1 addition & 1 deletion packages/composables/src/helpers/htmlDecoder.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @deprecated since version 1.0.0
*/
export function htmlDecode(input) {
export function htmlDecode(input: string) {
const formatName = () => {
try {
const domParser = new DOMParser();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import userEvent from '@testing-library/user-event';
import HeaderNavigation from '../HeaderNavigation.vue';
import { render } from '~/test-utils';

import { useUiHelpers } from '~/composables';
import useUiHelpersMock from '~/test-utils/mocks/useUiHelpersMock';
import CategoryTreeDataMock from '~/test-utils/mocks/categoryTreeDataMock';
import HeaderNavigation from '../HeaderNavigation.vue';

jest.mock('~/composables');
useUiHelpers.mockReturnValue(useUiHelpersMock());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import HeaderNavigationItem from '../HeaderNavigationItem.vue';
import { render } from '~/test-utils';
import HeaderNavigationItem from '../HeaderNavigationItem.vue';

describe('HeaderNavigationItem', () => {
it('display proper label and link', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import userEvent from '@testing-library/user-event';
import HeaderNavigationSubcategories from '../HeaderNavigationSubcategories.vue';
import { render } from '~/test-utils';
import CategoryTreeDataMock from '~/test-utils/mocks/categoryTreeDataMock';
import { useUiHelpers } from '~/composables';
import useUiHelpersMock from '~/test-utils/mocks/useUiHelpersMock';
import HeaderNavigationSubcategories from '../HeaderNavigationSubcategories.vue';

jest.mock('~/composables');
useUiHelpers.mockReturnValue(useUiHelpersMock());
Expand Down
4 changes: 2 additions & 2 deletions packages/theme/components/Header/SearchBar/SearchBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ import {
defineComponent, ref, watch, useRoute,
} from '@nuxtjs/composition-api';
import debounce from 'lodash.debounce';
import { clickOutside } from '~/utilities/directives/click-outside/click-outside-directive.js';
import { clickOutside } from '~/utilities/directives/click-outside/click-outside-directive';
import SvgImage from '~/components/General/SvgImage.vue';
import { useFacet } from '~/composables';
import { useFacet } from '~/modules/catalog/category/composables/useFacet';

export default defineComponent({
name: 'SearchBar',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Context } from '@nuxt/types';
import { Logger } from '~/helpers/logger';
import { VsfContext } from '~/composables/context';

Expand Down
2 changes: 2 additions & 0 deletions packages/theme/ecosystem.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// the PM2 ecosystem.config.js needs to use module.exports
// eslint-disable-next-line unicorn/prefer-module
module.exports = {
apps: [
{
Expand Down
2 changes: 1 addition & 1 deletion packages/theme/enums/cookieNameEnum.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
export default {
currencyCookieName: 'vsf-currency',
countryCookieName: 'vsf-country',
localeCookieName: 'vsf-locale',
Expand Down
2 changes: 1 addition & 1 deletion packages/theme/enums/stockStatusEnum.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
export default {
inStock: 'IN_STOCK',
outOfStock: 'OUT_OF_STOCK',
};
2 changes: 1 addition & 1 deletion packages/theme/getters/reviewGetters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const getReviewDate = (item: ProductReview): string => item.created_at;

export const getTotalReviews = (review: ProductInterface): number => review?.review_count || 0;

export const getAverageRating = (review: ProductInterface): number => (review?.reviews?.items?.reduce((acc, curr) => Number.parseInt(`${acc}`, 10) + getReviewRating(curr), 0)) / (review?.review_count || 1) || 0;
export const getAverageRating = (review: ProductInterface): number => ((review?.reviews?.items?.reduce((acc, curr) => Number.parseInt(`${acc}`, 10) + getReviewRating(curr), 0)) ?? 0) / (review?.review_count || 1) || 0;

export const getRatesCount = (_review: ProductReviews): AgnosticRateCount[] => [];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('asyncLocalStorage :: Promised Based Localstorage Management', () => {

expect(localStorage.setItem).toHaveBeenLastCalledWith(VSF_KEY, VSF_VALUE);
expect(localStorage.__STORE__[VSF_KEY]).toBe(VSF_VALUE);
expect(Object.keys(localStorage.__STORE__)).toHaveLength(1);
expect(Object.keys(localStorage.__STORE__ as Object)).toHaveLength(1);
});

test('getItem :: should get value from localStorage by key', async () => {
Expand Down Expand Up @@ -44,30 +44,30 @@ describe('asyncLocalStorage :: Promised Based Localstorage Management', () => {
await setItem(KEY, VALUE);

expect(localStorage.__STORE__[VSF_KEY]).toBe(VSF_VALUE);
expect(Object.keys(localStorage.__STORE__)).toHaveLength(1);
expect(Object.keys(localStorage.__STORE__ as Object)).toHaveLength(1);

await mergeItem(KEY, MERGE_VALUE);

expect(localStorage.__STORE__[VSF_KEY]).toBe(VSF_MERGE_VALUE);
expect(Object.keys(localStorage.__STORE__)).toHaveLength(1);
expect(Object.keys(localStorage.__STORE__ as Object)).toHaveLength(1);
});

test('remove :: should remove a key and value from localStorage', async () => {
const KEY = 'jest';
const VSF_KEY = `vsf-${KEY}`;

expect(Object.keys(localStorage.__STORE__)).toHaveLength(1);
expect(Object.keys(localStorage.__STORE__ as Object)).toHaveLength(1);

await removeItem(KEY);

expect(localStorage.removeItem).toHaveBeenCalledWith(VSF_KEY);
expect(Object.keys(localStorage.__STORE__)).toHaveLength(0);
expect(Object.keys(localStorage.__STORE__ as Object)).toHaveLength(0);
});

test('clear :: should clear all values and keys from localStorage', async () => {
await clear();

expect(localStorage.clear).toHaveBeenCalledWith();
expect(Object.keys(localStorage.__STORE__)).toHaveLength(0);
expect(Object.keys(localStorage.__STORE__ as Object)).toHaveLength(0);
});
});
46 changes: 32 additions & 14 deletions packages/theme/helpers/asyncLocalStorage.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
const getVsfKey = (key) => `vsf-${key}`;
const getVsfKey = (key: string) => `vsf-${key}`;

const mergeLocalStorageItem = (key: string, value: string) => {
type Callback<TValue> = (error: Error | null, value?: TValue) => void;

const mergeLocalStorageItem = (key: string, value: Record<string, unknown>) : void => {
const oldValue = window.localStorage.getItem(key);
const oldObject = JSON.parse(oldValue);
const newObject = value;
const nextValue = JSON.stringify({ ...JSON.parse(JSON.stringify(oldObject)), ...JSON.parse(JSON.stringify(newObject)) });
const nextValue = JSON.stringify({
...JSON.parse(JSON.stringify(oldObject)),
...JSON.parse(JSON.stringify(newObject)),
});
window.localStorage.setItem(key, nextValue);
};

const createPromise = (getValue, callback): Promise<any> => new Promise((resolve, reject) => {
const createPromise = <TValue>(
getValue: () => TValue,
callback: Callback<TValue>,
) : Promise<TValue> => new Promise((resolve, reject) => {
try {
const value = getValue();
if (callback) {
Expand All @@ -17,26 +25,36 @@ const createPromise = (getValue, callback): Promise<any> => new Promise((resolve
resolve(value);
} catch (err) {
if (callback) {
callback(err);
callback(err as Error);
}
reject(err);
}
});

// eslint-disable-next-line max-len
export const getItem = (key: string, callback?: Function): Promise<any> => createPromise(() => JSON.parse(window.localStorage.getItem(getVsfKey(key))), callback);
export const getItem = <T = unknown>(
key: string,
callback?: Callback<T>,
): Promise<T> => createPromise(() => JSON.parse(window.localStorage.getItem(getVsfKey(key))), callback);

// eslint-disable-next-line max-len
export const setItem = (key: string, value: string, callback?: Function): Promise<any> => createPromise(() => (window.localStorage.setItem(getVsfKey(key), JSON.stringify(value))), callback);
export const setItem = <T = unknown>(
key: string,
value: T,
callback?: Callback<void>,
): Promise<void> => createPromise(() => (window.localStorage.setItem(getVsfKey(key), JSON.stringify(value))), callback);

// eslint-disable-next-line max-len
export const removeItem = (key: string, callback?: Function): Promise<any> => createPromise(() => {
export const removeItem = (
key: string,
callback?: Callback<void>,
): Promise<void> => createPromise(() => {
window.localStorage.removeItem(getVsfKey(key));
}, callback);

// eslint-disable-next-line max-len
export const mergeItem = (key: string, value: string, callback?: Function): Promise<any> => createPromise(() => mergeLocalStorageItem(getVsfKey(key), value), callback);
export const mergeItem = (
key: string,
value: Record<string, unknown>,
callback?: Callback<void>,
): Promise<void> => createPromise(() => mergeLocalStorageItem(getVsfKey(key), value), callback);

export const clear = (callback?: Function): Promise<any> => createPromise(() => {
export const clear = (callback?: Callback<void>): Promise<void> => createPromise(() => {
window.localStorage.clear();
}, callback);
11 changes: 0 additions & 11 deletions packages/theme/helpers/cacheControl.js

This file was deleted.

2 changes: 1 addition & 1 deletion packages/theme/helpers/checkout/__tests__/steps.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const CHECKOUT_DATA = {
};

describe('steps :: steps helper for the checkout', () => {
beforeEach(async () => {
beforeEach(() => {
localStorage.clear();

localStorage.setItem('vsf-checkout', JSON.stringify(CHECKOUT_DATA));
Expand Down
4 changes: 2 additions & 2 deletions packages/theme/helpers/integrationPlugin/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* It extends given integartion, defined by `tag` in the context.
*/
export const createExtendIntegrationInCtx = ({ tag, nuxtCtx, inject }) => (integrationProperties) => {
export const createExtendIntegrationInCtx = ({ tag, nuxtCtx, inject }) => (integrationProperties: Record<string, unknown>) => {
const integrationKey = `$${tag}`;

if (!nuxtCtx.$vsf || !nuxtCtx.$vsf[integrationKey]) {
Expand All @@ -19,7 +19,7 @@ export const createExtendIntegrationInCtx = ({ tag, nuxtCtx, inject }) => (integ
/**
* It creates a function that adds an integration to the context under the given name, defined by `tag`.
*/
export const createAddIntegrationToCtx = ({ tag, nuxtCtx, inject }) => (integrationProperties) => {
export const createAddIntegrationToCtx = ({ tag, nuxtCtx, inject }) => (integrationProperties: Record<string, unknown>) => {
const integrationKey = `$${tag}`;

if (nuxtCtx.$vsf && !nuxtCtx.$vsf[integrationKey]) {
Expand Down
6 changes: 3 additions & 3 deletions packages/theme/helpers/integrationPlugin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Context as NuxtContext } from '@nuxt/types';
import { Inject } from '@nuxt/types/app';
import axios from 'axios';
import { createExtendIntegrationInCtx, createAddIntegrationToCtx } from './context';
import { getIntegrationConfig, createProxiedApi } from './_proxyUtils';
import { getIntegrationConfig, createProxiedApi, ApiClientMethod } from './_proxyUtils';

interface IntegrationContext {
integration: {
Expand Down Expand Up @@ -30,7 +30,7 @@ const setCookieValues = (cookieValues: Record<string, string>, cookieString = ''
};

export const integrationPlugin = (pluginFn: NuxtPluginWithIntegration) => (nuxtCtx: NuxtContext, inject: Inject) => {
const configure = (tag: string, configuration) => {
const configure = (tag: string, configuration: { api: Record<string, ApiClientMethod> }) => {
const injectInContext = createAddIntegrationToCtx({ tag, nuxtCtx, inject });
const config = getIntegrationConfig(nuxtCtx, configuration);
const { middlewareUrl, ssrMiddlewareUrl } = (nuxtCtx as any).$config;
Expand All @@ -51,7 +51,7 @@ export const integrationPlugin = (pluginFn: NuxtPluginWithIntegration) => (nuxtC
injectInContext({ api, client, config });
};

const extend = (tag, integrationProperties) => {
const extend = (tag, integrationProperties: Record<string, unknown>) => {
createExtendIntegrationInCtx({ tag, nuxtCtx, inject })(integrationProperties);
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import CategoryEmptyResults from '../CategoryEmptyResults.vue';
import { render } from '~/test-utils';
import CategoryEmptyResults from '../CategoryEmptyResults.vue';

describe('CategoryEmptyResults.vue', () => {
it('Renders with a default value', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ import { readonly, ref } from '@nuxtjs/composition-api';
import { Logger } from '~/helpers/logger';
import type { ComposableFunctionArgs } from '~/composables/types';
import type { GetProductSearchParams } from '~/modules/catalog/product/types';
import type {
UseFacetInterface, UseFacetErrors, UseFacetSearchResult, FacetSearchParams,
} from './useFacet';
import useApi from '~/composables/useApi';
import GetFacetDataQuery from './getFacetData.gql';
import { SortingOptions } from '~/modules/catalog/category/composables/useFacet/SortingOptions';
import { PerPageOptions } from '~/modules/catalog/category/composables/useFacet/PerPageOptions';
import { createProductAttributeFilterInput } from '~/modules/catalog/category/composables/useFacet/input/createProductAttributeFilterInput';
import { createProductAttributeSortInput } from '~/modules/catalog/category/composables/useFacet/input/createProductAttributeSortInput';
import { Products } from '~/modules/GraphQL/types';
import GetFacetDataQuery from './getFacetData.gql';
import type {
UseFacetInterface, UseFacetErrors, UseFacetSearchResult, FacetSearchParams,
} from './useFacet';

/**
* The `useFacet()` composable allows searching for products using facets.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import config, { FilterTypeEnum } from '~/modules/catalog/category/config/config';
import RendererTypesEnum from '~/modules/catalog/category/components/filters/renderer/RendererTypesEnum';
import {
getFilterConfig, getDisabledFilters,
} from '../FiltersConfig';
import config, { FilterTypeEnum } from '~/modules/catalog/category/config/config';
import RendererTypesEnum from '~/modules/catalog/category/components/filters/renderer/RendererTypesEnum';

jest.mock('~/modules/catalog/category/config/config');

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import type { Ref } from '@nuxtjs/composition-api';
import { ref, readonly, useContext } from '@nuxtjs/composition-api';
import { Logger } from '~/helpers/logger';
import type {
UseUpsellProductsError,
UseUpsellProductsInterface,
UseUpsellProductsSearchParams,
} from './useUpsellProducts';

import { Logger } from '~/helpers/logger';

/**
* The `useUpsellProducts()` composable allows loading upsell products.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ const getProducts = (wishlistData: Wishlist[] | Wishlist): {
quantity: item.quantity,
added_at: item.added_at,
id: item.id,
}))];
})) ?? []];

const mapper = (item) => ({
product: item.product,
Expand Down
2 changes: 2 additions & 0 deletions packages/theme/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@
"@vue-storefront/nuxt": "~2.5.6",
"@vue-storefront/redis-cache": "^1.0.1",
"axios": "^0.26.1",
"body-parser": "1.19.2",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These were already used by body-parser.js - I'm just adding them explicitly, rather than using the transient versions provided by unrelated packages

"cookie-universal-nuxt": "^2.1.5",
"deepdash": "^5.3.9",
"express": "4.17.3",
"graphql-request": "^4.0.0",
"is-https": "^4.0.0",
"isomorphic-dompurify": "^0.18.0",
Expand Down
8 changes: 5 additions & 3 deletions packages/theme/serverMiddleware/body-parser.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const bodyParser = require('body-parser');
const app = require('express')();
import bodyParser from 'body-parser';
import express from 'express';

const app = express();

app.use(bodyParser.json());
module.exports = app;
export default app;
2 changes: 1 addition & 1 deletion packages/theme/tests/e2e/cypress.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"baseUrl": "http://localhost:3000",
"fixturesFolder": "tests/e2e/fixtures",
"integrationFolder": "tests/e2e/integration",
"pluginsFile": "tests/e2e/plugins/index.js",
"pluginsFile": "tests/e2e/plugins/index.ts",
"supportFile": "tests/e2e/support/index.js",
"viewportHeight": 1080,
"viewportWidth": 1920,
Expand Down
Loading