Skip to content

Commit 2c90fc6

Browse files
committed
Fix linting
1 parent d89bf2d commit 2c90fc6

20 files changed

Lines changed: 133 additions & 89 deletions

.prettierrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"semi": false,
55
"trailingComma": "es5",
66
"singleQuote": true,
7+
"bracketSpacing": false,
78
"plugins": ["prettier-plugin-sql"],
89
"overrides": [
910
{

backend/shared/src/supabase/init.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import pgPromise, {IDatabase, ITask} from 'pg-promise'
22
import {log, metrics} from '../utils'
3-
import {IClient, type IConnectionParameters} from 'pg-promise/typescript/pg-subset'
3+
import {IClient, type IConnectionParameters,} from 'pg-promise/typescript/pg-subset'
44
import {HOUR_MS} from 'common/util/time'
55
import {METRICS_INTERVAL_MS} from 'shared/monitoring/metric-writer'
66
import {getMonitoringContext} from 'shared/monitoring/context'
7-
import {ENV_CONFIG} from "common/envs/constants";
7+
import {ENV_CONFIG} from 'common/envs/constants'
88

99
export {SupabaseClient} from 'common/supabase/utils'
1010

@@ -32,8 +32,10 @@ export const pgp = pgPromise({
3232
pgp.pg.types.setTypeParser(20, (value: any) => parseInt(value, 10))
3333
pgp.pg.types.setTypeParser(1700, parseFloat) // Type Id 1700 = NUMERIC
3434

35-
export type SupabaseTransaction = ITask<{}>
36-
export type SupabaseDirectClient = IDatabase<{}, IClient> | SupabaseTransaction
35+
export type SupabaseTransaction = ITask<object>
36+
export type SupabaseDirectClient =
37+
| IDatabase<object, IClient>
38+
| SupabaseTransaction
3739

3840
export function getInstanceId() {
3941
return ENV_CONFIG.supabaseInstanceId
@@ -87,7 +89,7 @@ const newClient = (
8789
}
8890

8991
// Use one connection to avoid WARNING: Creating a duplicate database object for the same connection.
90-
let pgpDirect: IDatabase<{}, IClient> | null = null
92+
let pgpDirect: IDatabase<object, IClient> | null = null
9193

9294
export function createSupabaseDirectClient(
9395
instanceId?: string,
@@ -128,7 +130,7 @@ export function createSupabaseDirectClient(
128130
return (pgpDirect = client)
129131
}
130132

131-
let shortTimeoutPgpClient: IDatabase<{}, IClient> | null = null
133+
let shortTimeoutPgpClient: IDatabase<object, IClient> | null = null
132134
export const createShortTimeoutDirectClient = () => {
133135
if (shortTimeoutPgpClient) return shortTimeoutPgpClient
134136
shortTimeoutPgpClient = newClient({

common/src/envs/is-prod.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export const isProd = () => {
77
return process.env.NEXT_PUBLIC_FIREBASE_ENV?.toUpperCase() == 'PROD'
88
} else {
99
// For local scripts and cloud functions
10-
// eslint-disable-next-line @typescript-eslint/no-var-requires
10+
// eslint-disable-next-line @typescript-eslint/no-require-imports
1111
const admin = require('firebase-admin')
1212
return admin.app().options.projectId === 'compass-130ba'
1313
}

common/src/util/json.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export const safeJsonParse = (json: string | undefined | null) => {
22
try {
3-
return JSON.parse(json ?? '')
4-
} catch (e) {
3+
return JSON.parse(json ?? '')
4+
} catch {
55
return null
66
}
77
}

package.json

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,19 @@
4545
"prepare": "npx husky"
4646
},
4747
"lint-staged": {
48-
"*.{ts,tsx,js,jsx}": [
48+
"web/**/*.{ts,tsx,js,jsx}": [
49+
"next lint --fix --file",
50+
"next lint --max-warnings 0 --file"
51+
],
52+
"common/**/*.{ts,tsx,js,jsx}": [
53+
"eslint --fix",
54+
"eslint --max-warnings 0"
55+
],
56+
"backend/api/**/*.{ts,tsx,js,jsx}": [
57+
"eslint --fix",
58+
"eslint --max-warnings 0"
59+
],
60+
"backend/shared/**/*.{ts,tsx,js,jsx}": [
4961
"eslint --fix",
5062
"eslint --max-warnings 0"
5163
]

web/.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ module.exports = {
1515
'prettier',
1616
],
1717
rules: {
18+
"react/prop-types": "off",
1819
'react/display-name': 'off',
1920
'react/no-unescaped-entities': 'off',
2021
'react/jsx-no-target-blank': 'off',

web/components/answers/add-compatibility-question-button.tsx

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,7 @@ export function AddCompatibilityQuestionButton(props: {
2929
if (!user) return null
3030
return (
3131
<>
32-
<button
33-
type="button"
34-
onClick={() => setOpen(true)}
35-
className="text-sm"
36-
>
32+
<button type="button" onClick={() => setOpen(true)} className="text-sm">
3733
{t('answers.add.submit_own', 'submit your own!')}
3834
</button>
3935
<AddCompatibilityQuestionModal
@@ -55,9 +51,8 @@ function AddCompatibilityQuestionModal(props: {
5551
onClose?: () => void
5652
}) {
5753
const {open, setOpen, user, onClose} = props
58-
const [dbQuestion, setDbQuestion] = useState<rowFor<'compatibility_prompts'> | null>(
59-
null
60-
)
54+
const [dbQuestion, setDbQuestion] =
55+
useState<rowFor<'compatibility_prompts'> | null>(null)
6156
const afterAddQuestion = (newQuestion: rowFor<'compatibility_prompts'>) => {
6257
setDbQuestion(newQuestion)
6358
console.debug('setDbQuestion', newQuestion)
@@ -125,29 +120,37 @@ function CreateCompatibilityModalContent(props: {
125120

126121
const generateJson = () => {
127122
// Note the change in the generic type
128-
return options.reduce((obj, item, index) => {
129-
if (item.trim() !== '') {
130-
obj[item] = index // Mapping each option to its index
131-
}
132-
return obj
133-
}, {} as Record<string, number>)
123+
return options.reduce(
124+
(obj, item, index) => {
125+
if (item.trim() !== '') {
126+
obj[item] = index // Mapping each option to its index
127+
}
128+
return obj
129+
},
130+
{} as Record<string, number>
131+
)
134132
}
135133

136134
const onAddQuestion = useEvent(async () => {
137135
try {
138136
const data = {
139137
question: question,
140138
options: generateJson(),
141-
};
139+
}
142140
const newQuestion = await api('create-compatibility-question', data)
143141
console.debug('create-compatibility-question', newQuestion, data)
144142
const q = newQuestion?.question
145143
if (q) {
146144
afterAddQuestion(q as rowFor<'compatibility_prompts'>)
147145
}
148146
track('create compatibility question')
149-
} catch (e) {
150-
toast.error(t('answers.add.error_create', 'Error creating compatibility question. Try again?'))
147+
} catch (_e) {
148+
toast.error(
149+
t(
150+
'answers.add.error_create',
151+
'Error creating compatibility question. Try again?'
152+
)
153+
)
151154
}
152155
})
153156

@@ -176,7 +179,9 @@ function CreateCompatibilityModalContent(props: {
176179
value={options[index]}
177180
onChange={(e) => onOptionChange(index, e.target.value)}
178181
className="w-full"
179-
placeholder={t('answers.add.option_placeholder', 'Option {n}', {n: String(index + 1)})}
182+
placeholder={t('answers.add.option_placeholder', 'Option {n}', {
183+
n: String(index + 1),
184+
})}
180185
rows={1}
181186
maxLength={MAX_ANSWER_LENGTH}
182187
/>

web/components/answers/answer-compatibility-question-content.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export const submitCompatibilityAnswer = async (
6767
explanation: input.explanation ?? null,
6868
})
6969

70-
// Track only if the upsert succeeds
70+
// Track only if upsert succeeds
7171
track('answer compatibility question', {
7272
...newAnswer,
7373
})
@@ -179,7 +179,7 @@ export function AnswerCompatibilityQuestionContent(props: {
179179
{shortenedPopularity && (
180180
<Row className="text-ink-500 select-none items-center text-sm">
181181
<Tooltip
182-
text={t('answers.content.people_answered', '{count} people have answered this question', { count: String(shortenedPopularity) })}
182+
text={t('answers.content.people_answered', '{count} people have answered this question', {count: String(shortenedPopularity)})}
183183
>
184184
{shortenedPopularity}
185185
</Tooltip>
@@ -204,7 +204,8 @@ export function AnswerCompatibilityQuestionContent(props: {
204204
/>
205205
</Col>
206206
<Col className="gap-2">
207-
<span className="text-ink-500 text-sm">{t('answers.content.answers_you_accept', "Answers you'll accept")}</span>
207+
<span
208+
className="text-ink-500 text-sm">{t('answers.content.answers_you_accept', "Answers you'll accept")}</span>
208209
<MultiSelectAnswers
209210
values={answer.pref_choices ?? []}
210211
setValue={(choice) =>

web/components/editor/floating-format-menu.tsx

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
import { LinkIcon, CheckIcon, TrashIcon } from '@heroicons/react/solid'
2-
import { Editor } from '@tiptap/core'
3-
import { BubbleMenu } from '@tiptap/react'
1+
import {CheckIcon, LinkIcon, TrashIcon} from '@heroicons/react/solid'
2+
import {Editor} from '@tiptap/core'
3+
import {BubbleMenu} from '@tiptap/react'
44
import clsx from 'clsx'
5-
import { getUrl } from 'common/util/parse'
6-
import { useState } from 'react'
7-
import BoldIcon from 'web/lib/icons/bold-icon.svg'
8-
import ItalicIcon from 'web/lib/icons/italic-icon.svg'
9-
import TypeIcon from 'web/lib/icons/type-icon.svg'
5+
import {getUrl} from 'common/util/parse'
6+
import {useState} from 'react'
7+
import {Bold, Italic, Type} from 'lucide-react'
108

119
// see https://tiptap.dev/guide/menus
1210

@@ -40,14 +38,14 @@ export function FloatingFormatMenu(props: {
4038
{advanced && (
4139
<>
4240
<IconButton
43-
icon={TypeIcon}
41+
icon={Type}
4442
onClick={() =>
4543
editor.chain().focus().toggleHeading({ level: 1 }).run()
4644
}
4745
isActive={editor.isActive('heading', { level: 1 })}
4846
/>
4947
<IconButton
50-
icon={TypeIcon}
48+
icon={Type}
5149
onClick={() =>
5250
editor.chain().focus().toggleHeading({ level: 2 }).run()
5351
}
@@ -58,12 +56,12 @@ export function FloatingFormatMenu(props: {
5856
</>
5957
)}
6058
<IconButton
61-
icon={BoldIcon}
59+
icon={Bold}
6260
onClick={() => editor.chain().focus().toggleBold().run()}
6361
isActive={editor.isActive('bold')}
6462
/>
6563
<IconButton
66-
icon={ItalicIcon}
64+
icon={Italic}
6765
onClick={() => editor.chain().focus().toggleItalic().run()}
6866
isActive={editor.isActive('italic')}
6967
/>

web/components/multi-checkbox.tsx

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import {Input} from 'web/components/widgets/input'
44
import {Button} from 'web/components/buttons/button'
55
import clsx from 'clsx'
66
import {useEffect, useMemo, useState} from 'react'
7-
import {useT} from "web/lib/locale";
8-
import {toKey} from "common/parsing";
7+
import {useT} from 'web/lib/locale'
8+
import {toKey} from 'common/parsing'
99

1010
export const MultiCheckbox = (props: {
1111
// Map of label -> value
@@ -20,14 +20,27 @@ export const MultiCheckbox = (props: {
2020
// - string: the stored value for the new option; label will be the input text
2121
// - { key, value }: explicit label (key) and stored value
2222
// - null/undefined to indicate failure/cancellation
23-
addOption?: (label: string) => string | { key: string; value: string } | null | undefined
23+
addOption?: (
24+
label: string
25+
) => string | { key: string; value: string } | null | undefined
2426
addPlaceholder?: string
2527
translationPrefix?: string
2628
}) => {
27-
const {choices, selected, onChange, className, optionsClassName, addOption, addPlaceholder, translationPrefix} = props
29+
const {
30+
choices,
31+
selected,
32+
onChange,
33+
className,
34+
optionsClassName,
35+
addOption,
36+
addPlaceholder,
37+
translationPrefix,
38+
} = props
2839

2940
// Keep a local merged copy to allow optimistic adds while remaining in sync with props
30-
const [localChoices, setLocalChoices] = useState<{ [key: string]: string }>(choices)
41+
const [localChoices, setLocalChoices] = useState<{ [key: string]: string }>(
42+
choices
43+
)
3144
useEffect(() => {
3245
setLocalChoices((prev) => {
3346
// If incoming choices changed, merge them with any locally added that still don't collide
@@ -56,7 +69,9 @@ export const MultiCheckbox = (props: {
5669
let q = newLabel.trim()
5770
q = translateOption(q, q).toLowerCase()
5871
if (!q) return entries
59-
return entries.filter(([key, value]) => translateOption(key, value).toLowerCase().includes(q))
72+
return entries.filter(([key, value]) =>
73+
translateOption(key, value).toLowerCase().includes(q)
74+
)
6075
}, [addOption, entries, newLabel])
6176

6277
const submitAdd = async () => {
@@ -68,8 +83,10 @@ export const MultiCheckbox = (props: {
6883
return
6984
}
7085
// prevent duplicate by label or by value already selected
71-
const existingEntry = Object.entries(localChoices).find(([key, value]) =>
72-
translateOption(key, value).toLowerCase() === translateOption(label, label).toLowerCase()
86+
const existingEntry = Object.entries(localChoices).find(
87+
([key, value]) =>
88+
translateOption(key, value).toLowerCase() ===
89+
translateOption(label, label).toLowerCase()
7390
)
7491

7592
if (existingEntry) {
@@ -88,12 +105,13 @@ export const MultiCheckbox = (props: {
88105
setAdding(false)
89106
return
90107
}
91-
const {key, value} = typeof result === 'string' ? {key: label, value: result} : result
108+
const {key, value} =
109+
typeof result === 'string' ? {key: label, value: result} : result
92110
setLocalChoices((prev) => ({...prev, [key]: value}))
93111
// auto-select newly added option if not already selected
94112
if (!selected.includes(value)) onChange([...selected, value])
95113
setNewLabel('')
96-
} catch (e) {
114+
} catch (_e) {
97115
setError(t('multi-checkbox.add_failed', 'Failed to add option.'))
98116
} finally {
99117
setAdding(false)
@@ -106,7 +124,10 @@ export const MultiCheckbox = (props: {
106124
<Row className="items-center gap-2">
107125
<Input
108126
value={newLabel}
109-
placeholder={addPlaceholder ?? t('multi-checkbox.search_or_add', 'Search or add')}
127+
placeholder={
128+
addPlaceholder ??
129+
t('multi-checkbox.search_or_add', 'Search or add')
130+
}
110131
onChange={(e) => {
111132
setNewLabel(e.target.value)
112133
setError(null)
@@ -119,7 +140,12 @@ export const MultiCheckbox = (props: {
119140
}}
120141
className="h-10"
121142
/>
122-
<Button size="sm" onClick={submitAdd} loading={adding} disabled={adding}>
143+
<Button
144+
size="sm"
145+
onClick={submitAdd}
146+
loading={adding}
147+
disabled={adding}
148+
>
123149
{t('common.add', 'Add')}
124150
</Button>
125151
{error && <span className="text-sm text-error">{error}</span>}
@@ -144,9 +170,12 @@ export const MultiCheckbox = (props: {
144170
</Row>
145171
{addOption && newLabel.trim() && filteredEntries.length === 0 && (
146172
<div className="px-2 text-sm text-ink-500">
147-
{t('multi-checkbox.no_matching_options', 'No matching options, feel free to add it.')}
173+
{t(
174+
'multi-checkbox.no_matching_options',
175+
'No matching options, feel free to add it.'
176+
)}
148177
</div>
149178
)}
150179
</div>
151180
)
152-
}
181+
}

0 commit comments

Comments
 (0)