The below is my advice. If you don't like it, then ignore it.

If you live in a state/country that allows riding without a helmet, do whatever you want. It's your head and your choice.
Personally I have had my life saved at least 5 times by my helmet in 47years and maybe 1/2 million miles of riding.
My advice is:
If the expanded polystyrene (EPS) foam has gone brittle, do not ride with it as that is the "crumple zone" that saves your life.
If the shell is damaged beyond minor surface scratches, do not ride with it.
If the straps or other bindings are frayed or worn, do not ride with it.
In an accident, if your head hits the ground with the helmet on, do not ride with it again. The EPS is now compressed and useless.
A good rule of thumb is 5 years usable helmet life, assuming you ride every day (eg. commute) and store your helmet inside the house and not in direct sunlight.
If you only ride once per week, and store the helmet carefully, then up to 10 years. Personally I wouldn't go beyond that.
If you store the helmet in the garage then subtract 1/5 of lifespan (due to all the oil/fuel vapours in the air degrading the EPS).
If you store the helmet in direct sunlight, subtract 1/5 of lifespan (due to UV degradation of the shell and any plastic parts).
I often get asked what is a good cheap helmet. There is no such thing.
There are good helmets and cheap helmets. Buy the best that you can afford.