He was definitely aiming for a certain style, which involved following certain rules. There are surviving draft manuscripts where he makes edits to follow voice-writing rules like avoiding parallel fifths, etc. It seems pretty clear based on this (and his training, and even a cursory study of what he wrote) that his compositional practice was intensely theoretical. The dude was not out there freestyling.
In fact, the places where he broke certain fundamental rules are so rare that they form a rather short list, despite his voluminous output: https://www.bach-chorales.com/ConsecutivesInChorales.htm.