From 4083592212a60be1a548d8c3b87dc7ea5d0346b6 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Wed, 2 Sep 2020 20:27:50 +0200 Subject: [PATCH] Fixed coding styles and ensured linting command applies to ts and tsx files --- package-lock.json | 6 +++--- package.json | 4 ++-- src/short-urls/reducers/shortUrlDeletion.ts | 2 +- src/visits/helpers/MapModal.tsx | 4 ++-- src/visits/reducers/shortUrlVisits.ts | 2 +- src/visits/reducers/tagVisits.ts | 5 ++++- .../reducers/shortUrlDeletion.test.ts | 21 +++++++++---------- 7 files changed, 23 insertions(+), 21 deletions(-) diff --git a/package-lock.json b/package-lock.json index c17aa0ed..ae7c56e6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -22525,9 +22525,9 @@ } }, "typescript": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.0.2.tgz", - "integrity": "sha512-e4ERvRV2wb+rRZ/IQeb3jm2VxBsirQLpQhdxplZ2MEzGvDkkMmPglecnNDfSUBivMjP93vRbngYYDQqQ/78bcQ==", + "version": "3.9.7", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.9.7.tgz", + "integrity": "sha512-BLbiRkiBzAwsjut4x/dsibSTB6yWpwT5qWmC2OfuCg3GgVQCSgMs4vEctYPhsaGtd0AeuuHMkjZ2h2WG8MSzRw==", "dev": true }, "uglify-es": { diff --git a/package.json b/package.json index f53e98e2..75ecaa8d 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "license": "MIT", "scripts": { "lint": "npm run lint:js && npm run lint:css", - "lint:js": "eslint src test scripts config", + "lint:js": "eslint --ext .js,.ts,.tsx src test scripts config", "lint:js:fix": "npm run lint:js -- --fix", "lint:css": "stylelint src/*.scss src/**/*.scss", "lint:css:fix": "npm run lint:css -- --fix", @@ -148,7 +148,7 @@ "terser-webpack-plugin": "^2.1.2", "ts-jest": "^26.0.0", "ts-mockery": "^1.2.0", - "typescript": "^4.0.2", + "typescript": "^3.9.7", "url-loader": "^2.2.0", "webpack": "^4.41.0", "webpack-dev-server": "^3.8.2", diff --git a/src/short-urls/reducers/shortUrlDeletion.ts b/src/short-urls/reducers/shortUrlDeletion.ts index 21347852..86fa00ee 100644 --- a/src/short-urls/reducers/shortUrlDeletion.ts +++ b/src/short-urls/reducers/shortUrlDeletion.ts @@ -1,6 +1,6 @@ import { Action, Dispatch } from 'redux'; import { buildActionCreator, buildReducer } from '../../utils/helpers/redux'; -import { ProblemDetailsError} from '../../utils/services/types'; +import { ProblemDetailsError } from '../../utils/services/types'; import { GetState } from '../../container/types'; import { ShlinkApiClientBuilder } from '../../utils/services/ShlinkApiClientBuilder'; diff --git a/src/visits/helpers/MapModal.tsx b/src/visits/helpers/MapModal.tsx index 85ce36e6..331d2357 100644 --- a/src/visits/helpers/MapModal.tsx +++ b/src/visits/helpers/MapModal.tsx @@ -1,6 +1,6 @@ import React, { FC } from 'react'; import { Modal, ModalBody } from 'reactstrap'; -import { Map, TileLayer, Marker, Popup, MapProps } from 'react-leaflet'; +import { Map, TileLayer, Marker, Popup } from 'react-leaflet'; import { prop } from 'ramda'; import { CityStats } from '../types'; import './MapModal.scss'; @@ -19,7 +19,7 @@ const OpenStreetMapTile: FC = () => ( /> ); -const calculateMapProps = (locations: CityStats[]): Partial => { +const calculateMapProps = (locations: CityStats[]): any => { if (locations.length === 0) { return {}; } diff --git a/src/visits/reducers/shortUrlVisits.ts b/src/visits/reducers/shortUrlVisits.ts index 339f37a9..6a1e837b 100644 --- a/src/visits/reducers/shortUrlVisits.ts +++ b/src/visits/reducers/shortUrlVisits.ts @@ -77,7 +77,7 @@ export const getShortUrlVisits = (buildShlinkApiClient: ShlinkApiClientBuilder) query: { domain?: OptionalString } = {}, ) => async (dispatch: Dispatch, getState: GetState) => { const { getShortUrlVisits } = buildShlinkApiClient(getState); - const visitsLoader = (page: number, itemsPerPage: number) => getShortUrlVisits( + const visitsLoader = async (page: number, itemsPerPage: number) => getShortUrlVisits( shortCode, { ...query, page, itemsPerPage }, ); diff --git a/src/visits/reducers/tagVisits.ts b/src/visits/reducers/tagVisits.ts index ab1d0379..b0f5746d 100644 --- a/src/visits/reducers/tagVisits.ts +++ b/src/visits/reducers/tagVisits.ts @@ -68,7 +68,10 @@ export const getTagVisits = (buildShlinkApiClient: ShlinkApiClientBuilder) => (t getState: GetState, ) => { const { getTagVisits } = buildShlinkApiClient(getState); - const visitsLoader = (page: number, itemsPerPage: number) => getTagVisits(tag, { ...query, page, itemsPerPage }); + const visitsLoader = async (page: number, itemsPerPage: number) => getTagVisits( + tag, + { ...query, page, itemsPerPage }, + ); const extraFinishActionData: Partial = { tag }; const actionMap = { start: GET_TAG_VISITS_START, diff --git a/test/short-urls/reducers/shortUrlDeletion.test.ts b/test/short-urls/reducers/shortUrlDeletion.test.ts index d4fccee3..5c68d2cd 100644 --- a/test/short-urls/reducers/shortUrlDeletion.test.ts +++ b/test/short-urls/reducers/shortUrlDeletion.test.ts @@ -8,27 +8,26 @@ import reducer, { deleteShortUrl, } from '../../../src/short-urls/reducers/shortUrlDeletion'; import { ProblemDetailsError } from '../../../src/utils/services/types'; +import ShlinkApiClient from '../../../src/utils/services/ShlinkApiClient'; describe('shortUrlDeletionReducer', () => { describe('reducer', () => { - - it('returns loading on DELETE_SHORT_URL_START', () => - expect(reducer(undefined, { type: DELETE_SHORT_URL_START })).toEqual({ + expect(reducer(undefined, { type: DELETE_SHORT_URL_START } as any)).toEqual({ shortCode: '', loading: true, error: false, })); it('returns default on RESET_DELETE_SHORT_URL', () => - expect(reducer(undefined, { type: RESET_DELETE_SHORT_URL })).toEqual({ + expect(reducer(undefined, { type: RESET_DELETE_SHORT_URL } as any)).toEqual({ shortCode: '', loading: false, error: false, })); it('returns shortCode on SHORT_URL_DELETED', () => - expect(reducer(undefined, { type: SHORT_URL_DELETED, shortCode: 'foo' })).toEqual({ + expect(reducer(undefined, { type: SHORT_URL_DELETED, shortCode: 'foo' } as any)).toEqual({ shortCode: 'foo', loading: false, error: false, @@ -37,7 +36,7 @@ describe('shortUrlDeletionReducer', () => { it('returns errorData on DELETE_SHORT_URL_ERROR', () => { const errorData = Mock.of({ type: 'bar' }); - expect(reducer(undefined, { type: DELETE_SHORT_URL_ERROR, errorData })).toEqual({ + expect(reducer(undefined, { type: DELETE_SHORT_URL_ERROR, errorData } as any)).toEqual({ shortCode: '', loading: false, error: true, @@ -63,9 +62,9 @@ describe('shortUrlDeletionReducer', () => { it.each( [[ undefined ], [ null ], [ 'example.com' ]], )('dispatches proper actions if API client request succeeds', async (domain) => { - const apiClientMock = { + const apiClientMock = Mock.of({ deleteShortUrl: jest.fn(() => ''), - }; + }); const shortCode = 'abc123'; await deleteShortUrl(() => apiClientMock)(shortCode, domain)(dispatch, getState); @@ -81,9 +80,9 @@ describe('shortUrlDeletionReducer', () => { it('dispatches proper actions if API client request fails', async () => { const data = { foo: 'bar' }; const error = { response: { data } }; - const apiClientMock = { - deleteShortUrl: jest.fn(() => Promise.reject(error)), - }; + const apiClientMock = Mock.of({ + deleteShortUrl: jest.fn(async () => Promise.reject(error)), + }); const shortCode = 'abc123'; try {