The Contingency spell allows you to "prepare" a spell of 5th level or lower that can target you and set a trigger for it to take effect. It can be any spell 5th or lower capable of targeting the caster, but it "takes effect only on you". Lightning Bolt has a range of "Self (100-foot line)". Would I be able to make it contingent on me being lunged at? I'd appreciate both RAW and RAI answers.
Contingency can cast Lightning Bolt, but it will only affect you
Because Lightning Bolt has a range of "self", it should be compatible with the requirements of the spell:
Choose a spell of 5th level or lower that you can cast, that has a casting time of 1 action, and that can target you.
Since "self" is equivalent to targeting yourself, that criterion is fulfilled.
However, you would not be able to use it to deal damage to anything else (like, say, a creature "lunging at you"). From a paragraph later in the spell's description,
The contingent spell takes effect only on you, even if it can normally target others.
Lightning Bolt dealing damage to anyone else would probably qualify it as "taking effect" on another creature, which the Contingency spell says will not happen.
So while you can cause Lightning Bolt to be triggered by this spell, it won't have any kind of value as a defensive mechanism, being unable to affect anything that would be in its range. You might be able to use it as a kind of scare tactic, i.e. having it go off to trick oncoming enemies into thinking that you're more dangerous than they might otherwise be inclined to believe you would be. But the actual effects of Lightning Bolt won't be able to affect those creatures.
No, you can’t
One of the prerequisites of the contingent spell is that it “... can target you.” Lightning Bolt does not target you, it “... blasts out from you in a direction you choose.”
The range of Lightning Bolt is “Self (100-foot line)” so it is an area of effect spell - it has a point of origin (Self) [which you can include in the AoE] but you are not a target. Targets are “creatures, objects, or a point in space”, this is a “point in space” (where you are).