Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: upgrade typescript + prettier + eslint with a single shared linting config #424

Merged
merged 18 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
/** @type {import("eslint").Linter.Config} */
module.exports = {
root: true,
extends: ["eslint-config-custom"],
parserOptions: {
tsconfigRootDir: __dirname,
project: [
"./tsconfig.json",
"./apps/*/tsconfig.json",
"./packages/*/tsconfig.json",
],
project: __dirname + "/tsconfig.json",
},
};
24 changes: 0 additions & 24 deletions apps/nextjs/.eslintrc.cjs

This file was deleted.

16 changes: 10 additions & 6 deletions apps/nextjs/jest.config.js → apps/nextjs/jest.config.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
const { pathsToModuleNameMapper } = require("ts-jest");
const { compilerOptions } = require("./tsconfig.test.json");
import { readFile } from "fs/promises";
import { pathsToModuleNameMapper } from "ts-jest";

const tsconfig = JSON.parse(
await readFile(new URL("./tsconfig.test.json", import.meta.url)),
);

/** @type {import('ts-jest').JestConfigWithTsJest} */
const config = {
Expand All @@ -11,12 +15,12 @@ const config = {
useESM: true,
},
],
"^.+\\.svg$": "<rootDir>/jest.svgTransform.js",
"^.+\\.svg$": "<rootDir>/jest.svgTransform.mjs",
"^.+\\.(css|scss|png|jpg|jpeg|gif|webp|avif)$": "jest-transform-stub",
},
preset: "ts-jest/presets/default-esm",
moduleNameMapper: {
...pathsToModuleNameMapper(compilerOptions.paths, {
...pathsToModuleNameMapper(tsconfig.compilerOptions.paths, {
prefix: "<rootDir>/src/",
}),
"^(\\.{1,2}/.*)\\.js$": "$1",
Expand All @@ -29,11 +33,11 @@ const config = {
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"],
rootDir: ".",
resetMocks: true,
setupFilesAfterEnv: ["<rootDir>/jest.setup.js"],
setupFilesAfterEnv: ["<rootDir>/jest.setup.cjs"],
collectCoverage:
process.env.CI === "true" || process.env.COLLECT_TEST_COVERAGE === "true",
coverageReporters: ["lcov", "text"],
coverageDirectory: "coverage",
};

module.exports = config;
export default config;
File renamed without changes.
1 change: 1 addition & 0 deletions apps/nextjs/jest.static.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
declare module "*.svg" {
const content: any;
export default content;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
export default {
process() {
console.log("Called jest svg transform");
return { code: "module.exports = {};" };
Expand Down
3 changes: 2 additions & 1 deletion apps/nextjs/next.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// This file should be in Common JS format to be compatible with Next.js
const {
getAppVersion,
getReleaseStage,
RELEASE_STAGE_PRODUCTION,
RELEASE_STAGE_TESTING,
} = require("./scripts/build_config_helpers.js");
} = require("./scripts/build_config_helpers.cjs");
const path = require("path");

const { PHASE_PRODUCTION_BUILD, PHASE_TEST } = require("next/constants");
Expand Down
34 changes: 20 additions & 14 deletions apps/nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,21 @@
"build:dev": "pnpm with-env next build",
"check": "tsc --noEmit",
"clean": "rm -rf .next .turbo node_modules",
"dev": "FORCE_COLOR=1 SENTRY_SUPPRESS_TURBOPACK_WARNING=1 pnpm with-env node scripts/increase-listeners.js next dev --port 2525 --turbo | pino-pretty -C",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

"dev:sentry": "FORCE_COLOR=1 pnpm with-env node scripts/increase-listeners.js next dev --port 2525 | pino-pretty -C",
"dev": "FORCE_COLOR=1 SENTRY_SUPPRESS_TURBOPACK_WARNING=1 pnpm with-env next dev --port 2525 --turbo | pino-pretty -C",
"dev:sentry": "FORCE_COLOR=1 pnpm with-env next dev --port 2525 | pino-pretty -C",
"dev-trace-deprecation": "NODE_OPTIONS=\"--trace-deprecation\" next dev --port 2525 | pino-pretty -C",
"lint": "next lint",
"lint": "eslint .",
"lint-fix": "next lint --fix",
"lint-debug": "eslint --debug .",
"start": "next start",
"type-check": "tsc --noEmit",
"test": "pnpm with-env jest --colors --config jest.config.js",
"test:seq": "pnpm with-env jest --colors --config jest.config.js --verbose --runInBand --no-cache",
"test": "pnpm with-env jest --colors --config jest.config.mjs",
"test:seq": "pnpm with-env jest --colors --config jest.config.mjs --verbose --runInBand --no-cache",
"test-e2e": "pnpm with-env playwright test",
"test-e2e-ui": "pnpm with-env playwright test --ui",
"test-e2e-ui-serve": "pnpm build && pnpm start --port 4848 --turbo",
"test-e2e-ui-built": "PORT=4848 pnpm with-env playwright test --ui",
"test-coverage": "COLLECT_TEST_COVERAGE=true pnpm with-env jest --colors --config jest.config.js --coverage",
"test-coverage": "COLLECT_TEST_COVERAGE=true pnpm with-env jest --colors --config jest.config.mjs --coverage",
"with-env": "dotenv -e ../../.env --",
"aila": "tsx scripts/aila-cli.ts",
"storybook": "dotenv -e ../../.env -- storybook dev -p 6006 --no-open",
Expand All @@ -46,11 +47,12 @@
"@oakai/exports": "*",
"@oakai/logger": "*",
"@oakai/prettier-config": "*",
"@oakai/eslint-config": "*",
"@oaknational/oak-components": "^1.50.0",
"@oaknational/oak-consent-client": "^2.1.0",
"@portabletext/react": "^3.1.0",
"@prisma/client": "5.16.1",
"@prisma/extension-accelerate": "^1.0.0",
"@prisma/client": "^5.16.1",
"@prisma/extension-accelerate": "^1.2.1",
"@radix-ui/react-accordion": "^1.1.2",
"@radix-ui/react-icons": "^1.3.0",
"@radix-ui/react-tooltip": "^1.0.7",
Expand Down Expand Up @@ -141,7 +143,7 @@
"@storybook/test": "^8.4.1",
"@tailwindcss/typography": "^0.5.10",
"@types/file-saver": "^2.0.6",
"@types/jest": "^29.5.12",
"@types/jest": "^29.5.14",
"@types/node": "^18.17.0",
"@types/react": "^18.2.37",
"@types/react-dom": "^18.2.15",
Expand All @@ -150,17 +152,14 @@
"avo": "^3.2.11",
"concurrently": "^8.2.2",
"dotenv-cli": "^6.0.0",
"eslint": "^8.56.0",
"eslint-config-next": "15.0.1",
"eslint-plugin-storybook": "^0.8.0",
"graphql": "^16.9.0",
"jest": "^29.7.0",
"msw": "^2.6.5",
"msw-storybook-addon": "^2.0.4",
"postcss": "^8.4.32",
"tailwindcss": "^3.3.7",
"ts-jest": "^29.1.4",
"typescript": "5.3.3",
"ts-jest": "^29.2.5",
"typescript": "5.7.2",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bumps Typescript to latest

"web-streams-polyfill": "^4.0.0"
},
"engines": {
Expand All @@ -171,5 +170,12 @@
"workerDirectory": [
".storybook/public"
]
},
"eslintConfig": {
"extends": "@oakai/eslint-config",
"parserOptions": {
"project": "./tsconfig.json"
},
"rules": {}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const { existsSync, readFileSync } = require("fs");
* @returns {(string|null)} The SHA if found, or "no_git_state" if mid-merge, or `null` if it cannot be determined.
*/
function getLocalGitRef() {
if (existsSync("../../.git")) {
if (existsSync("../../.git/HEAD")) {
const rev = readFileSync("../../.git/HEAD")
.toString()
.trim()
Expand Down
18 changes: 0 additions & 18 deletions apps/nextjs/scripts/increase-listeners.js

This file was deleted.

1 change: 1 addition & 0 deletions apps/nextjs/scripts/preload-chat-routes.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ const preBuildRoutes = async (
console.log("All routes pre-built successfully");
console.timeEnd(timerId);
} catch (error) {
console.error(error);
if (retryCount < maxRetries) {
console.log(
`Retrying pre-build (attempt ${retryCount + 1} of ${maxRetries})...`,
Expand Down
1 change: 1 addition & 0 deletions apps/nextjs/src/ai-apps/lesson-planner/state/actions.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-duplicate-enum-values */
import type { RateLimitInfo } from "@oakai/api/src/types";
import type { KeyStageName, SubjectName } from "@oakai/core";
import type {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { createOpenAIClient } from "@oakai/core/src/llm/openai";
import { aiLogger } from "@oakai/logger";
import fs from "fs/promises";
import type OpenAI from "openai";
import type { ChatCompletionCreateParamsNonStreaming } from "openai/resources";
import type { ChatCompletionCreateParamsNonStreaming } from "openai/resources/index.mjs";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why we have to do this now. This has changed a few times


const log = aiLogger("fixtures");

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Inspired by Chatbot-UI and modified to fit the needs of this project
// @see https://github.com/mckaywrigley/chatbot-ui/blob/main/components/Chat/ChatMessage.tsx
import type { ReactNode } from "react";
import type { ReactNode, JSX } from "react";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Global JSX is now deprecated

import { useState } from "react";

import type { MessagePart } from "@oakai/aila/src/protocol/jsonPatchProtocol";
Expand Down Expand Up @@ -200,7 +200,7 @@ function MessageWrapper({

function MessageTextWrapper({ children }: Readonly<{ children: ReactNode }>) {
return (
<div className=" flex w-full flex-col items-start justify-between">
<div className="flex w-full flex-col items-start justify-between">
{children}
</div>
);
Expand Down
32 changes: 15 additions & 17 deletions apps/nextjs/src/components/AppComponents/Chat/ui/textarea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,21 @@ import * as React from "react";

import { cn } from "@/lib/utils";

interface TextareaProps
extends React.TextareaHTMLAttributes<HTMLTextAreaElement> {}

const Textarea = React.forwardRef<HTMLTextAreaElement, TextareaProps>(
({ className, ...props }, ref) => {
return (
<textarea
className={cn(
"flex min-h-[80px] w-full rounded-md border border-input bg-transparent px-9 py-7 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",
className,
)}
ref={ref}
{...props}
/>
);
},
);
const Textarea = React.forwardRef<
HTMLTextAreaElement,
React.TextareaHTMLAttributes<HTMLTextAreaElement>
>(({ className, ...props }, ref) => {
return (
<textarea
className={cn(
"flex min-h-[80px] w-full rounded-md border border-input bg-transparent px-9 py-7 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",
className,
)}
ref={ref}
{...props}
/>
);
});
Textarea.displayName = "Textarea";

export { Textarea };
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { JSX } from "react";

import type { Responsive } from "@radix-ui/themes";
import { Box } from "@radix-ui/themes";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { JSX } from "react";

import { OakFlex, OakSpan } from "@oaknational/oak-components";

import { OakLinkNoUnderline } from "@/components/OakLinkNoUnderline";
Expand Down
8 changes: 5 additions & 3 deletions apps/nextjs/src/lib/hooks/use-sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ import {

const LOCAL_STORAGE_KEY = "sidebar";

export interface SidebarContext {
export interface SidebarContextValue {
isSidebarOpen: boolean;
toggleSidebar: () => void;
isLoading: boolean;
}

const SidebarContext = createContext<SidebarContext | undefined>(undefined);
const SidebarContext = createContext<SidebarContextValue | undefined>(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The eslint config no longer likes types named the same as code definitions

undefined,
);

export function useSidebar() {
const context = useContext(SidebarContext);
Expand Down Expand Up @@ -51,7 +53,7 @@ export function SidebarProvider({ children }: SidebarProviderProps) {
});
}, [setIsSidebarOpen]);

const contextValue = useMemo(() => {
const contextValue: SidebarContextValue = useMemo(() => {
return { isSidebarOpen, toggleSidebar, isLoading };
}, [isSidebarOpen, isLoading, toggleSidebar]);

Expand Down
1 change: 1 addition & 0 deletions apps/nextjs/src/middlewares/auth.middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ const shouldInterceptRouteForOnboarding = (req: NextRequest) => {
return true;
};

/* eslint-disable-next-line no-undef */
const needsToCompleteOnboarding = (sessionClaims: CustomJwtSessionClaims) => {
const labs = sessionClaims.labs;
return !labs.isOnboarded || labs.isDemoUser === null;
Expand Down
2 changes: 1 addition & 1 deletion apps/nextjs/src/mocks/clerk/ClerkDecorator.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Decorator } from "@storybook/react/*";
import type { Decorator } from "@storybook/react";

import { ClerkProvider } from "./nextjsComponents";

Expand Down
1 change: 0 additions & 1 deletion apps/nextjs/tailwind.config.cjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// eslint-disable-next-line @typescript-eslint/no-var-requires
const defaultTheme = require("tailwindcss/defaultTheme");
const { blackA } = require("@radix-ui/colors");

Expand Down
4 changes: 3 additions & 1 deletion apps/nextjs/tests-e2e/helpers/auth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ export async function prepareUser(
await test.step("Accept cookie consent", async () => {
try {
await page.getByTestId("cookie-banner-accept").click();
} catch {}
} catch (e) {
console.error("No cookie banner");
}
});

return login;
Expand Down
2 changes: 1 addition & 1 deletion apps/nextjs/tests-e2e/tests/aila-chat/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export async function waitForStreamingStatusChange(
await page.waitForFunction(
([currentStatus, expectedStatus]) => {
const statusElement = document.querySelector(
// eslint-disable-next-line @typescript-eslint/quotes, quotes
// eslint-disable-next-line quotes
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@typescript-eslint/quotes is deprecated

'[data-testid="chat-aila-streaming-status"]',
);
return (
Expand Down
4 changes: 3 additions & 1 deletion apps/nextjs/tests-e2e/tests/auth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ test.skip("authenticate through Clerk UI", async ({ page }) => {

try {
await page.getByTestId("cookie-banner-accept").click();
} catch {}
} catch (e) {
console.error("No cookie banner");
}

await signInThroughUI(page);

Expand Down
Loading
Loading