I'm very green at mathematical logic, so I apologize for what may be a stupid question.
As I understand it, the definition of a first-order formula allows for monstrosities like
$$\exists x \neg \exists x \varphi(x),$$
$$\forall x \forall x \forall x \exists x \psi(x),$$
etc. Is there a good reason to define formulas in such a way that these kinds of "formulas" are included? For instance, I was trying to write up a proof of the Tarski-Vaught test, and it seems like this case requires special handling apart from the main argument.
My natural instinct would be to define formulas in such a way that $\exists x \phi$ is a formula only if $x$ is a free variable in $\phi$, but this doesn't seem to be how things are generally done.
Note that when a specific variable $x$ is quantified repeatedly, the quantifier nested closest to the quantified statement is the one and only quantifier of $x$ that applies: it negates any and all previous quantifiers on that variable.
So:
$$\exists x, \color{blue}{\lnot \exists x}\varphi(x)\;\equiv\;\lnot \exists x\, \varphi(x)$$
$$\forall x,\,\forall x, \,\forall x, \,\color{blue}{\exists x}\, \psi(x)\; \equiv \;\exists x\, \psi(x)$$