Chapter 10. Hack Tools

A programming language’s features are only part of what makes it good. To be useful, a language needs to have a good tooling ecosystem around it: editor and IDE support, debuggers, analysis and linting tools, etc. The Hack typechecker is built on a powerful static analysis platform that can support many of these uses.

The standard HHVM/Hack installation ships with several tools for inspecting code, as well as for migrating code from PHP to Hack and transpiling Hack code to PHP. This chapter is about those tools.

Inspecting the Codebase

The core of the Hack typechecker’s infrastructure is a server that remembers a set of facts about the codebase. Checking for type errors with hh_client is but one way of querying this set of facts. This section describes other options available to hh_client to query data:

--search

Use this flag to perform a fuzzy search for a given symbol name. Pass a single argument after the flag as the string to search for. Note that this will search built-in symbols as well:

$ hh_client --search wrap
File "/home/oyamauchi/hack/test.php", line 58, characters 7-13: Wrapper,
class

The search is very responsive: the typechecker server indexes the codebase and doesn’t need to read any source files to do the search.

There are several related flags that can be used to restrict the kinds of symbols that will be returned: --search-class, --search-function, --search-constant, and --search-typedef (which searches type aliases). Each of these ...

Get Hack and HHVM now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.