Matthew 5:20-48 were all about Jesus calling his disciples to Greater Righteousness. Through contrasting the Old Commandment with the New, he gave his disciples seven commands. If Chapter 5 was all about the what of the Christian life, then Chapter 6 is all about the how.
The first thing that Jesus does after calling his disciples to a Greater Righteousness is warn them about the dangers of that righteousness. Wait! What? Jesus wants us to know that it’s important that we as disciples not only do what is right, but that we do it in the right way. Righteousness that is overly conscious of itself, love impressed with its sacrifice, mercy that seeks attention, or purity done for show are ALL unrighteous.
We were created by our heavenly Father to be noticed, but by him and him alone — not other people. When we aim towards generosity out of a motivation of being seen and praised by others, or even to impressed by ourselves, then we fail to actually pursue the kind of Christ-honoring righteousness he calls us to. True generosity aims only to be noticed by our heavenly Father and it’s this kind of generosity that he rewards us for!