If you're searching for guidance on configuring a compiler, consider exploring linters instead.
One popular option is ESLint, which offers rules like no-shadow:
Shadowing occurs when a local variable shares the same name as a variable in its surrounding scope. The goal of this rule is to prevent shadowed variable declarations.
The purpose of avoiding such configurations within a compiler infrastructure is due to the extensive responsibilities compilers already hold. Compilers focus on parsing source code and generating targeted output efficiently, making additional tasks such as readability checks too burdensome. This is where tools like linters come into play - they enforce coding standards and readability by applying specific rules to your codebase.
UPDATE: My initial understanding of the question was incorrect; it's not about shadowing variables but rather accessing them from higher scopes.
To address this, creating a custom plugin for a linter may be a viable solution.
For instance, developing a unique rule for ESLint - reference to developer guide.
The concept involves crafting your own rule (function) that returns a Visitor for AST nodes. By traversing the AST, you can manage information, save variable references within scopes, and detect unauthorized access attempts across different scopes (this is a simplified explanation).