This is fine in an existing setup...
This is the old way a switch loop was done, using the white wire to carry power to the switch and the black wire to carry the switched-hot back to the light. For a dumb light switch, not having neutral at the switch is a nothingburger, so all's well that ends well. There should be electrical tape wrapped around the white wire at each end to reidentify it as a hot, though -- if that's not the case, turn the circuit off at the breaker and add a wrap of black electrical tape around that white wire on each end.
However, new work works differently
In new work, though, this is not to Code. The 2011 NEC added provisions for neutral (what Code calls the grounded conductor vs ground, which Code calls the equipment grounding conductor) at switch locations in 404.2(C) due to the proliferation of advanced "smart" switches, dimmers, timers, and suchnot that need constant power. The alternatives involve returning that constant current through the load (which is incompatible with LED light bulbs and some other loads) or returning it on the equipment grounding system (which is a dirty hack).
(C) Switches Controlling Lighting Loads. The grounded
circuit conductor for the controlled lighting circuit shall be
provided at the location where switches control lighting
loads that are supplied by a grounded general-purpose
branch circuit for other than the following:
(1) Where conductors enter the box enclosing the switch
through a raceway, provided that the raceway is large
enough for all contained conductors, including a
grounded conductor
(2) Where the box enclosing the switch is accessible for
the installation of an additional or replacement cable
without removing finish materials
(3) Where snap switches with integral enclosures comply
with 300.15(E)
(4) Where a switch does not serve a habitable room or
bathroom
(5) Where multiple switch locations control the same lighting load such that the entire floor area of the room or space is visible from the single or combined switch
locations
(6) Where lighting in the area is controlled by automatic
means
(7) Where a switch controls a receptacle load
Informational Note: The provision for a (future) grounded
conductor is to complete a circuit path for electronic lighting control devices.