Skip to content

Commit

Permalink
tweak: improved eslint config
Browse files Browse the repository at this point in the history
  • Loading branch information
jcserv committed Jan 26, 2025
1 parent 94a497f commit 7e31422
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 17 deletions.
3 changes: 2 additions & 1 deletion cypress/support/component.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import "./commands";
import { mount } from "cypress/react18";

import "../../src/index.css";

import "./commands";

declare global {
namespace Cypress {
interface Chainable {
Expand Down
35 changes: 32 additions & 3 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import globals from "globals";
import pluginJs from "@eslint/js";
import tseslint from "typescript-eslint";
import pluginReact from "eslint-plugin-react";
import simpleImportSort from "eslint-plugin-simple-import-sort";
import globals from "globals";
import tseslint from "typescript-eslint";

export default [
{ files: ["**/*.{js,mjs,cjs,ts,jsx,tsx}"] },
Expand All @@ -18,5 +19,33 @@ export default [
pluginJs.configs.recommended,
...tseslint.configs.recommended,
pluginReact.configs.flat.recommended,
{ rules: { "react/react-in-jsx-scope": "off" } },
{
plugins: {
"simple-import-sort": simpleImportSort,
},
rules: {
"no-console": "error",
"simple-import-sort/imports": [
"error",
{
groups: [
// React import
["^react", "^react-dom"],
// External packages
["^([a-z]|@[^/])+"],
// Internal paths starting with @/
["^@/(?!assets).*"],
// Assets imports
["^@/assets"],
// Style imports
["^[./].*(?<!\\.(c|le|sc)ss)$"],
// CSS imports
["\\.(c|le|sc)ss$"],
],
},
],
"simple-import-sort/exports": "error",
"react/react-in-jsx-scope": "off",
},
},
];
4 changes: 3 additions & 1 deletion src/components/Header.cy.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { mount } from "@cypress/react18";
import { Header } from "./Header";
import { createRouter, RouterContextProvider } from "@tanstack/react-router";

import { routeTree } from "@/routeTree.gen";

import { Header } from "./Header";

describe("Header", () => {
it("should render the header contents", () => {
const router = createRouter({ routeTree });
Expand Down
3 changes: 2 additions & 1 deletion src/components/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Link } from "@tanstack/react-router";
import { Github } from "lucide-react";

import { ModeToggle } from "@/components";
import { Button } from "@/components/ui";
import { Link } from "@tanstack/react-router";

export const Header: React.FC = () => {
return (
Expand Down
2 changes: 1 addition & 1 deletion src/components/mode-toggle.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Moon, Sun } from "lucide-react";

import { Button } from "@/components/ui/button";
import { useTheme } from "@/components/theme-provider";
import { Button } from "@/components/ui/button";

export function ModeToggle() {
const { theme, setTheme } = useTheme();
Expand Down
3 changes: 2 additions & 1 deletion src/lib/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { add } from "./utils";
import { expect, test } from "vitest";

import { add } from "./utils";

test("adds 1 + 2 to equal 3", () => {
expect(add(1, 2)).toBe(3);
});
2 changes: 1 addition & 1 deletion src/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { clsx, type ClassValue } from "clsx";
import { type ClassValue, clsx } from "clsx";
import { twMerge } from "tailwind-merge";

export function cn(...inputs: ClassValue[]) {
Expand Down
7 changes: 5 additions & 2 deletions src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { StrictMode } from "react";
import ReactDOM from "react-dom/client";
import { RouterProvider, createRouter } from "@tanstack/react-router";

import { routeTree } from "./routeTree.gen";
import { createRouter, RouterProvider } from "@tanstack/react-router";

import { ThemeProvider } from "@/components/theme-provider";

import { routeTree } from "./routeTree.gen";

import "./index.css";

const router = createRouter({ routeTree });
Expand Down
3 changes: 2 additions & 1 deletion src/routes/__root.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Footer, Header } from "@/components";
import { createRootRoute, Outlet } from "@tanstack/react-router";
import { TanStackRouterDevtools } from "@tanstack/router-devtools";

import { Footer, Header } from "@/components";

export const Route = createRootRoute({
component: () => (
<>
Expand Down
6 changes: 4 additions & 2 deletions src/routes/index.lazy.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import dog from "@/assets/dog.jpg";
import { createLazyFileRoute } from "@tanstack/react-router";

import {
AlertDialog,
AlertDialogAction,
Expand All @@ -10,7 +11,8 @@ import {
AlertDialogTitle,
AlertDialogTrigger,
} from "@/components/ui";
import { createLazyFileRoute } from "@tanstack/react-router";

import dog from "@/assets/dog.jpg";

export const Route = createLazyFileRoute("/")({
component: Index,
Expand Down
6 changes: 3 additions & 3 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defineConfig } from "vite";
import path from "path";
import react from "@vitejs/plugin-react";
import { TanStackRouterVite } from "@tanstack/router-plugin/vite";
import react from "@vitejs/plugin-react";
import path from "path";
import { defineConfig } from "vite";

// https://vitejs.dev/config/
export default defineConfig({
Expand Down

0 comments on commit 7e31422

Please sign in to comment.