From 52c398b0ca4530a3f0a53567bffbccd46bca4aec Mon Sep 17 00:00:00 2001 From: Joe Gasiorek Date: Tue, 25 Jun 2024 13:31:57 -0700 Subject: [PATCH] FFS-975: Enable Unused import eslint plugin --- .eslintrc.json | 16 ++++++++- app/StoreProvider.tsx | 2 +- app/components/TextFieldWithValidation.tsx | 2 +- app/ledger/expense/add/page.test.tsx | 2 +- app/ledger/expense/add/page.tsx | 8 ++--- app/ledger/expense/list/page.test.tsx | 4 +-- app/ledger/expense/list/page.tsx | 2 +- app/ledger/expense/page.test.tsx | 4 +-- app/ledger/expense/snap/page.test.tsx | 2 +- app/ledger/expense/snap/page.tsx | 5 +-- .../expense/snap/recommend/page.test.tsx | 3 +- app/ledger/expense/snap/recommend/page.tsx | 2 +- app/ledger/income/add/page.test.tsx | 5 +-- app/ledger/income/add/page.tsx | 2 +- app/ledger/income/list/page.test.tsx | 3 +- app/ledger/review/LedgerReviewHeader.test.tsx | 4 +-- app/ledger/review/SnapExpenses.test.tsx | 4 +-- app/ledger/review/page.test.tsx | 2 +- app/page.test.tsx | 2 +- app/statement/confirmation/page.tsx | 5 +-- app/statement/set/page.test.tsx | 3 +- lib/actions.ts | 2 +- lib/hooks.ts | 2 +- lib/store.ts | 2 +- package-lock.json | 33 +++++++++++++++++++ package.json | 1 + 26 files changed, 78 insertions(+), 44 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 0ab95fc..71bb546 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,3 +1,17 @@ { - "extends": ["plugin:i18next/recommended", "next/core-web-vitals"] + "extends": ["plugin:i18next/recommended", "next/core-web-vitals"], + "plugins": ["unused-imports"], + "rules": { + "no-unused-vars": "off", + "unused-imports/no-unused-imports": "error", + "unused-imports/no-unused-vars": [ + "warn", + { + "vars": "all", + "varsIgnorePattern": "^_", + "args": "after-used", + "argsIgnorePattern": "^_" + } + ] + } } diff --git a/app/StoreProvider.tsx b/app/StoreProvider.tsx index 287166b..1d4ee17 100644 --- a/app/StoreProvider.tsx +++ b/app/StoreProvider.tsx @@ -1,6 +1,6 @@ 'use client' import { useRef } from "react" -import { Provider, useDispatch } from "react-redux" +import { Provider } from "react-redux" import { makeStore, AppStore } from '../lib/store' export default function StoreProvider({ diff --git a/app/components/TextFieldWithValidation.tsx b/app/components/TextFieldWithValidation.tsx index 2ee937f..56824cb 100644 --- a/app/components/TextFieldWithValidation.tsx +++ b/app/components/TextFieldWithValidation.tsx @@ -1,4 +1,4 @@ -import { ErrorMessage, Label, RequiredMarker, TextInput } from "@trussworks/react-uswds" +import { ErrorMessage, Label, TextInput } from "@trussworks/react-uswds" import React, { FocusEventHandler } from "react" type Args = { diff --git a/app/ledger/expense/add/page.test.tsx b/app/ledger/expense/add/page.test.tsx index 1380318..2496c6b 100644 --- a/app/ledger/expense/add/page.test.tsx +++ b/app/ledger/expense/add/page.test.tsx @@ -1,4 +1,4 @@ -import { afterEach, beforeEach, describe, expect, it, test } from 'vitest' +import { afterEach, beforeEach, describe, expect, it } from 'vitest' import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react' import { Provider } from 'react-redux' import Page from './page' diff --git a/app/ledger/expense/add/page.tsx b/app/ledger/expense/add/page.tsx index 9f8fd06..a2becb6 100644 --- a/app/ledger/expense/add/page.tsx +++ b/app/ledger/expense/add/page.tsx @@ -2,14 +2,12 @@ import "@trussworks/react-uswds/lib/uswds.css" import "@trussworks/react-uswds/lib/index.css" import { useTranslation } from 'react-i18next' -import { Header, Title, Button, Form, FormGroup, Grid, GridContainer, Alert, Checkbox, DatePicker, ErrorMessage, ComboBox, Label, ValidationChecklist, ValidationItem, RequiredMarker } from '@trussworks/react-uswds' +import { Header, Title, Button, Form, FormGroup, Grid, GridContainer, Alert, Checkbox, DatePicker, ComboBox, Label, ValidationChecklist, ValidationItem, RequiredMarker } from '@trussworks/react-uswds' import { useAppDispatch } from "@/lib/hooks" -import { ExpenseItem, addExpense, selectExpenseItems } from "@/lib/features/ledger/expenses/expensesSlice" +import { ExpenseItem, addExpense } from "@/lib/features/ledger/expenses/expensesSlice" import { useRouter } from "next/navigation" -import { FieldErrors, SubmitHandler, useForm, Controller } from "react-hook-form" +import { SubmitHandler, useForm, Controller } from "react-hook-form" import TextFieldWithValidation from "@/app/components/TextFieldWithValidation" -import { useRef, useImperativeHandle } from "react" -import exp from "constants" import RequiredFieldDescription from "@/app/components/RequiredFieldDescription" export default function Page() { diff --git a/app/ledger/expense/list/page.test.tsx b/app/ledger/expense/list/page.test.tsx index 784e000..5427bd3 100644 --- a/app/ledger/expense/list/page.test.tsx +++ b/app/ledger/expense/list/page.test.tsx @@ -1,5 +1,5 @@ -import { afterEach, beforeEach, describe, expect, it, test } from 'vitest' -import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react' +import { afterEach, beforeEach, describe, expect, it } from 'vitest' +import { cleanup, render, screen } from '@testing-library/react' import { Provider } from 'react-redux' import Page from './page' import { makeStore } from '@/lib/store' diff --git a/app/ledger/expense/list/page.tsx b/app/ledger/expense/list/page.tsx index 3de7583..a879eae 100644 --- a/app/ledger/expense/list/page.tsx +++ b/app/ledger/expense/list/page.tsx @@ -2,7 +2,7 @@ import "@trussworks/react-uswds/lib/uswds.css" import "@trussworks/react-uswds/lib/index.css" -import { Header, Title, Button, ButtonGroup, CardGroup, ModalToggleButton, Modal, ModalHeading, ModalFooter, Card, CardBody, CardHeader, Grid, GridContainer, Label, TextInput, ModalRef } from '@trussworks/react-uswds' +import { Header, Title, Button, ButtonGroup, Grid, GridContainer } from '@trussworks/react-uswds' import { useTranslation } from 'react-i18next' import { useRouter } from "next/navigation" import ExpenseList from "@/app/components/ExpenseList" diff --git a/app/ledger/expense/page.test.tsx b/app/ledger/expense/page.test.tsx index 25e1742..95197a2 100644 --- a/app/ledger/expense/page.test.tsx +++ b/app/ledger/expense/page.test.tsx @@ -1,5 +1,5 @@ -import { afterEach, beforeEach, describe, expect, it, test } from 'vitest' -import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react' +import { afterEach, beforeEach, describe, expect, it } from 'vitest' +import { cleanup, render, screen } from '@testing-library/react' import { Provider } from 'react-redux' import Page from './page' import { makeStore } from '@/lib/store' diff --git a/app/ledger/expense/snap/page.test.tsx b/app/ledger/expense/snap/page.test.tsx index fba5a2e..1a980f4 100644 --- a/app/ledger/expense/snap/page.test.tsx +++ b/app/ledger/expense/snap/page.test.tsx @@ -1,4 +1,4 @@ -import { afterEach, beforeEach, describe, expect, it, test } from 'vitest' +import { afterEach, beforeEach, describe, expect, it } from 'vitest' import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react' import { Provider } from 'react-redux' import Page from './page' diff --git a/app/ledger/expense/snap/page.tsx b/app/ledger/expense/snap/page.tsx index 7d83f59..15a8511 100644 --- a/app/ledger/expense/snap/page.tsx +++ b/app/ledger/expense/snap/page.tsx @@ -2,9 +2,8 @@ import "@trussworks/react-uswds/lib/uswds.css" import "@trussworks/react-uswds/lib/index.css" -import { Header, Title, Button, HeadingLevel, Grid, GridContainer, Accordion, Radio, Form } from '@trussworks/react-uswds' +import { Header, Title, Button, Grid, GridContainer, Radio, Form } from '@trussworks/react-uswds' import { useRouter } from "next/navigation" -import Link from 'next/link' import { useTranslation } from "react-i18next" import { Controller, SubmitHandler, useForm } from "react-hook-form" @@ -19,8 +18,6 @@ export default function Page() { } const { - register, - formState: { errors }, handleSubmit, control } = useForm() diff --git a/app/ledger/expense/snap/recommend/page.test.tsx b/app/ledger/expense/snap/recommend/page.test.tsx index 8b241d9..80def18 100644 --- a/app/ledger/expense/snap/recommend/page.test.tsx +++ b/app/ledger/expense/snap/recommend/page.test.tsx @@ -1,6 +1,5 @@ -import { afterEach, beforeEach, describe, expect, it, test } from 'vitest' +import { afterEach, beforeEach, describe, expect, it } from 'vitest' import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react' -import { Provider } from 'react-redux' import Page from './page' import { makeStore } from '@/lib/store' import { vi } from 'vitest' diff --git a/app/ledger/expense/snap/recommend/page.tsx b/app/ledger/expense/snap/recommend/page.tsx index d0598b6..0b7bd36 100644 --- a/app/ledger/expense/snap/recommend/page.tsx +++ b/app/ledger/expense/snap/recommend/page.tsx @@ -48,7 +48,7 @@ export default function Page() { // User should not have been pushed to this screen return router.push('/ledger/review') } - }, []) + }, [benefits.snap, reccommendStandardDeduction, router]) return (
diff --git a/app/ledger/income/add/page.test.tsx b/app/ledger/income/add/page.test.tsx index 9c6a93a..0f22fff 100644 --- a/app/ledger/income/add/page.test.tsx +++ b/app/ledger/income/add/page.test.tsx @@ -1,14 +1,11 @@ -import { afterEach, beforeEach, describe, expect, it, test } from 'vitest' +import { afterEach, beforeEach, describe, expect, it } from 'vitest' import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react' import Page from './page' -import { makeStore } from '@/lib/store' import { vi } from 'vitest' -import { EnhancedStore } from '@reduxjs/toolkit' import mockRouter from 'next-router-mock' import TestWrapper from '@/app/TestWrapper' describe('Add Income To Ledger Page', async () => { - let store: EnhancedStore beforeEach(() => { vi.mock('next/navigation', () => require('next-router-mock')) mockRouter.push('/ledger/income/add') diff --git a/app/ledger/income/add/page.tsx b/app/ledger/income/add/page.tsx index 9e47663..07d5baa 100644 --- a/app/ledger/income/add/page.tsx +++ b/app/ledger/income/add/page.tsx @@ -6,7 +6,7 @@ import { useTranslation } from 'react-i18next' import { useAppDispatch } from "@/lib/hooks" import { addIncome, IncomeItem } from "@/lib/features/ledger/income/incomeSlice" import { useRouter } from "next/navigation" -import { FieldErrors, SubmitHandler, useForm, Controller } from "react-hook-form" +import { FieldErrors, SubmitHandler, useForm } from "react-hook-form" import TextFieldWithValidation from "@/app/components/TextFieldWithValidation" import TextAreaWithValidation from "@/app/components/TextAreaWithValidation" import RequiredFieldDescription from "@/app/components/RequiredFieldDescription" diff --git a/app/ledger/income/list/page.test.tsx b/app/ledger/income/list/page.test.tsx index b31d573..c31c700 100644 --- a/app/ledger/income/list/page.test.tsx +++ b/app/ledger/income/list/page.test.tsx @@ -1,4 +1,4 @@ -import { afterEach, beforeEach, describe, expect, it, test } from 'vitest' +import { afterEach, beforeEach, describe, expect, it } from 'vitest' import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react' import { Provider } from 'react-redux' import Page from './page' @@ -15,7 +15,6 @@ describe('List Income in Ledger Page', async () => { vi.mock('next/navigation', () => require('next-router-mock')) mockRouter.push('/ledger/income/add') store = makeStore() - // render () }) afterEach(cleanup) diff --git a/app/ledger/review/LedgerReviewHeader.test.tsx b/app/ledger/review/LedgerReviewHeader.test.tsx index 4c84e92..d91224a 100644 --- a/app/ledger/review/LedgerReviewHeader.test.tsx +++ b/app/ledger/review/LedgerReviewHeader.test.tsx @@ -1,5 +1,5 @@ -import { afterEach, beforeEach, describe, expect, it, test } from 'vitest' -import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react' +import { afterEach, beforeEach, describe, expect, it } from 'vitest' +import { cleanup, render, screen } from '@testing-library/react' import LedgerReviewHeader from './LedgerReviewHeader' import { BenefitsState } from '@/lib/features/benefits/benefitsSlice' import TestWrapper from '@/app/TestWrapper' diff --git a/app/ledger/review/SnapExpenses.test.tsx b/app/ledger/review/SnapExpenses.test.tsx index d5dea6f..e14e4f5 100644 --- a/app/ledger/review/SnapExpenses.test.tsx +++ b/app/ledger/review/SnapExpenses.test.tsx @@ -1,5 +1,5 @@ -import { afterEach, beforeEach, describe, expect, it, test } from 'vitest' -import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react' +import { afterEach, beforeEach, describe, expect, it } from 'vitest' +import { cleanup, render, screen, waitFor } from '@testing-library/react' import { Provider } from 'react-redux' import { makeStore } from '@/lib/store' import { EnhancedStore } from '@reduxjs/toolkit' diff --git a/app/ledger/review/page.test.tsx b/app/ledger/review/page.test.tsx index 69f25a0..cbd65b6 100644 --- a/app/ledger/review/page.test.tsx +++ b/app/ledger/review/page.test.tsx @@ -1,4 +1,4 @@ -import { afterEach, beforeEach, describe, expect, it, test } from 'vitest' +import { afterEach, beforeEach, describe, expect, it } from 'vitest' import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react' import { Provider } from 'react-redux' import Page from './page' diff --git a/app/page.test.tsx b/app/page.test.tsx index b047d56..54abe6e 100644 --- a/app/page.test.tsx +++ b/app/page.test.tsx @@ -1,4 +1,4 @@ -import { afterEach, beforeEach, describe, expect, it, test } from 'vitest' +import { afterEach, beforeEach, describe, expect, it } from 'vitest' import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react' import { Provider } from 'react-redux' import Page from './page' diff --git a/app/statement/confirmation/page.tsx b/app/statement/confirmation/page.tsx index b9c875a..4f87757 100644 --- a/app/statement/confirmation/page.tsx +++ b/app/statement/confirmation/page.tsx @@ -3,8 +3,7 @@ import "@trussworks/react-uswds/lib/uswds.css" import "@trussworks/react-uswds/lib/index.css" import { Header, Title, Button, Grid, GridContainer } from '@trussworks/react-uswds' import { useTranslation } from 'react-i18next' -import { useAppDispatch, useAppSelector } from "@/lib/hooks" -import { useRouter } from "next/navigation" +import { useAppSelector } from "@/lib/hooks" import { selectSignedStatement } from "@/lib/features/statement/statementSlice" import Link from "next/link" import Image from "next/image" @@ -12,8 +11,6 @@ import ledgerImage from './ledger.png' export default function Page() { const { t } = useTranslation() - const dispatch = useAppDispatch() - const router = useRouter() const signedStatement = useAppSelector((state) => selectSignedStatement(state)) return ( diff --git a/app/statement/set/page.test.tsx b/app/statement/set/page.test.tsx index a878b22..4ca7009 100644 --- a/app/statement/set/page.test.tsx +++ b/app/statement/set/page.test.tsx @@ -1,4 +1,4 @@ -import { afterEach, beforeEach, describe, expect, it, test } from 'vitest' +import { afterEach, beforeEach, describe, expect, it } from 'vitest' import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react' import { Provider } from 'react-redux' import Page from './page' @@ -6,7 +6,6 @@ import { makeStore } from '@/lib/store' import { vi } from 'vitest' import { EnhancedStore } from '@reduxjs/toolkit' import mockRouter from 'next-router-mock' -import { selectSignedStatement } from '@/lib/features/statement/statementSlice' describe('Set Signed Statment', async () => { let store: EnhancedStore diff --git a/lib/actions.ts b/lib/actions.ts index 41bcb82..31edb33 100644 --- a/lib/actions.ts +++ b/lib/actions.ts @@ -1,3 +1,3 @@ -import { Action, createAction } from "@reduxjs/toolkit"; +import { createAction } from "@reduxjs/toolkit"; export const setInitialStateAction = createAction<{}>('SET_INITIAL_STATE') \ No newline at end of file diff --git a/lib/hooks.ts b/lib/hooks.ts index 737c4bf..f342ab9 100644 --- a/lib/hooks.ts +++ b/lib/hooks.ts @@ -1,4 +1,4 @@ -import { useDispatch, useSelector, useStore } from "react-redux" +import { useDispatch, useSelector } from "react-redux" import type { AppDispatch, RootState } from './store' export const useAppDispatch = useDispatch.withTypes() diff --git a/lib/store.ts b/lib/store.ts index a523432..f3018b7 100644 --- a/lib/store.ts +++ b/lib/store.ts @@ -1,4 +1,4 @@ -import { Action, ConfigureStoreOptions, Store, combineReducers, configureStore } from "@reduxjs/toolkit"; +import { Action, combineReducers, configureStore } from "@reduxjs/toolkit"; import incomeReducer, { selectIncomeTotal } from './features/ledger/income/incomeSlice' import expenseReducer, { selectExpenseTotal } from './features/ledger/expenses/expensesSlice' import statementReducer from './features/statement/statementSlice' diff --git a/package-lock.json b/package-lock.json index 93be1d0..fd625a2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -36,6 +36,7 @@ "eslint": "^8", "eslint-config-next": "14.2.3", "eslint-plugin-i18next": "^6.0.3", + "eslint-plugin-unused-imports": "^3.2.0", "jsdom": "^24.1.0", "pa11y-ci": "^3.1.0", "typescript": "^5", @@ -4567,6 +4568,38 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/eslint-plugin-unused-imports": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-unused-imports/-/eslint-plugin-unused-imports-3.2.0.tgz", + "integrity": "sha512-6uXyn6xdINEpxE1MtDjxQsyXB37lfyO2yKGVVgtD7WEWQGORSOZjgrD6hBhvGv4/SO+TOlS+UnC6JppRqbuwGQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "eslint-rule-composer": "^0.3.0" + }, + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + }, + "peerDependencies": { + "@typescript-eslint/eslint-plugin": "6 - 7", + "eslint": "8" + }, + "peerDependenciesMeta": { + "@typescript-eslint/eslint-plugin": { + "optional": true + } + } + }, + "node_modules/eslint-rule-composer": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/eslint-rule-composer/-/eslint-rule-composer-0.3.0.tgz", + "integrity": "sha512-bt+Sh8CtDmn2OajxvNO+BX7Wn4CIWMpTRm3MaiKPCQcnnlm0CS2mhui6QaoeQugs+3Kj2ESKEEGJUdVafwhiCg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=4.0.0" + } + }, "node_modules/eslint-scope": { "version": "7.2.2", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-7.2.2.tgz", diff --git a/package.json b/package.json index 39a5664..9cee027 100644 --- a/package.json +++ b/package.json @@ -40,6 +40,7 @@ "eslint": "^8", "eslint-config-next": "14.2.3", "eslint-plugin-i18next": "^6.0.3", + "eslint-plugin-unused-imports": "^3.2.0", "jsdom": "^24.1.0", "pa11y-ci": "^3.1.0", "typescript": "^5",