diff --git a/.eslintrc.json b/.eslintrc.json deleted file mode 100644 index bffb357..0000000 --- a/.eslintrc.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "extends": "next/core-web-vitals" -} diff --git a/eslint.config.mjs b/eslint.config.mjs new file mode 100644 index 0000000..a38b091 --- /dev/null +++ b/eslint.config.mjs @@ -0,0 +1,35 @@ +import typescriptEslint from "@typescript-eslint/eslint-plugin"; +import simpleImportSort from "eslint-plugin-simple-import-sort"; +import globals from "globals"; +import tsParser from "@typescript-eslint/parser"; +import path from "node:path"; +import { fileURLToPath } from "node:url"; +import js from "@eslint/js"; +import { FlatCompat } from "@eslint/eslintrc"; + +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( + "eslint:recommended", + "plugin:@typescript-eslint/recommended" + ), + { + plugins: { + "@typescript-eslint": typescriptEslint, + "simple-import-sort": simpleImportSort, + }, + rules: { + // Sorting imports and exports + "simple-import-sort/imports": "error", + "simple-import-sort/exports": "error", + }, + }, +]; diff --git a/package.json b/package.json index b2e494f..26fd0b9 100644 --- a/package.json +++ b/package.json @@ -32,9 +32,12 @@ "dev:debug": "NODE_OPTIONS='--inspect' next dev", "build": "next build", "start": "next start", - "eslint": "next lint", - "lint": "prettier --check .", - "format": "prettier --write ." + "lint:prettier": "prettier --check src docs .github *.json *.md *.mjs", + "format:prettier": "prettier --write src docs .github *.json *.md *.mjs", + "lint:eslint": "eslint src", + "format:eslint": "eslint --fix src", + "lint": "yarn lint:prettier && yarn lint:eslint", + "format": "yarn format:prettier && yarn format:eslint" }, "engines": { "node": "22.x" @@ -58,6 +61,15 @@ ] }, "devDependencies": { + "@eslint/eslintrc": "^3.2.0", + "@eslint/js": "^9.16.0", + "@typescript-eslint/eslint-plugin": "^8.17.0", + "@typescript-eslint/parser": "^8.17.0", + "eslint": "^9.16.0", + "eslint-config-next": "^15.0.4", + "eslint-config-prettier": "^9.1.0", + "eslint-plugin-prettier": "^5.2.1", + "eslint-plugin-simple-import-sort": "^12.1.1", "prettier": "^2.5.1", "typescript": "^5.7.2" } diff --git a/src/components/Error.tsx b/src/components/Error.tsx index 4e44190..d3baf04 100644 --- a/src/components/Error.tsx +++ b/src/components/Error.tsx @@ -1,5 +1,6 @@ import { FunctionComponent } from "react"; import { Alert } from "react-bootstrap"; + import { ErrorType } from "../context/error"; interface ErrorProps extends ErrorType { diff --git a/src/components/Errors.tsx b/src/components/Errors.tsx index fc60769..158f169 100644 --- a/src/components/Errors.tsx +++ b/src/components/Errors.tsx @@ -1,4 +1,5 @@ import { useContext } from "react"; + import { ErrorContext } from "../context/error"; import Error from "./Error"; diff --git a/src/components/Header.tsx b/src/components/Header.tsx index 6454e5b..a29fde9 100644 --- a/src/components/Header.tsx +++ b/src/components/Header.tsx @@ -1,5 +1,6 @@ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { Container, Nav, Navbar } from "react-bootstrap"; + import { useIsLoggedIn } from "../utils/hooks"; import Login from "./Login"; import Logout from "./Logout"; diff --git a/src/components/Home.tsx b/src/components/Home.tsx index f652271..cb8b379 100644 --- a/src/components/Home.tsx +++ b/src/components/Home.tsx @@ -1,7 +1,8 @@ -import { KeyboardEvent, useEffect, useState } from "react"; +import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import Link from "next/link"; +import { KeyboardEvent, useEffect, useState } from "react"; import { Button, Card, Form, ListGroup } from "react-bootstrap"; -import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; + import { isValidFireplace } from "../utils/helpers"; // I suspect there's no API for fetching fireplaces. diff --git a/src/components/Login.tsx b/src/components/Login.tsx index 9ffe781..5121353 100644 --- a/src/components/Login.tsx +++ b/src/components/Login.tsx @@ -1,8 +1,9 @@ +import { signIn } from "edilkamin"; import React, { useCallback, useContext, useState } from "react"; import { Button, Form } from "react-bootstrap"; -import { signIn } from "edilkamin"; -import { TokenContext } from "../context/token"; + import { ErrorContext, ErrorType } from "../context/error"; +import { TokenContext } from "../context/token"; import { setTokenLocalStorage } from "../utils/helpers"; const Login = (): JSX.Element => { @@ -13,7 +14,7 @@ const Login = (): JSX.Element => { const addErrorCallback = useCallback( (error: ErrorType) => addError(error), - // eslint-disable-next-line + [] ); @@ -23,7 +24,7 @@ const Login = (): JSX.Element => { const onPasswordChange = (e: React.ChangeEvent): void => setPassword(e.target.value); - const onLogin = async (e: React.MouseEvent): Promise => { + const onLogin = async (): Promise => { try { const token = await signIn(username, password); setTokenLocalStorage(token); diff --git a/src/components/Logout.tsx b/src/components/Logout.tsx index 59e39ea..f76c865 100644 --- a/src/components/Logout.tsx +++ b/src/components/Logout.tsx @@ -1,10 +1,11 @@ import { Button } from "react-bootstrap"; + import { useLogout } from "../utils/hooks"; const Logout = (): JSX.Element => { // TODO: ideally hit the backend to invalidate the token too const logout = useLogout(); - const onLogoutClick = (e: React.MouseEvent): void => logout(); + const onLogoutClick = (): void => logout(); return (