Hard-coded localhost
Hard-coded localhost. A hard-coded local address (http://localhost:3000) in shipped code.
This is how the comment reads inline, under the flagged line.
Why it matters
A localhost URL in production code works in development and fails everywhere else, usually silently.
What to do
Read the base URL from config once at startup.
Examples
const api = "http://localhost:3000/api";
const api = config.apiUrl;
What it catches
It reads a pattern on each line, aware of strings and comments. Languages: TypeScript and JavaScript, Python, Go, Rust, Java, C and similar. Scope: Shipped code only. These cases are the rule's own tests: the first set must be flagged and the second must not.
Flagged
const api = "http://localhost:3000";
Left alone
const api = config.apiUrl;
Research
Hard-coded localhost URLs, and environment reads deep in logic. The value cannot change per environment, and tests must patch globals.
- AI code audit taxonomy
- owner's code bar
Turn it off or change it
In a config file for the CLI, or in the API's rules field:
{
"rules": {
"disable": [
"localhost-url"
],
"severity": {
"localhost-url": "medium"
}
}
}