Rashi brings two opinions as to why the Torah emphasizes that Noach was righteous “in his generations”:
Some of our Sages interpret this in praise of Noach: How much more so that if he had lived in a generation of righteous people, he would have been even more righteous. Others interpret it disparagingly: Relative to his generation he was righteous, but if he had been in Avraham’s generation, he would not have been regarded as significant at all.
The two views Rashi outlines are not necessarily arguing about Noach’s level of righteousness. It is possible that everyone agrees that in comparison to Avraham, Noach’s conduct was impressive but not ideal. Nevertheless, Noach was not entirely to blame. For all can agree that had he lived in a more righteous generation, the positive environment would have helped him become even greater!
The Sages were debating only what the Torah seeks to communicate by saying that Noach was “perfect in his generation.” Some Sages interpret these words in praise of Noach: despite the negative influences around him, Noach remained righteous, and had he lived in another era, he surely would have been even greater. According to the second opinion, however, the Torah’s emphasis on Noach’s righteousness “in his generation” warns us that although Noach’s inner strength was certainly praiseworthy, not all aspects of his behavior should be emulated (such as his failure to pray for the people of his generation to be saved).
Noach’s perfection was only relative to his environment; in some areas we must strive to be even greater than Noach was, just as he would have been had he lived in better times.
—Likkutei Sichos, vol. 25, pp. 19–21