attempt to duplicate the logic from jshint more closely