Would it be out of code to switch a receptical this way?
You are probably OK on two counts:


the room is not considered habitable
the wiring is a switch loop controlling a receptacle rather than a direct wired lighting load.


This is covered by NEC 404.2(C). This is the 2014 version.

Note that not all jurisdictions subscribe to all NEC code, and some use older version.