Skip to content

Commit

Permalink
Require explicit function return types w/ ESLint.
Browse files Browse the repository at this point in the history
  • Loading branch information
retrixe committed Jul 21, 2023
1 parent 9870cad commit 94feb06
Show file tree
Hide file tree
Showing 34 changed files with 112 additions and 80 deletions.
1 change: 0 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ module.exports = {
'@typescript-eslint/restrict-plus-operands': 'off',
'@typescript-eslint/no-dynamic-delete': 'off',
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/explicit-function-return-type': 'off', // TODO: Enable later.
// Adjust to Prettier's presence. (Maybe we should do away with it later.)
'@typescript-eslint/space-before-function-paren': 'off',
'@typescript-eslint/member-delimiter-style': 'off',
Expand Down
10 changes: 5 additions & 5 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ export interface RootStackParamList {
Home: undefined
Chat: { serverName: string; version: number }
}
type HomeNavigationProp = NativeStackNavigationProp<RootStackParamList, 'Home'>
type HomeProp = NativeStackNavigationProp<RootStackParamList, 'Home'>

const HomeScreen = ({ navigation }: { navigation: HomeNavigationProp }) => {
const HomeScreen = ({ navigation }: { navigation: HomeProp }): JSX.Element => {
const { connection } = React.useContext(ConnectionContext)
React.useEffect(() => {
if (connection) {
Expand Down Expand Up @@ -92,7 +92,7 @@ const HomeScreen = ({ navigation }: { navigation: HomeNavigationProp }) => {
)
}

const App = () => {
const App = (): JSX.Element => {
const [connection, setConnection] = React.useState<
ServerConnection | undefined
>()
Expand All @@ -109,9 +109,9 @@ const App = () => {
const [serversStore, setServersStore] = useAsyncStorage('@servers', '{}')
const accounts: Accounts = JSON.parse(accountsStore)
const servers: Servers = JSON.parse(serversStore)
const setAccounts = (newAccounts: Accounts) =>
const setAccounts = (newAccounts: Accounts): void =>
setAccountsStore(JSON.stringify(newAccounts))
const setServers = (newServers: Servers) =>
const setServers = (newServers: Servers): void =>
setServersStore(JSON.stringify(newServers))

const colorScheme = useColorScheme()
Expand Down
2 changes: 1 addition & 1 deletion src/components/Dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const Dialog = ({
visible: boolean
onRequestClose: () => void
containerStyles?: ViewStyle
}>) => (
}>): JSX.Element => (
<Modal
animationType='fade'
transparent
Expand Down
2 changes: 1 addition & 1 deletion src/components/DisconnectDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
import Dialog, { dialogStyles } from './Dialog'
import Text from './Text'

const DisconnectDialog = () => {
const DisconnectDialog = (): JSX.Element => {
const darkMode = useDarkMode()
const { disconnectReason, setDisconnectReason } =
useContext(ConnectionContext)
Expand Down
2 changes: 1 addition & 1 deletion src/components/ElevatedView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import useDarkMode from '../context/useDarkMode'

const ElevatedView = (
props: React.PropsWithChildren<{ style?: ViewStyle }>
) => (
): JSX.Element => (
<View
{...props}
style={Object.assign(
Expand Down
2 changes: 1 addition & 1 deletion src/components/Text.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from 'react-native'
import useDarkMode from '../context/useDarkMode'

const Text = (props: React.PropsWithChildren<TextProps>) => (
const Text = (props: React.PropsWithChildren<TextProps>): JSX.Element => (
<RNText
{...props}
style={[
Expand Down
2 changes: 1 addition & 1 deletion src/components/TextField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react'
import { TextInput, StyleSheet, type TextInputProps } from 'react-native'
import useDarkMode from '../context/useDarkMode'

const TextField = (props: TextInputProps & { red?: boolean }) => {
const TextField = (props: TextInputProps & { red?: boolean }): JSX.Element => {
const style = props.style?.valueOf()
const darkMode = useDarkMode()
return (
Expand Down
6 changes: 3 additions & 3 deletions src/components/TextFieldDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ const TextFieldDialog = ({
closeModal: () => void
initialState: string
setFinalState: (state: string) => void
}) => {
}): JSX.Element => {
const [modalContent, setModalContent] = useState(initialState)
const closeModalAndSaveState = () => {
const closeModalAndSaveState = (): void => {
setFinalState(modalContent)
closeModal()
}
const closeModalAndReset = () => {
const closeModalAndReset = (): void => {
setModalContent(initialState)
closeModal()
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/accounts/AccountDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const AccountDisplay = ({
darkMode: boolean
setActiveAccount: (uuid: string) => void
setDeleteAccount: (uuid: string) => void
}) => (
}): JSX.Element => (
<ElevatedView style={styles.accountView}>
<Pressable
onPress={() => setActiveAccount(uuid)}
Expand Down
6 changes: 3 additions & 3 deletions src/components/accounts/AddAccountDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const AddAccountDialog = ({
}: {
open: boolean
setOpen: React.Dispatch<React.SetStateAction<boolean>>
}) => {
}): JSX.Element => {
const darkMode = useDarkMode()
const { accounts, setAccounts } = useContext(UsersContext)

Expand All @@ -32,7 +32,7 @@ const AddAccountDialog = ({
!/^[A-Za-z0-9_]{3,16}$/.test(newUser) &&
(password === null ? true : !/^[^\s@]+@[^\s@]+$/.test(newUser))

const cancelAddAccount = () => {
const cancelAddAccount = (): void => {
setMicrosoftLogin(false)
setOpen(false)
setUserRed(false)
Expand All @@ -41,7 +41,7 @@ const AddAccountDialog = ({
setPassword(null) // setPassword('')
setDialogError('')
}
const addAccount = () => {
const addAccount = (): void => {
const accountExists =
!!accounts[newUser] ||
!!Object.keys(accounts).find(id => accounts[id].email === newUser)
Expand Down
8 changes: 4 additions & 4 deletions src/components/accounts/MicrosoftLogin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
} from '../../minecraft/api/microsoft'
import config from '../../../config.json'

const MicrosoftLogin = ({ close }: { close: () => void }) => {
const MicrosoftLogin = ({ close }: { close: () => void }): JSX.Element => {
const darkMode = useDarkMode()
const style = darkMode
? '<style>body{font-size:48px;padding:16px;background-color:#242424;color:#ffffff;}</style>'
Expand All @@ -27,7 +27,7 @@ const MicrosoftLogin = ({ close }: { close: () => void }) => {
const webview = useRef<WebView>(null)
const [loading, setLoading] = useState(false)
const [html, setRawHtml] = useState('')
const setHtml = (newHtml: string) => setRawHtml(style + newHtml)
const setHtml = (newHtml: string): void => setRawHtml(style + newHtml)

const addAccount = (
id: string,
Expand All @@ -54,12 +54,12 @@ const MicrosoftLogin = ({ close }: { close: () => void }) => {
return alreadyExists
}

const onRequestClose = () => {
const onRequestClose = (): void => {
if (!loading) close()
}
const handleNavigationStateChange = async (
newNavState: WebViewNavigation
) => {
): Promise<void> => {
// LOW-TODO: Parse errors.
if (!webview.current || !newNavState.url) return
if (
Expand Down
8 changes: 4 additions & 4 deletions src/components/servers/EditServerDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const EditServerDialog = ({
deleteServer: (server: string) => void
editServerDialogOpen: string | boolean
setEditServerDialogOpen: (server: string | boolean) => void
}) => {
}): JSX.Element => {
const [ipAddr, setIpAddr] = useState('')
const [ipAddrRed, setIpAddrRed] = useState(false)
const [newServerName, setNewServerName] = useState('')
Expand All @@ -54,15 +54,15 @@ const EditServerDialog = ({
}
}, [editServerDialogOpen, server])

const closeDialog = () => setEditServerDialogOpen(false)
const closeDialog = (): void => setEditServerDialogOpen(false)

const handleDeleteServer = () => {
const handleDeleteServer = (): void => {
if (typeof editServerDialogOpen !== 'string') return
deleteServer(editServerDialogOpen)
closeDialog()
}

const handleEditServer = () => {
const handleEditServer = (): void => {
const edit = typeof editServerDialogOpen === 'string'
if (
!newServerName ||
Expand Down
2 changes: 1 addition & 1 deletion src/components/servers/ServerDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const ServerDisplay = ({
darkMode: boolean
connectToServer: (server: string) => void
openEditServerDialog: (server: string) => void
}) => (
}): JSX.Element => (
<ElevatedView style={styles.serverView}>
<Pressable
onPress={() => connectToServer(server)}
Expand Down
7 changes: 5 additions & 2 deletions src/components/settings/DarkModeSetting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import useDarkMode from '../../context/useDarkMode'
const RadioButton = (props: {
style?: StyleProp<ViewStyle>
selected: boolean
}) => {
}): JSX.Element => {
const darkMode = useDarkMode()
return (
<View
Expand Down Expand Up @@ -58,7 +58,10 @@ interface DarkModeSettingProps {
setValue: (newValue: boolean | null) => void
}

const DarkModeSetting = ({ value, setValue }: DarkModeSettingProps) => {
const DarkModeSetting = ({
value,
setValue
}: DarkModeSettingProps): JSX.Element => {
const [modalOpen, setModalOpen] = useState(false)
const ripple = { color: '#aaa' }
const dark = useDarkMode()
Expand Down
4 changes: 2 additions & 2 deletions src/components/settings/Setting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const Setting = <T extends string | boolean>({
setValue?: (newValue: T) => void
multiline?: boolean
maxLength?: number
}) => {
}): JSX.Element => {
const da = useDarkMode()
const [modalOpen, setModalOpen] = useState(false)
const [modalContent, setModalContent] = useState(
Expand All @@ -30,7 +30,7 @@ const Setting = <T extends string | boolean>({
const [toggleValue, setToggleValue] = useState(value)

const Wrapper = setValue ?? onClick ? Pressable : React.Fragment
const wrapperPress = () => {
const wrapperPress = (): void => {
if (onClick) onClick()
else if (typeof value === 'boolean' && setValue) {
setValue(!toggleValue as T)
Expand Down
2 changes: 1 addition & 1 deletion src/context/useDarkMode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import { createContext, useContext } from 'react'

export const ColorSchemeContext = createContext<boolean>(false)

const useDarkMode = () => useContext(ColorSchemeContext)
const useDarkMode = (): boolean => useContext(ColorSchemeContext)

export default useDarkMode
6 changes: 4 additions & 2 deletions src/minecraft/api/microsoft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ export const authenticateWithXsts = async (
return res.access_token
}

export const checkGameOwnership = async (accessToken: string) => {
export const checkGameOwnership = async (
accessToken: string
): Promise<boolean> => {
const req = await fetch(mcStoreUrl, {
headers: {
Accept: 'application/json',
Expand All @@ -125,7 +127,7 @@ export const checkGameOwnership = async (accessToken: string) => {
if (!req.ok) throw new Error('Failed to check if user owns Minecraft game!')
const res = await req.json()
const items = res.items as Array<{ name: string }>
return (
return !!(
items?.length >= 2 &&
items.find(item => item.name === 'game_minecraft') &&
items.find(item => item.name === 'product_minecraft')
Expand Down
6 changes: 4 additions & 2 deletions src/minecraft/api/mojang.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@ export const joinMinecraftSession = async (
accessToken: string,
selectedProfile: string,
serverId: string
) =>
): Promise<Response> =>
await fetch(joinMinecraftSessionUrl, {
body: JSON.stringify({ accessToken, selectedProfile, serverId }),
headers: { 'content-type': 'application/json' },
method: 'POST'
})

export const getPlayerCertificates = async (accessToken: string) =>
export const getPlayerCertificates = async (
accessToken: string
): Promise<Certificate> =>
await fetch(getPlayerCertificatesUrl, {
headers: { Authorization: 'Bearer ' + accessToken },
method: 'POST'
Expand Down
15 changes: 12 additions & 3 deletions src/minecraft/api/yggdrasil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ export const refresh = async (
return await request.json()
}

export const validate = async (accessToken: string, clientToken?: string) => {
export const validate = async (
accessToken: string,
clientToken?: string
): Promise<void> => {
const request = await fetch('https://authserver.mojang.com/validate', {
method: 'POST',
headers: { 'content-type': 'application/json' },
Expand All @@ -64,7 +67,10 @@ export const validate = async (accessToken: string, clientToken?: string) => {
}
}

export const signout = async (username: string, password: string) => {
export const signout = async (
username: string,
password: string
): Promise<void> => {
const request = await fetch('https://authserver.mojang.com/signout', {
method: 'POST',
headers: { 'content-type': 'application/json' },
Expand All @@ -75,7 +81,10 @@ export const signout = async (username: string, password: string) => {
}
}

export const invalidate = async (accessToken: string, clientToken: string) => {
export const invalidate = async (
accessToken: string,
clientToken: string
): Promise<void> => {
const request = await fetch('https://authserver.mojang.com/invalidate', {
method: 'POST',
headers: { 'content-type': 'application/json' },
Expand Down
8 changes: 4 additions & 4 deletions src/minecraft/chatToJsx.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export interface HoverEvent {
value: MinecraftChat
}

const hasColorCodes = (s: string) => /§[0-9a-fk-orx]/.test(s)
const hasColorCodes = (s: string): boolean => /§[0-9a-fk-orx]/.test(s)
// const stripColorCodes = (s: string) => s.replace(/§[0-9a-fk-orx]/g, '').trim()
const parseColorCodes = (arg: string | PlainTextChat): PlainTextChat[] => {
let s: string
Expand Down Expand Up @@ -253,7 +253,7 @@ const parseChatToJsx = (
clickEventHandler: (clickEvent: ClickEvent) => void = () => {},
componentProps?: Record<string, unknown>,
trim = false
) => {
): JSX.Element => {
let flat = sanitizeComponents(flattenComponents(chat))
if (trim) flat = trimComponentsByLine(flat)
return (
Expand Down Expand Up @@ -296,7 +296,7 @@ export const ChatToJsx = (props: {
componentProps?: Record<string, unknown>
clickEventHandler?: (clickEvent: ClickEvent) => void
trim?: boolean
}) =>
}): JSX.Element =>
parseChatToJsx(
props.chat ?? { text: '' },
props.component,
Expand All @@ -306,7 +306,7 @@ export const ChatToJsx = (props: {
props.trim
)

export const parseValidJson = (text: string) => {
export const parseValidJson = (text: string): any => {
try {
return JSON.parse(text)
} catch (e) {
Expand Down
4 changes: 3 additions & 1 deletion src/minecraft/connection/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ export interface ServerConnection extends events.EventEmitter {
((event: string, listener: Function) => this) // eslint-disable-line @typescript-eslint/ban-types
}

const initiateConnection = async (opts: ConnectionOptions) => {
const initiateConnection = async (
opts: ConnectionOptions
): Promise<ServerConnection> => {
if (isNativeConnectionAvailable()) {
return await initiateNativeConnection(opts)
}
Expand Down
6 changes: 4 additions & 2 deletions src/minecraft/connection/javascript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export class JavaScriptServerConnection
}

onlyOneCloseCall = false
close() {
close(): void {
if (this.onlyOneCloseCall) return
else this.onlyOneCloseCall = true

Expand All @@ -81,7 +81,9 @@ export class JavaScriptServerConnection
}
}

const initiateJavaScriptConnection = async (opts: ConnectionOptions) => {
const initiateJavaScriptConnection = async (
opts: ConnectionOptions
): Promise<JavaScriptServerConnection> => {
const [host, port] = await resolveHostname(opts.host, opts.port)
const socket = net.createConnection({ host, port })
const conn = new JavaScriptServerConnection(socket, opts)
Expand Down
Loading

0 comments on commit 94feb06

Please sign in to comment.