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:tests

Find 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:testUtils

Find versioned API handlers in routes:

query:/api\/v[0-9]+/ with:".Handle" include:routes

Full Syntax Reference

Basic Search

Search for text anywhere in your codebase:

useState
query:useState  # explicit form

Clause Arguments

Clauses support three formats:

Simple text match: keyword:term

ext:js

Exact 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:hook

not: - Match must not contain this

useState not:import

Filtering by File Contents

with: - Only search files containing this

with:test
with:/import.*react/i

without: - Exclude files containing this

without:node_modules

repo: - Limit to specific repository (supports short names and org/repo format)

repo:webapp
repo:my-org/my-repo

ext: - Limit by file extension (can specify multiple)

ext:go
ext:tsx ext:ts

lang: - Limit by programming language

lang:javascript
lang:python

Path 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_modules

Tips

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.