Skip to content

Commit

Permalink
build: force the usage of t3-env and throw error on process.env usage
Browse files Browse the repository at this point in the history
  • Loading branch information
niebag committed Apr 25, 2024
1 parent cc80498 commit f037ae3
Show file tree
Hide file tree
Showing 5 changed files with 14,599 additions and 19,283 deletions.
10 changes: 8 additions & 2 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const config = {
parserOptions: {
project: true
},
plugins: ['@typescript-eslint'],
plugins: ['@typescript-eslint', 'eslint-plugin-n'],
extends: [
'plugin:@next/next/recommended',
'plugin:@typescript-eslint/recommended-type-checked',
Expand All @@ -31,7 +31,13 @@ const config = {
{
checksVoidReturn: { attributes: false }
}
]
],

// In favor of type safety, the usage of `process.env` will throw an error.
// All references to `process.env` should be replaced with the `env` object created by
// the `@t3-oss/env-nextjs` package, which can be found at `src/env.js`.
// This ensures that the environment variables are properly validated and that the code is type-safe.
'n/no-process-env': 'error'
}
};

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"format": "prettier --write .",
"jest:test": "SKIP_ENV_VALIDATION=1 jest",
"jest:watch": "jest --watch",
"lint": "next lint",
"lint": "next lint --dir .",
"playwright:test": "playwright test",
"playwright:test:codegen": "playwright codegen",
"playwright:test:debug": "playwright test --debug",
Expand Down Expand Up @@ -66,6 +66,7 @@
"autoprefixer": "~10.4",
"eslint": "~8.57",
"eslint-config-next": "~14.2",
"eslint-plugin-n": "~17.3",
"eslint-plugin-storybook": "~0.8",
"husky": "~9.0",
"jest": "~29.7",
Expand Down
8 changes: 5 additions & 3 deletions playwright.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { defineConfig, devices } from '@playwright/test';

import { env } from '~/env';

/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
Expand All @@ -14,11 +16,11 @@ export default defineConfig({
/* Run tests in files in parallel */
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,
forbidOnly: env.CI,
/* Retry on CI only */
retries: process.env.CI ? 2 : 0,
retries: env.CI ? 2 : 0,
/* Opt out of parallel tests on CI. */
workers: process.env.CI ? 1 : undefined,
workers: env.CI ? 1 : undefined,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: 'html',
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
Expand Down
Loading

0 comments on commit f037ae3

Please sign in to comment.