Canon 915 was already quoted, so I won’t bother. But I will add one little bit of clarification onto that: the reason Canon 915 is there is for the avoidance of scandal among the faithful.
For example, if a notorious abortionist approached to receive communion, that would be an example. In other areas, if known members of the Mafia approached. And so on. Canon 915 has been used as a rationale behind banning vocal, outspoken pro-abortion, pro-homosexual politicians from receiving. Rainbow Sash people are generally banned per Canon 915.
All these people are public, notorious sinners who have not repented.
Let us say the priest knew that a man was committing adultery against his wife. This had been going on for a long time…and, in fact, was fairly common knowledge in the parish. That, in of itself, (IMHO) would not be grounds for not admitting him to communion…in as much as, for what we know, he may have dumped his floozy and gone to confession the night before.
However, if he was going all around the town bragging about flaunting God’s law. Daring the Church to say anything about it. Throwing it in everybody’s faces. It may scandalize the faithful to see him receive. It is likely that the priest would have grounds to apply Canon 915 in that case (the difference being an occult sin versus a very public one).