Branch circuit taps supplying luminaires
Branch circuit taps supplying luminaires
Start by looking in 240.21 for overcurrent device location and you get into tap conductor requirements. 240.21(A) sends you to 210.19 and 210.20 for additional requirements for tap conductors on branch circuits.
210.19(A)(4) exception 1(b) sends you to 410.117 for taps supplying luminaires.
410.117(C):
(C) Tap Conductors. Tap conductors of a type suitable for the temperature encountered shall be permitted to run from the luminaire terminal connection to an outlet box placed at least 300 mm (1 ft) from the luminaire. Such tap conductors shall be in suitable raceway or Type AC or MC cable of at least 450 mm (18 in.) but not more than 1.8 m (6 ft) in length.
Unless you put the switch in a box that is between 18 inches and 6 feet of whip away from the luminaire it can not be done as proposed by the OP.