Ibn Qudamah al-Maqdisi said:
“Know that not everyone is suitable to be your friend. You must verify that this potential friend has the neccessary characteristics that make friendship with him something to be desired. The one you seek to befriend must have five characteristics:
He must be intelligent, as there is no good in befriending an idiot, as he will only harm you when he wants to benefit you. By intelligent, we mean one who understands things as they are, either on his own, or if they are explained to him.
He must have good manners, and this is a must. One who is simply intelligent might be overcome by anger or desire, and obey his desire. Thus, there would be no benefit in befriending him.
He must not be a fasiq, as such a person would not fear Allah, and whoever does not fear Allah cannot be trusted.
He must not be an innovator, as his abundance of innovation is feared from befriending him;
He should not be eager for the dunya.”
[‘Mukhtasar Minhaj al-Qasidin’ p.126-132].