A unit is being installed in a closet. The opening is 18″ and the unit is 18″ and will fit the opening. Is this installation legal according to code ?

A unit is being installed in a closet. The opening is 18″ and the unit is 18″ and will fit the opening. Is this installation legal according to code ?