fix: scope jest, lint, prettier, and tsc to ignore .worktrees directory#7131
fix: scope jest, lint, prettier, and tsc to ignore .worktrees directory#7131diegolmello wants to merge 1 commit intodevelopfrom
Conversation
Avoid running test/lint/typecheck commands on sibling git worktrees by ignoring the standard .worktrees/ directory in all four tools.
WalkthroughThis PR adds Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Suggested labels
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@jest.config.js`:
- Line 2: The regex in testPathIgnorePatterns currently has a leading literal
slash which prevents the ^ anchor from matching; update the pattern in
jest.config.js for testPathIgnorePatterns (the entry currently
'/(^|\\/)\\.worktrees\\//') to remove the leading slash so it reads
'(^|\\/)\\.worktrees\\/' (or an equivalent pattern that matches either
start-of-string or a path separator before .worktrees, e.g.,
'^(.*/)?\\.worktrees\\/') so .worktrees paths are correctly ignored.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: d0d8346b-bad7-4bf2-b025-71b6ac0116e5
📒 Files selected for processing (4)
.eslintignore.prettierignorejest.config.jstsconfig.json
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: ESLint and Test / run-eslint-and-test
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{js,jsx,ts,tsx,json}
📄 CodeRabbit inference engine (CLAUDE.md)
Configure Prettier with tabs, single quotes, 130 character width, no trailing commas, arrow parens avoid, and bracket same line
Files:
tsconfig.jsonjest.config.js
**/*.{js,jsx,ts,tsx}
📄 CodeRabbit inference engine (CLAUDE.md)
Use ESLint with
@rocket.chat/eslint-configbase configuration including React, React Native, TypeScript, and Jest plugins
Files:
jest.config.js
**/*.{js,ts,jsx,tsx}
📄 CodeRabbit inference engine (AGENTS.md)
**/*.{js,ts,jsx,tsx}: Use descriptive names for functions, variables, and classes that clearly convey their purpose
Write comments that explain the 'why' behind code decisions, not the 'what'
Keep functions small and focused on a single responsibility
Use const by default, let when reassignment is needed, and avoid var
Prefer async/await over .then() chains for handling asynchronous operations
Use explicit error handling with try/catch blocks for async operations
Avoid deeply nested code; refactor complex logic into helper functions
Files:
jest.config.js
🧠 Learnings (5)
📓 Common learnings
Learnt from: CR
Repo: RocketChat/Rocket.Chat.ReactNative PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-04-07T17:49:17.538Z
Learning: Applies to **/*.{js,jsx,ts,tsx} : Use ESLint with rocket.chat/eslint-config base configuration including React, React Native, TypeScript, and Jest plugins
Learnt from: CR
Repo: RocketChat/Rocket.Chat.ReactNative PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-04-07T17:49:17.538Z
Learning: Run yarn prettier-lint and TZ=UTC yarn test for modified files before committing
Learnt from: CR
Repo: RocketChat/Rocket.Chat.ReactNative PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-04-07T17:49:17.538Z
Learning: Applies to **/*.{js,jsx,ts,tsx,json} : Configure Prettier with tabs, single quotes, 130 character width, no trailing commas, arrow parens avoid, and bracket same line
📚 Learning: 2026-04-07T17:49:25.836Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat.ReactNative PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-07T17:49:25.836Z
Learning: Applies to **/*.{ts,tsx} : Use TypeScript for type safety; add explicit type annotations to function parameters and return types
Applied to files:
tsconfig.json
📚 Learning: 2026-04-07T17:49:17.538Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat.ReactNative PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-04-07T17:49:17.538Z
Learning: Applies to **/*.{ts,tsx} : Use TypeScript with strict mode enabled and configure baseUrl to app/ for import resolution
Applied to files:
tsconfig.json
📚 Learning: 2026-04-07T17:49:17.538Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat.ReactNative PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-04-07T17:49:17.538Z
Learning: Applies to **/*.{js,jsx,ts,tsx} : Use ESLint with rocket.chat/eslint-config base configuration including React, React Native, TypeScript, and Jest plugins
Applied to files:
tsconfig.jsonjest.config.js
📚 Learning: 2026-04-07T17:49:17.538Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat.ReactNative PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-04-07T17:49:17.538Z
Learning: Applies to **/*.{js,jsx,ts,tsx,json} : Configure Prettier with tabs, single quotes, 130 character width, no trailing commas, arrow parens avoid, and bracket same line
Applied to files:
tsconfig.jsonjest.config.js
🔇 Additional comments (3)
.eslintignore (1)
8-8: LGTM: ESLint scope now correctly excludes.worktrees/.This matches the PR intent and prevents linting sibling worktree files.
.prettierignore (1)
12-12: LGTM: Prettier ignore entry is correct.Adding
.worktrees/here is consistent with the rest of the tooling exclusions.tsconfig.json (1)
73-73: LGTM: TypeScript exclusion is correctly scoped.
"**/.worktrees/**"is an appropriate addition to keeptsclimited to the active worktree.
| @@ -1,5 +1,5 @@ | |||
| module.exports = { | |||
| testPathIgnorePatterns: ['e2e', 'node_modules'], | |||
| testPathIgnorePatterns: ['/e2e/', '/node_modules/', '/(^|\\/)\\.worktrees\\//'], | |||
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Verifies current vs proposed regex behavior on representative paths.
python - <<'PY'
import re
current = re.compile(r'/(^|\/)\.worktrees\/')
proposed = re.compile(r'(^|[/\\])\.worktrees([/\\]|$)')
samples = [
"/repo/.worktrees/feature/app/foo.test.ts",
"/repo/app/foo.test.ts",
r"C:\repo\.worktrees\feature\app\foo.test.ts",
]
for s in samples:
print(s)
print(" current :", bool(current.search(s)))
print(" proposed:", bool(proposed.search(s)))
PYRepository: RocketChat/Rocket.Chat.ReactNative
Length of output: 289
🏁 Script executed:
#!/bin/bash
# Check the jest.config.js file to see the current state
cd /repo && head -20 jest.config.jsRepository: RocketChat/Rocket.Chat.ReactNative
Length of output: 133
🏁 Script executed:
#!/bin/bash
# Also check if there are any Jest documentation or comments in the file
cd /repo && wc -l jest.config.jsRepository: RocketChat/Rocket.Chat.ReactNative
Length of output: 133
🏁 Script executed:
#!/bin/bash
# Find jest.config.js in the repository
git ls-files | grep -E 'jest\.config\.(js|ts|json)$'Repository: RocketChat/Rocket.Chat.ReactNative
Length of output: 92
🏁 Script executed:
#!/bin/bash
# Read the jest.config.js file content
if [ -f "jest.config.js" ]; then
cat -n jest.config.js
fiRepository: RocketChat/Rocket.Chat.ReactNative
Length of output: 896
🌐 Web query:
Jest testPathIgnorePatterns regex behavior and how it matches file paths
💡 Result:
Jest's testPathIgnorePatterns is an array of regexp pattern strings matched against all test paths before executing tests. If a test path matches any pattern, the test is skipped. Key behaviors: - Patterns match against the full absolute file path of potential test files. - Uses JavaScript RegExp syntax, not glob patterns (e.g., no or !; use regex equivalents like /src/.*/state/ instead of /src//state/). - Default: ["/node_modules/"]. - Use token for project root: e.g., ["//build/", "//dist/"]. - Patterns are applied after testMatch/testRegex finds candidates, filtering them out. - Common pitfalls: confusing regex with globs causes invalid regex errors; paths include full system path, so use leading / for path starts; Windows paths may need escaping. Examples: - Ignore node_modules and build: ["/build/", "/node_modules/"] - Ignore files starting with DISABLED.: "/DISABLED\." - Negative lookahead (exclude specific subpath): "/dist/(?!e2e/sfn)" Official docs confirm: "These pattern strings match against the full path." GitHub issues and Stack Overflow examples validate regex-only behavior and full-path matching.
Citations:
- 1: https://jestjs.io/docs/configuration
- 2: testPathIgnorePatterns - needs clarity to use "regex" jestjs/jest#11626
- 3: testPathIgnorePatterns runs tests on paths that match the regex jestjs/jest#11007
- 4: https://stackoverflow.com/questions/59273284/how-to-ignore-filename-convention-with-jest-testpathignorepatterns-react-jest
- 5: https://jestjs.io/docs/29.7/configuration
Fix .worktrees Jest ignore regex; current pattern fails to match .worktrees paths.
At Line 2, the pattern '/(^|\\/)\\.worktrees\\//' starts with a literal / followed by (^|\\/), which means the leading / makes the ^ anchor impossible to match, leaving only the \/ branch. This requires a double-slash before .worktrees, so the pattern effectively never matches typical paths like /repo/.worktrees/. Tests under .worktrees/ directories will not be ignored.
Suggested patch
- testPathIgnorePatterns: ['/e2e/', '/node_modules/', '/(^|\\/)\\.worktrees\\//'],
+ testPathIgnorePatterns: ['/e2e/', '/node_modules/', '(^|[/\\\\])\\.worktrees([/\\\\]|$)'],📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| testPathIgnorePatterns: ['/e2e/', '/node_modules/', '/(^|\\/)\\.worktrees\\//'], | |
| testPathIgnorePatterns: ['/e2e/', '/node_modules/', '(^|[/\\\\])\\.worktrees([/\\\\]|$)'], |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@jest.config.js` at line 2, The regex in testPathIgnorePatterns currently has
a leading literal slash which prevents the ^ anchor from matching; update the
pattern in jest.config.js for testPathIgnorePatterns (the entry currently
'/(^|\\/)\\.worktrees\\//') to remove the leading slash so it reads
'(^|\\/)\\.worktrees\\/' (or an equivalent pattern that matches either
start-of-string or a path separator before .worktrees, e.g.,
'^(.*/)?\\.worktrees\\/') so .worktrees paths are correctly ignored.
Proposed changes
Avoid running test/lint/typecheck commands on sibling git worktrees by ignoring the standard
.worktrees/directory in all four tools:/(^|\\/)\.worktrees\\//totestPathIgnorePatterns.worktrees/to.eslintignore.worktrees/to.prettierignore**/.worktrees/**totsconfig.jsonexcludeHow to test or reproduce
Run any of the four commands from a worktree inside
.worktrees/and verify only files from the current worktree are processed.Types of changes
Checklist