Skip to content

Commit

Permalink
fix(lint): rework codebase for @typescript-eslint@4
Browse files Browse the repository at this point in the history
- Pick up new rules for no-shadow from @typescript-eslint
- Disable no-shadow in favour of @typescript-eslint equivalent
- Ensure that @typescript-eslint recognises DOM globals by setting
  `parserOptions.lib`
- Reorder type definitions to avoid no-use-before-define
- Properly pick up sequelize types in test mocks
  • Loading branch information
LoneRifle committed Sep 3, 2020
1 parent cfd3798 commit 70b2ed9
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 56 deletions.
5 changes: 4 additions & 1 deletion .eslintrc.ts.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,18 @@
],
"parserOptions": {
"ecmaVersion": 2018,
"lib": ["es6", "dom"],
"sourceType": "module"
},
"plugins": ["jsdoc", "jest"],
"plugins": ["@typescript-eslint", "jsdoc", "jest"],
"rules": {
"@typescript-eslint/no-shadow": ["error"],
"comma-dangle": ["error", "always-multiline"],
"import/first": "off",
"import/extensions": "off",
"newline-per-chained-call": ["error"],
"no-console": "off",
"no-shadow": "off",
"no-unused-vars": "off",
"no-useless-return": "off",
"semi": [2, "never"],
Expand Down
10 changes: 5 additions & 5 deletions src/client/components/CollapsibleMessage/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ export enum CollapsibleMessageType {
Success,
}

export enum CollapsibleMessagePosition {
Static = 'static',
Absolute = 'absolute',
}

export type CollapsibleMessageProps = {
type: CollapsibleMessageType
visible: boolean
Expand All @@ -15,8 +20,3 @@ export type CollapsibleMessageStyles = {
type: CollapsibleMessageType
position: CollapsibleMessagePosition
}

export enum CollapsibleMessagePosition {
Static = 'static',
Absolute = 'absolute',
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ export const useStatistics = (shortUrl: string) => {
const fetchStatistics = async () => {
const endpoint = `/api/link-stats?url=${shortUrl}`
const response = await get(endpoint)
const LinkStatistics: LinkStatistics = {
const linkStatistics: LinkStatistics = {
status: response.status,
contents: await response.json(),
}
setStatistics(LinkStatistics)
setStatistics(linkStatistics)
}
if (shortUrl) {
fetchStatistics()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ import { isValidLongUrl } from '../../../../../../shared/util/validation'
import { UrlType } from '../../../../../reducers/user/types'
import { GoGovReduxState } from '../../../../../reducers/types'

export type ShortLinkState = [
UrlType | undefined,
ShortLinkDispatch | undefined,
]

type Dispatch = () => (dispatch: any) => void

export type ShortLinkDispatch = {
Expand All @@ -18,6 +13,11 @@ export type ShortLinkDispatch = {
applyEditLongUrl: Dispatch
}

export type ShortLinkState = [
UrlType | undefined,
ShortLinkDispatch | undefined,
]

export default function useShortLink(shortLink: string) {
const urls: UrlType[] = useSelector<GoGovReduxState, UrlType[]>(
(state) => state.user.urls,
Expand Down
4 changes: 2 additions & 2 deletions src/client/reducers/home/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ export type HomeStatistics = {
clickCount: number | null
}

export type LinksToRotate = Array<string>

export type HomeState = {
statistics: HomeStatistics
linksToRotate?: LinksToRotate
}

export type LinksToRotate = Array<string>
48 changes: 24 additions & 24 deletions src/client/reducers/user/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
export enum UrlState {
Active = 'ACTIVE',
Inactive = 'INACTIVE',
}

export type UrlTableFilterConfig = {
isFile?: boolean
state?: UrlState
}

export enum SortDirection {
Descending = 'desc',
Ascending = 'asc',
}

export type UrlTableConfig = {
numberOfRows: number
pageNumber: number
sortDirection: SortDirection
orderBy: string
searchText: string
filter: UrlTableFilterConfig
}

export type UrlType = {
clicks: number
createdAt: string
Expand Down Expand Up @@ -30,27 +54,3 @@ export type UserState = {
lastCreatedLink?: string
message: string | null
}

export type UrlTableConfig = {
numberOfRows: number
pageNumber: number
sortDirection: SortDirection
orderBy: string
searchText: string
filter: UrlTableFilterConfig
}

export type UrlTableFilterConfig = {
isFile?: boolean
state?: UrlState
}

export enum UrlState {
Active = 'ACTIVE',
Inactive = 'INACTIVE',
}

export enum SortDirection {
Descending = 'desc',
Ascending = 'asc',
}
2 changes: 1 addition & 1 deletion src/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ exitIfAnyMissing(requiredVars)
let otpFunction: OtpFunction | null = null
let transporterOpts: nodemailer.TransporterOptions | null = null
let proxy: boolean = true
let cookieConfig: CookieSettings | null = null
let cookieConfig = null

if (DEV_ENV) {
// Only configure things particular to development here
Expand Down
10 changes: 5 additions & 5 deletions src/server/repositories/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,16 @@ export type UserUrlsQueryConditions = {
isFile: boolean | undefined
}

export type UrlsPublicPaginated = {
count: number
urls: Array<UrlPublic>
}

export type UrlPublic = Pick<
StorableUrl,
'shortUrl' | 'longUrl' | 'description' | 'contactEmail' | 'isFile'
>

export type UrlsPublicPaginated = {
count: number
urls: Array<UrlPublic>
}

export type UrlsPaginated = {
count: number
urls: Array<StorableUrl>
Expand Down
10 changes: 5 additions & 5 deletions src/server/services/types.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { StorableUrl } from '../repositories/types'
import { GoUploadedFile } from '../controllers/types'

export enum RedirectType {
Direct,
TransitionPage,
}

export type RedirectResult = {
visitedUrls: string[]
longUrl: string
redirectType: RedirectType
}

export enum RedirectType {
Direct,
TransitionPage,
}

export type UpdateUrlOptions = Partial<
Pick<
StorableUrl,
Expand Down
10 changes: 5 additions & 5 deletions src/shared/util/messages.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
export type JsonMessage = {
message: string
type?: MessageType
}

export enum MessageType {
ShortUrlError = 'ShortUrlError',
LongUrlError = 'LongUrlError',
FileUploadError = 'FileUploadError',
}

export type JsonMessage = {
message: string
type?: MessageType
}
3 changes: 2 additions & 1 deletion test/server/mocks/repositories/LinkStatisticsRepository.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable class-methods-use-this */

import { injectable } from 'inversify'
import { Transaction } from 'sequelize/types'
import { LinkStatisticsRepositoryInterface } from '../../../../src/server/repositories/interfaces/LinkStatisticsRepositoryInterface'
import { LinkStatisticsInterface } from '../../../../src/shared/interfaces/link-statistics'
import { DeviceType } from '../../../../src/server/services/interfaces/DeviceCheckServiceInterface'
Expand All @@ -26,7 +27,7 @@ export class MockLinkStatisticsRepository

incrementClick: (
shortUrl: string,
transaction?: import('sequelize/types').Transaction,
transaction?: Transaction,
) => Promise<boolean> = () => Promise.resolve(true)

updateLinkStatistics: (shortUrl: string, device: DeviceType) => void = () =>
Expand Down

0 comments on commit 70b2ed9

Please sign in to comment.