Skip to content

Commit 94feb06

Browse files
committed
Require explicit function return types w/ ESLint.
1 parent 9870cad commit 94feb06

34 files changed

+112
-80
lines changed

.eslintrc.js

-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ module.exports = {
3333
'@typescript-eslint/restrict-plus-operands': 'off',
3434
'@typescript-eslint/no-dynamic-delete': 'off',
3535
'@typescript-eslint/no-var-requires': 'off',
36-
'@typescript-eslint/explicit-function-return-type': 'off', // TODO: Enable later.
3736
// Adjust to Prettier's presence. (Maybe we should do away with it later.)
3837
'@typescript-eslint/space-before-function-paren': 'off',
3938
'@typescript-eslint/member-delimiter-style': 'off',

src/App.tsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ export interface RootStackParamList {
4343
Home: undefined
4444
Chat: { serverName: string; version: number }
4545
}
46-
type HomeNavigationProp = NativeStackNavigationProp<RootStackParamList, 'Home'>
46+
type HomeProp = NativeStackNavigationProp<RootStackParamList, 'Home'>
4747

48-
const HomeScreen = ({ navigation }: { navigation: HomeNavigationProp }) => {
48+
const HomeScreen = ({ navigation }: { navigation: HomeProp }): JSX.Element => {
4949
const { connection } = React.useContext(ConnectionContext)
5050
React.useEffect(() => {
5151
if (connection) {
@@ -92,7 +92,7 @@ const HomeScreen = ({ navigation }: { navigation: HomeNavigationProp }) => {
9292
)
9393
}
9494

95-
const App = () => {
95+
const App = (): JSX.Element => {
9696
const [connection, setConnection] = React.useState<
9797
ServerConnection | undefined
9898
>()
@@ -109,9 +109,9 @@ const App = () => {
109109
const [serversStore, setServersStore] = useAsyncStorage('@servers', '{}')
110110
const accounts: Accounts = JSON.parse(accountsStore)
111111
const servers: Servers = JSON.parse(serversStore)
112-
const setAccounts = (newAccounts: Accounts) =>
112+
const setAccounts = (newAccounts: Accounts): void =>
113113
setAccountsStore(JSON.stringify(newAccounts))
114-
const setServers = (newServers: Servers) =>
114+
const setServers = (newServers: Servers): void =>
115115
setServersStore(JSON.stringify(newServers))
116116

117117
const colorScheme = useColorScheme()

src/components/Dialog.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const Dialog = ({
1717
visible: boolean
1818
onRequestClose: () => void
1919
containerStyles?: ViewStyle
20-
}>) => (
20+
}>): JSX.Element => (
2121
<Modal
2222
animationType='fade'
2323
transparent

src/components/DisconnectDialog.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
import Dialog, { dialogStyles } from './Dialog'
1212
import Text from './Text'
1313

14-
const DisconnectDialog = () => {
14+
const DisconnectDialog = (): JSX.Element => {
1515
const darkMode = useDarkMode()
1616
const { disconnectReason, setDisconnectReason } =
1717
useContext(ConnectionContext)

src/components/ElevatedView.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import useDarkMode from '../context/useDarkMode'
44

55
const ElevatedView = (
66
props: React.PropsWithChildren<{ style?: ViewStyle }>
7-
) => (
7+
): JSX.Element => (
88
<View
99
{...props}
1010
style={Object.assign(

src/components/Text.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
} from 'react-native'
88
import useDarkMode from '../context/useDarkMode'
99

10-
const Text = (props: React.PropsWithChildren<TextProps>) => (
10+
const Text = (props: React.PropsWithChildren<TextProps>): JSX.Element => (
1111
<RNText
1212
{...props}
1313
style={[

src/components/TextField.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react'
22
import { TextInput, StyleSheet, type TextInputProps } from 'react-native'
33
import useDarkMode from '../context/useDarkMode'
44

5-
const TextField = (props: TextInputProps & { red?: boolean }) => {
5+
const TextField = (props: TextInputProps & { red?: boolean }): JSX.Element => {
66
const style = props.style?.valueOf()
77
const darkMode = useDarkMode()
88
return (

src/components/TextFieldDialog.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ const TextFieldDialog = ({
2424
closeModal: () => void
2525
initialState: string
2626
setFinalState: (state: string) => void
27-
}) => {
27+
}): JSX.Element => {
2828
const [modalContent, setModalContent] = useState(initialState)
29-
const closeModalAndSaveState = () => {
29+
const closeModalAndSaveState = (): void => {
3030
setFinalState(modalContent)
3131
closeModal()
3232
}
33-
const closeModalAndReset = () => {
33+
const closeModalAndReset = (): void => {
3434
setModalContent(initialState)
3535
closeModal()
3636
}

src/components/accounts/AccountDisplay.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const AccountDisplay = ({
1616
darkMode: boolean
1717
setActiveAccount: (uuid: string) => void
1818
setDeleteAccount: (uuid: string) => void
19-
}) => (
19+
}): JSX.Element => (
2020
<ElevatedView style={styles.accountView}>
2121
<Pressable
2222
onPress={() => setActiveAccount(uuid)}

src/components/accounts/AddAccountDialog.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const AddAccountDialog = ({
1616
}: {
1717
open: boolean
1818
setOpen: React.Dispatch<React.SetStateAction<boolean>>
19-
}) => {
19+
}): JSX.Element => {
2020
const darkMode = useDarkMode()
2121
const { accounts, setAccounts } = useContext(UsersContext)
2222

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

35-
const cancelAddAccount = () => {
35+
const cancelAddAccount = (): void => {
3636
setMicrosoftLogin(false)
3737
setOpen(false)
3838
setUserRed(false)
@@ -41,7 +41,7 @@ const AddAccountDialog = ({
4141
setPassword(null) // setPassword('')
4242
setDialogError('')
4343
}
44-
const addAccount = () => {
44+
const addAccount = (): void => {
4545
const accountExists =
4646
!!accounts[newUser] ||
4747
!!Object.keys(accounts).find(id => accounts[id].email === newUser)

src/components/accounts/MicrosoftLogin.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
} from '../../minecraft/api/microsoft'
1818
import config from '../../../config.json'
1919

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

3232
const addAccount = (
3333
id: string,
@@ -54,12 +54,12 @@ const MicrosoftLogin = ({ close }: { close: () => void }) => {
5454
return alreadyExists
5555
}
5656

57-
const onRequestClose = () => {
57+
const onRequestClose = (): void => {
5858
if (!loading) close()
5959
}
6060
const handleNavigationStateChange = async (
6161
newNavState: WebViewNavigation
62-
) => {
62+
): Promise<void> => {
6363
// LOW-TODO: Parse errors.
6464
if (!webview.current || !newNavState.url) return
6565
if (

src/components/servers/EditServerDialog.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const EditServerDialog = ({
2727
deleteServer: (server: string) => void
2828
editServerDialogOpen: string | boolean
2929
setEditServerDialogOpen: (server: string | boolean) => void
30-
}) => {
30+
}): JSX.Element => {
3131
const [ipAddr, setIpAddr] = useState('')
3232
const [ipAddrRed, setIpAddrRed] = useState(false)
3333
const [newServerName, setNewServerName] = useState('')
@@ -54,15 +54,15 @@ const EditServerDialog = ({
5454
}
5555
}, [editServerDialogOpen, server])
5656

57-
const closeDialog = () => setEditServerDialogOpen(false)
57+
const closeDialog = (): void => setEditServerDialogOpen(false)
5858

59-
const handleDeleteServer = () => {
59+
const handleDeleteServer = (): void => {
6060
if (typeof editServerDialogOpen !== 'string') return
6161
deleteServer(editServerDialogOpen)
6262
closeDialog()
6363
}
6464

65-
const handleEditServer = () => {
65+
const handleEditServer = (): void => {
6666
const edit = typeof editServerDialogOpen === 'string'
6767
if (
6868
!newServerName ||

src/components/servers/ServerDisplay.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const ServerDisplay = ({
2929
darkMode: boolean
3030
connectToServer: (server: string) => void
3131
openEditServerDialog: (server: string) => void
32-
}) => (
32+
}): JSX.Element => (
3333
<ElevatedView style={styles.serverView}>
3434
<Pressable
3535
onPress={() => connectToServer(server)}

src/components/settings/DarkModeSetting.tsx

+5-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import useDarkMode from '../../context/useDarkMode'
1515
const RadioButton = (props: {
1616
style?: StyleProp<ViewStyle>
1717
selected: boolean
18-
}) => {
18+
}): JSX.Element => {
1919
const darkMode = useDarkMode()
2020
return (
2121
<View
@@ -58,7 +58,10 @@ interface DarkModeSettingProps {
5858
setValue: (newValue: boolean | null) => void
5959
}
6060

61-
const DarkModeSetting = ({ value, setValue }: DarkModeSettingProps) => {
61+
const DarkModeSetting = ({
62+
value,
63+
setValue
64+
}: DarkModeSettingProps): JSX.Element => {
6265
const [modalOpen, setModalOpen] = useState(false)
6366
const ripple = { color: '#aaa' }
6467
const dark = useDarkMode()

src/components/settings/Setting.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const Setting = <T extends string | boolean>({
2020
setValue?: (newValue: T) => void
2121
multiline?: boolean
2222
maxLength?: number
23-
}) => {
23+
}): JSX.Element => {
2424
const da = useDarkMode()
2525
const [modalOpen, setModalOpen] = useState(false)
2626
const [modalContent, setModalContent] = useState(
@@ -30,7 +30,7 @@ const Setting = <T extends string | boolean>({
3030
const [toggleValue, setToggleValue] = useState(value)
3131

3232
const Wrapper = setValue ?? onClick ? Pressable : React.Fragment
33-
const wrapperPress = () => {
33+
const wrapperPress = (): void => {
3434
if (onClick) onClick()
3535
else if (typeof value === 'boolean' && setValue) {
3636
setValue(!toggleValue as T)

src/context/useDarkMode.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ import { createContext, useContext } from 'react'
22

33
export const ColorSchemeContext = createContext<boolean>(false)
44

5-
const useDarkMode = () => useContext(ColorSchemeContext)
5+
const useDarkMode = (): boolean => useContext(ColorSchemeContext)
66

77
export default useDarkMode

src/minecraft/api/microsoft.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,9 @@ export const authenticateWithXsts = async (
115115
return res.access_token
116116
}
117117

118-
export const checkGameOwnership = async (accessToken: string) => {
118+
export const checkGameOwnership = async (
119+
accessToken: string
120+
): Promise<boolean> => {
119121
const req = await fetch(mcStoreUrl, {
120122
headers: {
121123
Accept: 'application/json',
@@ -125,7 +127,7 @@ export const checkGameOwnership = async (accessToken: string) => {
125127
if (!req.ok) throw new Error('Failed to check if user owns Minecraft game!')
126128
const res = await req.json()
127129
const items = res.items as Array<{ name: string }>
128-
return (
130+
return !!(
129131
items?.length >= 2 &&
130132
items.find(item => item.name === 'game_minecraft') &&
131133
items.find(item => item.name === 'product_minecraft')

src/minecraft/api/mojang.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,16 @@ export const joinMinecraftSession = async (
1919
accessToken: string,
2020
selectedProfile: string,
2121
serverId: string
22-
) =>
22+
): Promise<Response> =>
2323
await fetch(joinMinecraftSessionUrl, {
2424
body: JSON.stringify({ accessToken, selectedProfile, serverId }),
2525
headers: { 'content-type': 'application/json' },
2626
method: 'POST'
2727
})
2828

29-
export const getPlayerCertificates = async (accessToken: string) =>
29+
export const getPlayerCertificates = async (
30+
accessToken: string
31+
): Promise<Certificate> =>
3032
await fetch(getPlayerCertificatesUrl, {
3133
headers: { Authorization: 'Bearer ' + accessToken },
3234
method: 'POST'

src/minecraft/api/yggdrasil.ts

+12-3
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ export const refresh = async (
5151
return await request.json()
5252
}
5353

54-
export const validate = async (accessToken: string, clientToken?: string) => {
54+
export const validate = async (
55+
accessToken: string,
56+
clientToken?: string
57+
): Promise<void> => {
5558
const request = await fetch('https://authserver.mojang.com/validate', {
5659
method: 'POST',
5760
headers: { 'content-type': 'application/json' },
@@ -64,7 +67,10 @@ export const validate = async (accessToken: string, clientToken?: string) => {
6467
}
6568
}
6669

67-
export const signout = async (username: string, password: string) => {
70+
export const signout = async (
71+
username: string,
72+
password: string
73+
): Promise<void> => {
6874
const request = await fetch('https://authserver.mojang.com/signout', {
6975
method: 'POST',
7076
headers: { 'content-type': 'application/json' },
@@ -75,7 +81,10 @@ export const signout = async (username: string, password: string) => {
7581
}
7682
}
7783

78-
export const invalidate = async (accessToken: string, clientToken: string) => {
84+
export const invalidate = async (
85+
accessToken: string,
86+
clientToken: string
87+
): Promise<void> => {
7988
const request = await fetch('https://authserver.mojang.com/invalidate', {
8089
method: 'POST',
8190
headers: { 'content-type': 'application/json' },

src/minecraft/chatToJsx.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export interface HoverEvent {
9191
value: MinecraftChat
9292
}
9393

94-
const hasColorCodes = (s: string) => /§[0-9a-fk-orx]/.test(s)
94+
const hasColorCodes = (s: string): boolean => /§[0-9a-fk-orx]/.test(s)
9595
// const stripColorCodes = (s: string) => s.replace(/§[0-9a-fk-orx]/g, '').trim()
9696
const parseColorCodes = (arg: string | PlainTextChat): PlainTextChat[] => {
9797
let s: string
@@ -253,7 +253,7 @@ const parseChatToJsx = (
253253
clickEventHandler: (clickEvent: ClickEvent) => void = () => {},
254254
componentProps?: Record<string, unknown>,
255255
trim = false
256-
) => {
256+
): JSX.Element => {
257257
let flat = sanitizeComponents(flattenComponents(chat))
258258
if (trim) flat = trimComponentsByLine(flat)
259259
return (
@@ -296,7 +296,7 @@ export const ChatToJsx = (props: {
296296
componentProps?: Record<string, unknown>
297297
clickEventHandler?: (clickEvent: ClickEvent) => void
298298
trim?: boolean
299-
}) =>
299+
}): JSX.Element =>
300300
parseChatToJsx(
301301
props.chat ?? { text: '' },
302302
props.component,
@@ -306,7 +306,7 @@ export const ChatToJsx = (props: {
306306
props.trim
307307
)
308308

309-
export const parseValidJson = (text: string) => {
309+
export const parseValidJson = (text: string): any => {
310310
try {
311311
return JSON.parse(text)
312312
} catch (e) {

src/minecraft/connection/index.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ export interface ServerConnection extends events.EventEmitter {
3737
((event: string, listener: Function) => this) // eslint-disable-line @typescript-eslint/ban-types
3838
}
3939

40-
const initiateConnection = async (opts: ConnectionOptions) => {
40+
const initiateConnection = async (
41+
opts: ConnectionOptions
42+
): Promise<ServerConnection> => {
4143
if (isNativeConnectionAvailable()) {
4244
return await initiateNativeConnection(opts)
4345
}

src/minecraft/connection/javascript.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export class JavaScriptServerConnection
6767
}
6868

6969
onlyOneCloseCall = false
70-
close() {
70+
close(): void {
7171
if (this.onlyOneCloseCall) return
7272
else this.onlyOneCloseCall = true
7373

@@ -81,7 +81,9 @@ export class JavaScriptServerConnection
8181
}
8282
}
8383

84-
const initiateJavaScriptConnection = async (opts: ConnectionOptions) => {
84+
const initiateJavaScriptConnection = async (
85+
opts: ConnectionOptions
86+
): Promise<JavaScriptServerConnection> => {
8587
const [host, port] = await resolveHostname(opts.host, opts.port)
8688
const socket = net.createConnection({ host, port })
8789
const conn = new JavaScriptServerConnection(socket, opts)

0 commit comments

Comments
 (0)