Skip to content

Commit

Permalink
chore: upgrade eslint to 9 version (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
uigywnkiub authored Dec 22, 2024
1 parent 7185e6a commit 822d158
Show file tree
Hide file tree
Showing 13 changed files with 396 additions and 249 deletions.
3 changes: 0 additions & 3 deletions .eslintrc.json

This file was deleted.

2 changes: 1 addition & 1 deletion app/lib/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ export const copyToClipboard = async (
try {
await navigator.clipboard.writeText(content)
toast.success(successTitle)
} catch (err) {
} catch {
toast.error(errorTitle)
}
}
Expand Down
6 changes: 0 additions & 6 deletions app/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,47 +56,41 @@ export default function manifest(): MetadataRoute.Manifest {
src: '/images/screenshots/home.png',
sizes: SCREENSHOT_SIZE_DESKTOP,
type: SCREENSHOT_TYPE,
// @ts-ignore
form_factor: SCREENSHOT_FORM_FACTOR_DESKTOP,
label: NAV_TITLE.HOME,
},
{
src: '/images/screenshots/monthly-report.png',
sizes: SCREENSHOT_SIZE_DESKTOP,
type: SCREENSHOT_TYPE,
// @ts-ignore
form_factor: SCREENSHOT_FORM_FACTOR_DESKTOP,
label: NAV_TITLE.MONTHLY_REPORT,
},
{
src: '/images/screenshots/chart.png',
sizes: SCREENSHOT_SIZE_DESKTOP,
type: SCREENSHOT_TYPE,
// @ts-ignore
form_factor: SCREENSHOT_FORM_FACTOR_DESKTOP,
label: NAV_TITLE.CHART,
},
{
src: '/images/screenshots/home-mobile.png',
sizes: SCREENSHOT_SIZE_MOBILE,
type: SCREENSHOT_TYPE,
// @ts-ignore
form_factor: SCREENSHOT_FORM_FACTOR_MOBILE,
label: `${NAV_TITLE.HOME} ${SCREENSHOT_MOBILE_SUFFIX}`,
},
{
src: '/images/screenshots/monthly-report-mobile.png',
sizes: SCREENSHOT_SIZE_MOBILE,
type: SCREENSHOT_TYPE,
// @ts-ignore
form_factor: SCREENSHOT_FORM_FACTOR_MOBILE,
label: `${NAV_TITLE.MONTHLY_REPORT} ${SCREENSHOT_MOBILE_SUFFIX}`,
},
{
src: '/images/screenshots/categories-mobile.png',
sizes: SCREENSHOT_SIZE_MOBILE,
type: SCREENSHOT_TYPE,
// @ts-ignore
form_factor: SCREENSHOT_FORM_FACTOR_MOBILE,
label: `${NAV_TITLE.CATEGORIES} ${SCREENSHOT_MOBILE_SUFFIX}`,
},
Expand Down
10 changes: 7 additions & 3 deletions app/ui/balance-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ function BalanceCard({ balance, currency, user }: TProps) {
<>
{!isLoading && isTotalLoaded ? (
<motion.div
className='flex select-none flex-wrap justify-center gap-0 text-lg font-semibold md:gap-2'
className='flex select-none flex-wrap justify-center gap-0 text-lg md:gap-2'
initial={{ opacity: 0, scale: 0 }}
animate={{ opacity: 1, scale: 1 }}
transition={{ ...DIV.TRANSITION_SPRING }}
Expand All @@ -109,12 +109,16 @@ function BalanceCard({ balance, currency, user }: TProps) {
<span className='text-sm text-default-500'>
Income:
</span>{' '}
{getFormattedCurrency(total.income)} {currency?.code}
<span className='font-semibold'>
{getFormattedCurrency(total.income)} {currency?.code}
</span>
</p>
<p>
<PiArrowCircleDownFill className='mr-1 inline fill-danger' />
<span className='text-sm text-default-500'>Expense:</span>{' '}
{getFormattedCurrency(total.expense)} {currency?.code}
<span className='font-semibold'>
{getFormattedCurrency(total.expense)} {currency?.code}
</span>
</p>
</motion.div>
) : (
Expand Down
2 changes: 1 addition & 1 deletion app/ui/chart/custom-tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function CustomTooltip({ active, payload, label, currency }: TProps) {
<span className='text-xs text-default-500 md:text-sm'>
{capitalizeFirstLetter(item.dataKey)}:{' '}
</span>
<span>
<span className='font-semibold'>
{getFormattedCurrency(item.value)} {currency?.code}
</span>
</p>
Expand Down
18 changes: 11 additions & 7 deletions app/ui/monthly-report/month-picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,18 @@ function MonthPicker({
)

const daysInMonth = getDaysInMonth(new Date())
const maxTransactionDayOfMonth = toCalendarDate(
maxTransaction?.createdAt!,
).day
const maxTransactionDayOfMonth = maxTransaction?.createdAt
? toCalendarDate(maxTransaction.createdAt).day
: 1

const minTransactionValue = toCalendarDate(minTransaction?.createdAt!)
const maxTransactionValue = toCalendarDate(maxTransaction?.createdAt!).add({
days: daysInMonth - maxTransactionDayOfMonth,
})
const minTransactionValue = minTransaction
? toCalendarDate(minTransaction.createdAt)
: null
const maxTransactionValue = maxTransaction
? toCalendarDate(maxTransaction.createdAt).add({
days: daysInMonth - maxTransactionDayOfMonth,
})
: null

// Docs https://github.com/streamich/react-use/blob/master/docs/useDebounce.md
const [isReady, cancel] = useDebounce(
Expand Down
23 changes: 16 additions & 7 deletions app/ui/monthly-report/monthly-report.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,29 +46,38 @@ type TProps = {
function MonthlyReport({ transactions, currency }: TProps) {
const [tipsDataAI, setTipsDataAI] = useState<TExpenseAdvice[] | null>(null)
const [isLoadingTips, setIsLoadingTips] = useState(false)

const { canAttempt, registerAttempt } = useAttemptTracker('expense-ai-tips')
const { minTransaction, maxTransaction } = useMemo(
() => getMinMaxTransactionsByDate(transactions),
[transactions],
)
const minTransactionCalendarDate = toCalendarDate(minTransaction?.createdAt!)

const minTransactionCalendarDate = minTransaction
? toCalendarDate(minTransaction.createdAt)
: null
const startOfMonthCalendarDate = toCalendarDate(startOfMonth(startOfToday()))
const endOfMonthCalendarDate = toCalendarDate(endOfMonth(endOfToday()))

const isMinTransactionAfterStartOfMonth =
minTransactionCalendarDate &&
minTransactionCalendarDate.day > 1 &&
minTransactionCalendarDate.month === startOfMonthCalendarDate.month

const [selectedDate, setSelectedDate] = useState<RangeValue<DateValue>>({
start: isMinTransactionAfterStartOfMonth
? minTransactionCalendarDate
: startOfMonthCalendarDate,
end: endOfMonthCalendarDate,
})
const startDate = selectedDate?.start.toDate(getLocalTimeZone())
const endDate = selectedDate?.end.toDate(getLocalTimeZone())
const formattedDateRange = useMemo(
() => `${format(startDate, 'MMMM d')}${format(endDate, 'MMMM d')}`,
[startDate, endDate],
)

const startDate = selectedDate.start?.toDate(getLocalTimeZone()) || null
const endDate = selectedDate.end?.toDate(getLocalTimeZone()) || null

const formattedDateRange = useMemo(() => {
if (!startDate || !endDate) return ''
return `${format(startDate, 'MMMM d')}${format(endDate, 'MMMM d')}`
}, [startDate, endDate])

const onDateSelection = useCallback((dateRange: RangeValue<DateValue>) => {
setSelectedDate(dateRange)
Expand Down
1 change: 0 additions & 1 deletion app/ui/settings/currency.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ const currencies: {
// ImgComponent={Image}
ImgComponent={'img'}
imgProps={{
// @ts-ignore
// quality: 100,
width: DEFAULT_ICON_SIZE,
height: DEFAULT_ICON_SIZE,
Expand Down
1 change: 0 additions & 1 deletion app/ui/sidebar/user-profile-info.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ function UserProfileInfo({ user }: TProps) {
// ImgComponent: Image,
ImgComponent: 'img',
imgProps: {
// @ts-ignore
// priority: true,
// quality: 100,
width: 40,
Expand Down
5 changes: 2 additions & 3 deletions app/ui/transaction-form-edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function TransactionFormEdit({ transaction }: TProps) {
: [getCategoryWithoutEmoji(transaction.category)],
),
)
// @ts-ignore
// @ts-expect-error - Property 'size' does not exist on type 'Selection', but it does.
const isCategorySelect = Boolean(category.size)
const categoryName = Array.from(category)[0]?.toString()
const userCategories = transaction.categories || DEFAULT_CATEGORIES
Expand All @@ -80,9 +80,8 @@ function TransactionFormEdit({ transaction }: TProps) {
newData: Partial<TTransaction>,
oldData: TTransaction,
) => {
const { amount, ...restOldData } = oldData
const modifiedOldData: TTransaction = {
...restOldData,
...oldData,
amount: getFormattedCurrency(oldData.amount),
}
return Object.keys(newData).some((key) => {
Expand Down
83 changes: 83 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { FlatCompat } from '@eslint/eslintrc'
import js from '@eslint/js'
import typescriptEslintEslintPlugin from '@typescript-eslint/eslint-plugin'
import tsParser from '@typescript-eslint/parser'
import jsxA11y from 'eslint-plugin-jsx-a11y'
import prettier from 'eslint-plugin-prettier'
import path from 'node:path'
import { fileURLToPath } from 'node:url'

const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all,
})

export default [
...compat.extends('next', 'next/core-web-vitals', 'prettier'),
{
plugins: {
prettier,
jsxA11y,
},

rules: {
'prettier/prettier': 'error',
camelcase: 'off',
'import/prefer-default-export': 'off',
'react/jsx-filename-extension': 'off',
'react/jsx-props-no-spreading': 'off',
'react/no-unused-prop-types': 'off',
'react/require-default-props': 'off',

'import/extensions': [
'error',
'ignorePackages',
{
ts: 'never',
tsx: 'never',
js: 'never',
jsx: 'never',
},
],

'jsx-a11y/anchor-is-valid': [
'error',
{
components: ['Link'],
specialLink: ['hrefLeft', 'hrefRight'],
aspects: ['invalidHref', 'preferButton'],
},
],
},
},
...compat
.extends('plugin:@typescript-eslint/recommended', 'prettier')
.map((config) => ({
...config,
files: ['**/*.+(ts|tsx)'],
})),
{
files: ['**/*.+(ts|tsx)'],

plugins: {
'@typescript-eslint': typescriptEslintEslintPlugin,
},

languageOptions: {
parser: tsParser,
},

rules: {
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'no-use-before-define': [0],
'@typescript-eslint/no-use-before-define': [1],
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/no-unused-vars': 'warn',
},
},
]
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"start": "next start",
"lint": "next lint",
"lint:fix": "next lint",
"lint:all": "pnpm prettier && pnpm lint && pnpm typecheck && pnpm test && echo \"\\x1b[32m✔ All linters passed successfully!\\x1b[0m\"",
"lint:all": "pnpm prettier && pnpm lint && pnpm typecheck && pnpm test",
"typecheck": "tsc",
"test": "vitest run",
"test:dev": "vitest",
Expand Down Expand Up @@ -60,19 +60,24 @@
"devDependencies": {
"@commitlint/cli": "^19.6.1",
"@commitlint/config-conventional": "^19.6.0",
"@eslint/eslintrc": "^3.2.0",
"@eslint/js": "^9.17.0",
"@svgr/webpack": "^8.1.0",
"@testing-library/dom": "^10.4.0",
"@testing-library/react": "^16.1.0",
"@trivago/prettier-plugin-sort-imports": "^5.2.0",
"@types/node": "^22.10.2",
"@types/react": "19.0.2",
"@types/react-dom": "19.0.2",
"@typescript-eslint/eslint-plugin": "^8.18.1",
"@typescript-eslint/parser": "^8.18.1",
"@vitejs/plugin-react": "^4.3.4",
"@vitest/coverage-v8": "^2.1.8",
"eslint": "^8.57.1",
"eslint": "^9.17.0",
"eslint-config-next": "15.1.2",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-jsx-a11y": "^6.10.2",
"eslint-plugin-prettier": "^5.2.1",
"husky": "^9.1.7",
"jsdom": "^25.0.1",
"knip": "^5.41.1",
Expand Down
Loading

0 comments on commit 822d158

Please sign in to comment.