Had he not been of them who glorify Allah, He would have indeed remained inside its belly (the fish) till the Day of Resurrection.
It was said that, if he had not already done righteous deeds during his time of ease.
This was the view of Ad-Dahhak bin Qays, Abu Al-`Aliyah, Wahb bin Munabbih, Qatadah and others, and it was the view favored by Ibn Jarir.
This is what is indicated in the authentic Hadith which we quote below, if Allah wills. In a Hadith narrated from Ibn Abbas, may Allah be pleased with him, he said;
تَعَرَّفْ إِلَى اللهِ فِي الرَّخَاءِ يَعْرِفْكَ فِي الشِّدَّة
Remember Allah during times of ease and He will remember you during times of difficulty.
And it was said that what was meant by the Ayah;
فَلَوْلَا أَنَّهُ كَانَ مِنْ الْمُسَبِّحِينَ
(Had he not been of them who glorify Allah), was the meaning of the following Ayat;
فَنَادَى فِى الظُّلُمَـتِ أَن لاَّ إِلَـهَ إِلاَّ أَنتَ سُبْحَـنَكَ إِنِّى كُنتُ مِنَ الظَّـلِمِينَ
فَاسْتَجَبْنَا لَهُ وَنَجَّيْنَـهُ مِنَ الْغَمِّ وَكَذلِكَ نُنجِـى الْمُوْمِنِينَ
But he cried through the darkness (saying);
"La ilaha illa Anta, You are glorified! Truly, I have been of the wrongdoers."
So We answered his call, and delivered him from the distress. And thus We do deliver the believers. (21;87-88)
This was the view of Sa`id bin Jubayr and others.
Ibn Abi Hatim recorded that Anas bin Malik, may Allah be pleased with him -- and I do not know of anything narrated from Anas that he did not attribute to the Messenger of Allah;
إِنَّ يُونُسَ النَّبِيَّ عَلَيْهِ الصَّلَةُ وَالسَّلَمُ حِينَ بَدَا لَهُ أَنْ يَدْعُوَ بِهَذِهِ الْكَلِمَاتِ وَهُوَ فِي بَطْنِ الْحُوتِ فَقَالَ اللْهُمَّ لَا إِلَهَ إِلاَّ أَنْتَ سُبْحَانَكَ إِنِّي كُنْتُ مِنَ الظَّالِمِينَ
فَأَقْبَلَتِ الدَّعْوَةُ تَحُفُّ بِالْعَرْشِ قَالَتِ الْمَلَأيِكَةُ يَا رَبِّ هَذَا صَوْتٌ ضَعِيفٌ مَعْرُوفٌ مِنْ بِلَأدٍ بَعِيدَةٍ غَرِيبَةٍ
فَقَالَ اللهُ تَعَالَى أَمَا تَعْرِفُونَ ذَلِكَ
قَالُوا يَا رَبِّ وَمَنْ هُوَ
قَالَ عَزَّ وَجَلَّ عَبْدِي يُونُسُ
قَالُوا عَبْدُكَ يُونُسُ الَّذِي لَمْ يَزَلْ يُرْفَعُ لَهُ عَمَلٌ مُتَقَبَّلٌ وَدَعْوَةٌ مُسْتَجَابَةٌ
قَالُوا يَا رَبِّ أَوَلَاا تَرْحَمُ مَا كَانَ يَصْنَعُ فِي الرَّخَاءِ فَتُنْجِيَهُ فِي الْبَلَاءِ
قَالَ بَلَى
فَأَمَرَ الْحُوتَ فَطَرَحَهُ بِالْعَرَاء
When it occurred to the Prophet Yunus, upon him be peace, to call upon Allah in these words when he was in the belly of the great fish, he said,
"La ilaha illa Anta, You are glorified! Truly, I have been of the wrongdoers."
This call went and hovered around the (mighty) Throne, and the angels said, "O Lord, this is the voice of one who is weak but known, in a faraway strange land.
Allah, may He be exalted, said, "How do you know this?"
They said, "O Lord, who is he?"
Allah, may He be exalted, said, "My servant Yunus."
They said, "Your servant Yunus, from whom there kept coming acceptable deeds and supplications which were answered!"
They said, "O Lord, will You not have mercy on him for what he did during his time of ease, and save him from this trial and tribulation?"
He said, "Of course."
So, He commanded the great fish, and it cast him forth on the naked shore.
Allah says