New Validator rules format + tests. (#5127)

Same as  #5136 but with tests, better empty rules handling, tests and commited to 4.2.