The immediate context of James’ comments about worldliness is that his readers were arguing with one another and engaging in the wrong kinds of prayers. So their worldliness was expressed verbally to other believers and to God. He also says that the basic cause of their worldliness was coveting something that they could not have, although he does not say what they were coveting. So their worldliness was expressed clearly by wrong words flowing out of wrong desires.
James describes their worldliness as spiritual adultery, which was how the Old Testament prophets often described the wrong religious behaviour of their listeners. The reason that the prophets did so was because the Israelites had been brought into a special relationship with God by the covenant he made with them at Mount Sinai. Christians also have been brought into a special relationship with God through their faith in Christ, and James mentions that relationship when he says that they are friends of God. But the words and behaviour of James’ readers were affecting that relationship.
What happens when a professing Christian does this? God becomes his enemy, says James. What does this mean? It means that God opposes what the worldly believer does. Obviously James does not mean that God uses all his power against that individual. Instead, the Lord will deprive that individual of spiritual blessings and work against him in his providence. This activity of the Lord may lead such a person to consider his way and repent. That is what James wants his readers to experience.
Why does God respond in this way? James tells us in verse 5 that God, like a jealous husband, yearns for the return of his backsliding people to a place of dedicated discipleship and service. It is good for us to know that God responds in this manner. If he was indifferent about it, or merely angry, what hope would there be for us? But he yearns for our fellowship and works to restore us.
It is possible to translate this clause as the New King James Version does: ‘The Spirit who dwells in us yearns jealously.’ If this translation is correct, then what we have here is a description of the response of the grieved Holy Spirit when we sin. James’ readers had their forms of sin and we have ours. But the response of the Spirit would be the same in both. He is full of longing that we would be fully devoted once more to the God who has saved us.