Search Syntax
Tern’s search syntax helps you find exactly the code you need to transform. Here are some real examples:
Examples
Find useState hooks in React files, excluding tests:
query:useState and:hook with:/import.*react/i exclude:testsFind TODO comments in Go files, excluding vendor:
TODO ext:go exclude:/.*vendor\/.*/Find React component tests, excluding helper utilities:
ext:tsx ext:ts with:"describe(" include:__tests__ -file:testUtilsFind versioned API handlers in routes:
query:/api\/v[0-9]+/ with:".Handle" include:routesFull Syntax Reference
Basic Search
Search for text anywhere in your codebase:
useState
query:useState # explicit formClause Arguments
Clauses support three formats:
Simple text match: keyword:term
ext:jsExact phrase (quoted): keyword:"quoted text, \"escapable\"" - Supports escaped quotes.
with:"import React"
query:"useState hook"Regex pattern: keyword:/regex/[ims] - Flags: i (case-insensitive), m (multiline), s (dotall)
and:/TODO[0-9]+/i
exclude:/\.(md|txt|pdf)$/Refining Matches
and: - Match must also contain this
function and:async
query:useState and:hooknot: - Match must not contain this
useState not:importFiltering by File Contents
with: - Only search files containing this
with:test
with:/import.*react/iwithout: - Exclude files containing this
without:node_modulesrepo: - Limit to specific repository (supports short names and org/repo format)
repo:webapp
repo:my-org/my-repoext: - Limit by file extension (can specify multiple)
ext:go
ext:tsx ext:tslang: - Limit by programming language
lang:javascript
lang:pythonPath Matching
include: or +: - Include paths matching pattern
include:internal
+:/.*\/components\/.*/exclude: or -: - Exclude paths matching pattern
exclude:test
-:node_modules-file: - Exclude specific files
-file:\.test\.js
-file:/.*\.spec\.[jt]sx?$/-dir: - Exclude specific directories
-dir:vendor
-dir:node_modulesTips
Start broad, then refine. Use regex for patterns like version numbers. Combine multiple filters - ext:, and:, exclude: work together. Test queries before writing transformation recipes to verify matches.
