Skip to content

Commit

Permalink
Add prettier config and format
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-rogerson committed Jan 9, 2024
1 parent a5108d2 commit 4c9a99a
Show file tree
Hide file tree
Showing 76 changed files with 7,034 additions and 3,998 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.eslintrc.js
postcss.config.js
49 changes: 25 additions & 24 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,40 @@
const { resolve } = require("path");
const { resolve } = require('path')

const project = resolve(__dirname, "tsconfig.json");
const project = resolve(__dirname, 'tsconfig.json')

module.exports = {
root: true,
extends: [
"next/core-web-vitals",
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-type-checked",
require.resolve("@vercel/style-guide/eslint/react"),
require.resolve("@vercel/style-guide/eslint/next"),
require.resolve("@vercel/style-guide/eslint/typescript"),
'next/core-web-vitals',
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-type-checked',
require.resolve('@vercel/style-guide/eslint/react'),
require.resolve('@vercel/style-guide/eslint/next'),
require.resolve('@vercel/style-guide/eslint/typescript'),
],
rules: {
"@typescript-eslint/no-unnecessary-type-assertion": "error",
"@typescript-eslint/no-inferrable-types": "error",
"@typescript-eslint/array-type": ["error", { default: "array-simple" }],
"@typescript-eslint/no-unused-vars": ["warn", { argsIgnorePattern: "^_" }],
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/consistent-type-definitions": "off",
"react/function-component-definition": "off",
"react/jsx-sort-props": "off",
"react/jsx-no-leaked-render": [2, { validStrategies: ["coerce"] }],
'@typescript-eslint/no-unnecessary-type-assertion': 'error',
'@typescript-eslint/no-inferrable-types': 'error',
'@typescript-eslint/array-type': ['error', { default: 'array-simple' }],
'@typescript-eslint/no-unused-vars': ['warn', { argsIgnorePattern: '^_' }],
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/consistent-type-definitions': 'off',
'react/function-component-definition': 'off',
'react/jsx-sort-props': 'off',
'react/jsx-no-leaked-render': [2, { validStrategies: ['coerce'] }],
},
parserOptions: { project },
overrides: [
{
files: ["*.ts", "*.tsx"],
files: ['*.ts', '*.tsx'],
parserOptions: { project },
},
{
files: ["*.test.ts", "*.test.tsx"],
plugins: ["vitest"],
extends: ["plugin:vitest/recommended"],
files: ['*.test.ts', '*.test.tsx'],
plugins: ['vitest'],
extends: ['plugin:vitest/recommended'],
},
],
settings: { "import/resolver": { typescript: { project } } },
};
settings: { 'import/resolver': { typescript: { project } } },
}
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: "pnpm"
cache: 'pnpm'

- name: Install dependencies
run: pnpm install
Expand Down
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
. "$(dirname -- "$0")/_/husky.sh"

pnpm test
npx lint-staged
pnpm exec lint-staged
10 changes: 10 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"trailingComma": "es5",
"tabWidth": 2,
"useTabs": false,
"bracketSpacing": true,
"semi": false,
"arrowParens": "avoid",
"singleQuote": true,
"plugins": ["prettier-plugin-tailwindcss"]
}
46 changes: 23 additions & 23 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
{
"cSpell.words": [
"burd",
"clsx",
"codemirror",
"debouncer",
"downloadurl",
"Iconish",
"immer",
"lucide",
"multipass",
"partialize",
"spritesheet",
"Svgs",
"testid",
"textbox",
"Uncurried",
"usehooks",
"vectoreffect",
"viewbox",
"zustand"
],
"testing.automaticallyOpenPeekView": "never"
}
"cSpell.words": [
"burd",
"clsx",
"codemirror",
"debouncer",
"downloadurl",
"Iconish",
"immer",
"lucide",
"multipass",
"partialize",
"spritesheet",
"Svgs",
"testid",
"textbox",
"Uncurried",
"usehooks",
"vectoreffect",
"viewbox",
"zustand"
],
"testing.automaticallyOpenPeekView": "never"
}
56 changes: 28 additions & 28 deletions __mocks__/zustand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,55 +2,55 @@
// From:
// https://docs.pmnd.rs/zustand/guides/testing

import { afterEach, vi } from "vitest";
import type * as zustand from "zustand";
import { act } from "@testing-library/react";
import { afterEach, vi } from 'vitest'
import type * as zustand from 'zustand'
import { act } from '@testing-library/react'

const { create: actualCreate, createStore: actualCreateStore } =
await vi.importActual<typeof zustand>("zustand");
await vi.importActual<typeof zustand>('zustand')

// a variable to hold reset functions for all stores declared in the app
export const storeResetFns = new Set<() => void>();
export const storeResetFns = new Set<() => void>()

const createUncurried = <T>(stateCreator: zustand.StateCreator<T>) => {
const store = actualCreate(stateCreator);
const initialState = store.getState();
const store = actualCreate(stateCreator)
const initialState = store.getState()
storeResetFns.add(() => {
store.setState(initialState, true);
});
return store;
};
store.setState(initialState, true)
})
return store
}

// when creating a store, we get its initial state, create a reset function and add it in the set
export const create = (<T>(stateCreator: zustand.StateCreator<T>) => {
// to support curried version of create
return typeof stateCreator === "function"
return typeof stateCreator === 'function'
? createUncurried(stateCreator)
: createUncurried;
}) as typeof zustand.create;
: createUncurried
}) as typeof zustand.create

const createStoreUncurried = <T>(stateCreator: zustand.StateCreator<T>) => {
const store = actualCreateStore(stateCreator);
const initialState = store.getState();
const store = actualCreateStore(stateCreator)
const initialState = store.getState()
storeResetFns.add(() => {
store.setState(initialState, true);
});
return store;
};
store.setState(initialState, true)
})
return store
}

// when creating a store, we get its initial state, create a reset function and add it in the set
export const createStore = (<T>(stateCreator: zustand.StateCreator<T>) => {
// to support curried version of createStore
return typeof stateCreator === "function"
return typeof stateCreator === 'function'
? createStoreUncurried(stateCreator)
: createStoreUncurried;
}) as typeof zustand.createStore;
: createStoreUncurried
}) as typeof zustand.createStore

// reset all stores after each test run
afterEach(() => {
act(() => {
storeResetFns.forEach((resetFn) => {
resetFn();
});
});
});
storeResetFns.forEach(resetFn => {
resetFn()
})
})
})
10 changes: 5 additions & 5 deletions next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ const config = {

webpack(config, { nextRuntime }) {
// as of Next.js latest versions, the nextRuntime is preferred over `isServer`, because of edge-runtime
if (typeof nextRuntime === "undefined") {
if (typeof nextRuntime === 'undefined') {
config.resolve.fallback = {
...config.resolve.fallback,
fs: false,
};
}
}

return config;
return config
},
};
}

export default config;
export default config
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"lint-staged": {
"*.{js,ts,tsx}": [
"eslint --ext .ts,.tsx,.js --fix",
"prettier --cache --write"
"prettier --write"
]
},
"dependencies": {
Expand Down Expand Up @@ -90,12 +90,15 @@
"eslint": "8.49.0",
"eslint-config-next": "13.5.2",
"eslint-plugin-vitest": "^0.3.10",
"husky": "^8.0.0",
"jsdom": "^22.1.0",
"lint-staged": "^15.2.0",
"postcss": "8.4.30",
"prettier": "^3.1.1",
"prettier-plugin-tailwindcss": "^0.5.11",
"tailwindcss-animate": "^1.0.7",
"typescript": "5.2.2",
"vite": "^5.0.8",
"vitest": "^1.0.4",
"husky": "^8.0.0"
"vitest": "^1.0.4"
}
}
32 changes: 16 additions & 16 deletions playwright.config.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { defineConfig, devices } from "@playwright/experimental-ct-react";
import react from "@vitejs/plugin-react";
import { type AliasOptions } from "vite";
import { resolve } from "path";
import { compilerOptions } from "./tsconfig.json";
import { defineConfig, devices } from '@playwright/experimental-ct-react'
import react from '@vitejs/plugin-react'
import { type AliasOptions } from 'vite'
import { resolve } from 'path'
import { compilerOptions } from './tsconfig.json'

// https://github.com/vitejs/vite/issues/88#issuecomment-864348862
const alias: AliasOptions = Object.entries(compilerOptions.paths).reduce(
(acc, [key, [value]]) => {
const aliasKey = key.substring(0, key.length - 2);
const path = value.substring(0, value.length - 2);
const aliasKey = key.substring(0, key.length - 2)
const path = value.substring(0, value.length - 2)
return {
...acc,
[aliasKey]: resolve(__dirname, path),
};
}
},
{}
);
)

/**
* Read environment variables from file.
Expand All @@ -28,7 +28,7 @@ const alias: AliasOptions = Object.entries(compilerOptions.paths).reduce(
*/
export default defineConfig({
timeout: 10000,
testDir: "./tests",
testDir: './tests',
/* Run tests in files in parallel */
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
Expand All @@ -38,16 +38,16 @@ export default defineConfig({
/* Opt out of parallel tests on CI. */
workers: process.env.CI ? 1 : undefined,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: "html",
reporter: 'html',
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Base URL to use in actions like `await page.goto('/')`. */
// baseURL: 'http://127.0.0.1:3000',

/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: "on-first-retry",
trace: 'on-first-retry',

baseURL: "http://localhost:3000",
baseURL: 'http://localhost:3000',

ctViteConfig: {
plugins: [react()],
Expand All @@ -58,8 +58,8 @@ export default defineConfig({
/* Configure projects for major browsers */
projects: [
{
name: "chromium",
use: { ...devices["Desktop Chrome"] },
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
},

// {
Expand Down Expand Up @@ -99,4 +99,4 @@ export default defineConfig({
// url: 'http://127.0.0.1:3000',
// reuseExistingServer: !process.env.CI,
// },
});
})
2 changes: 1 addition & 1 deletion playwright/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import "../src/app/globals.css";
import '../src/app/globals.css'
// Apply theme here, add anything your component needs at runtime here.
// eg: https://playwright.dev/docs/test-components#how-can-i-use-router
Loading

0 comments on commit 4c9a99a

Please sign in to comment.