The rule
The flexible connectors used on water heaters (flexible copper or stainless, reinforced flexible, braided stainless, or polymer braided with an EPDM core) have to comply with ASME A112.18.6/CSA B125.6. Flexible copper, copper alloy or stainless connectors can't be longer than 24 inches.
Tubing like PEX, PEX-AL-PEX, PE-AL-PE and PE-RT can't be installed within the first 18 inches of piping connected to a water heater. Use metal for that first stretch, then transition to the plastic.
In California, PEX-AL-PEX isn't adopted for potable water supply and distribution, so that material isn't an option on ordinary jobs.
On the job
- Measure the 18 inches from the heater's own inlet and outlet connections. If the plastic starts inside that distance, it has to be moved out.
- Pick a connector length that doesn't need to kink or loop. Anything over 24 inches in flexible copper or stainless is out.
- The cold supply to the heater needs a fullway valve at or near the heater (606.2), so plan the metal stub-out with the valve in mind.
The inspector and your city's adopted edition have the final word.