Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
33 changes: 33 additions & 0 deletions documentation/Environment variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,39 @@ With `next-public-env`, the separation between client and server variables is en
- Always audit which validator you're adding new variables to
- When in doubt, start with server-only and only move to client if absolutely necessary

## Development Tooling Variables

### DISABLE_LINTERS_AUTO_FIX

Controls auto-fix behavior in lint-staged pre-commit hooks.

**Default behavior:** Auto-fix is enabled. ESLint runs with `--fix` flag and Prettier runs with `--write` flag, automatically fixing issues during git commits.

**When set:** Auto-fix is disabled. ESLint runs without `--fix` and Prettier runs with `--check`, only reporting issues without fixing them.

**Usage:**

Set the variable in your shell session:

```bash
# macOS / Ubuntu (bash/zsh)
export DISABLE_LINTERS_AUTO_FIX=1

# Windows (cmd)
set DISABLE_LINTERS_AUTO_FIX=1

# Windows (PowerShell)
$env:DISABLE_LINTERS_AUTO_FIX=1
```

For persistent configuration, add it to your shell profile (e.g., `~/.bashrc`, `~/.zshrc`):

```bash
export DISABLE_LINTERS_AUTO_FIX=1
```

**Note:** The variable only needs to be set (any value) to disable auto-fix. The code checks for existence, not a specific value.

## Environment Validation with Envsafe

### Two-Validator Approach
Expand Down
30 changes: 23 additions & 7 deletions lint-staged.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const path = require('node:path');
const fs = require('node:fs');

const WORKSPACE_TOP_DIRS = ['apps', 'packages']; // customise if needed

Expand All @@ -7,6 +8,8 @@ const WORKSPACE_TOP_DIRS = ['apps', 'packages']; // customise if needed
*/
module.exports = {
'*': (stagedAbsPaths) => {
const shouldFix = !process.env.DISABLE_LINTERS_AUTO_FIX;

/** @type {{[bucket: string]: string[]}} */
const buckets = {};
// For each staged file, we need to determine which bucket it belongs to.
Expand All @@ -28,16 +31,29 @@ module.exports = {
const commands = [];

for (const [bucket, files] of Object.entries(buckets)) {
const f = files.map((p) => `"${p}"`).join(' '); // quote every path

// Linting the root level files
if (bucket === '.') {
commands.push(`eslint --cache ${f}`);
commands.push(`prettier --check ${f}`);
// Linting the files in apps/packages (workspaces aka buckets)
const f = files.map((p) => `"${p}"`).join(' '); // quote every path
const eslintCmd = shouldFix ? `eslint --cache --fix ${f}` : `eslint --cache ${f}`;
const prettierMode = shouldFix ? '--write' : '--check';
commands.push(eslintCmd);
commands.push(`prettier ${prettierMode} ${f}`);
} else {
commands.push(`pnpm --filter ${bucket} exec eslint --cache ${f}`);
commands.push(`pnpm --filter ${bucket} exec prettier ${f}`);
// Run linting from the root directory with workspace-specific configs
const workspaceFiles = files.map((p) => `"${p}"`).join(' ');
const workspaceConfig = `${bucket}/eslint.config.mjs`;
const workspacePrettier = `${bucket}/.prettierrc.js`;

const eslintCmd = shouldFix
? `eslint --config ${workspaceConfig} --cache --fix ${workspaceFiles}`
: `eslint --config ${workspaceConfig} --cache ${workspaceFiles}`;
commands.push(eslintCmd);
const workspacePrettierIgnore = `${bucket}/.prettierignore`;
const prettierIgnorePath = fs.existsSync(workspacePrettierIgnore) ? workspacePrettierIgnore : '.prettierignore';
const prettierMode = shouldFix ? '--write' : '--check';
commands.push(
`prettier --config ${workspacePrettier} --ignore-path ${prettierIgnorePath} ${prettierMode} ${workspaceFiles}`
);
}
}

Expand Down