He heard the Messenger of Allah ﷺ say, "Do not keep company with anyone but a believer, and let none eat your food but the God-fearing."
حدثنا سويد بن نصر أخبرنا ابن المبارك عن حيوة بن شريح حدثني سالم بن غيلان أن الوليد بن قيس التجيبي أخبره أنه سمع أبا سعيد الخدري قال سالم أو عن أبي الهيثم
أنه سمع رسول الله ﷺ يقول لا تصاحب إلا مؤمنا ولا يأكل طعامك إلا تقي
Sourcing, its isnad is sahih. Abu Dawud narrated it in the book of Manners, chapter of who one is commanded to sit with, hadith 4832, from the hadith of Ibn Mubarak with the same wording. Ibn Hibban graded it sahih, hadith 2049, 2050, 2522, as did Hakim, 4/128, and Dhahabi agreed with him.