Dan Doriani in this post outlines four classes of legalists: (1) Those who believe they can "earn God’s favor" and merit salvation, (2) those who "require believers to submit to man-made commandments, as if they were God’s law," (3) those who "obey God and do good in order to retain God’s favor," (4) those who "so dwell on God’s law that they neglect other aspects of the Christian life."
Among conservative Christians there is broad agreement that class 1 is unbiblical and is legalism.
Class 2 is where much of the debate exists. It is no doubt true that a real danger exists in exalting man-made rules to the status of divine commands. But there is also a danger in not allowing for applications of Scripture that extend beyond the explicit letter of Scripture. This too is a form of legalism. So it would be legalism to insist that, as a timeless divine directive, men should not wear beards or women should not wear jeans. But it is also legalism to deny that a father could tell his son, "I don’t want you to dress or groom in a way that identifies you with a certain subculutre known for its opposition to God" or say to his daughter, "I don’t want you to wear this specific style of clothing because it is immodest" (or vice versa).
Class 3 also deserves some clarification. If by retaining God’s favor Doriani means maintaining one’s salvation or position in Christ before God, this certainly would be legalism. It would be a variant of class 1. If it means that the person thinks he has to work his way back into God’s favor after sin, then that also would be legalism. However, it is not legalistic to understand that God is pleased when we obey him and displeased when we disobey him; (1 Pet 1:7; Eph. 4:30; Heb. 12:5-6). This is a difficult truth to keep balanced. Christians must rest in the fact that God is unchangeably their Father who loves them and freely forgives them while also recognizing that their sin grieves God’s Spirit and can result in chastening. To employ a Puritan distinction, Christians should have a filial fear of God, but not a servile fear. They must recognize that God does chasten, but he chastens those he loves.
Class 4 is, I think, more properly labeled moralism, which the OED defines as "religion consisting of or reduced to moral practice; morality practised impersonally or without sympathy." Labels aside, however, Doriani is correct that a Christianity that consists of checking off the boxes next to a list of rules is sub-Christian, not least because it neglects the two great commandments upon which all the Law hangs. Of course Christians who are concerned about loving God and the weightier matters of justice, mercy, and faithfulness are also concerned to tithe mint and dill and cumin (Matt 23:23). These need not, ought not, be pitted against each other.