Skip to content

chore: lint only staged files in the pre-commit hook - #3882

Merged
isekovanic merged 1 commit into
developfrom
chore/pre-commit-staged-lint
Oct 20, 2026
Merged

isekovanic merged 1 commit into
developfrom
chore/pre-commit-staged-lint

Conversation

@testableapple

Copy link
Copy Markdown
Member

🎯 Goal

Make commits fast. The pre-commit hook ran the full yarn lint on every commit, so even a README-only commit took ~20s, and ~40s when anything failed (it then ran a full lint-fix too). It also failed with env: python: No such file or directory in GUI git clients (e.g. Fork) that don't have pyenv shims on PATH.

🛠 Implementation details

  • dotgit/hooks/pre-commit-format.sh now checks only the staged files:
    • Prettier on the staged files (--ignore-unknown; .prettierignore still applies)
    • ESLint on the staged JS/TS files, with --cache (node_modules/.cache/eslint/) and --no-warn-ignored
    • validate-translations and validate-entry-isolation only when something under package/ is staged (both only read the SDK package)
    • on failure, fixes just those files and aborts with the same message as before
  • dotgit/hooks/pre-commit-reject-binaries.py: shebang python → python3 (present on macOS via the Xcode CLT and on current Linux distros)
  • AGENTS.md: documents what the hook checks

CI is unchanged: check-pr.yml still runs the full yarn lint.

Known limitation, same as before: the hook checks the working-tree version of each staged file, so with partial staging the unstaged lines are checked too.

🎨 UI Changes

None.

🧪 Testing

Ran the hook against a temporary index (GIT_INDEX_FILE) for each case:

Case Before After
Nothing staged ~20s 0.2s
README only ~20s 0.3s
TS file in package/ (validators run) ~20s 2.9s (2.1s with a warm ESLint cache)
Prettier violation ~40s (full fix) 0.9s, file auto-fixed, commit aborted
ESLint warning (unused variable) ~40s 1.6s, reported, commit aborted

shellcheck is clean, and the script stays bash 3.2-compatible (macOS default). This PR's own commit went through both hooks and commitlint in 0.85s.

☑️ Checklist

  • I have signed the Stream CLA (required)
  • PR targets the develop branch
  • Documentation is updated
  • New code is tested in main example apps, including all possible scenarios
    • SampleApp iOS and Android
    • Expo iOS and Android

The format hook ran the full `yarn lint` on every commit (~20s, even for a
README change). It now checks only the staged files, with an ESLint cache,
and runs the SDK validators only when package/ is staged. CI still runs
the full lint.

The binary check now uses python3, which GUI git clients without pyenv on
PATH can find.

@isekovanic isekovanic left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for this !

@isekovanic
isekovanic merged commit f3b4487 into develop Oct 20, 2026
9 checks passed
@isekovanic
isekovanic deleted the chore/pre-commit-staged-lint branch October 20, 2026 16:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants